home *** CD-ROM | disk | FTP | other *** search
/ Computer Buyer 1998 October / dpcb1098.iso / Business / Maxim / MAX5 / data.z / MaxWizard.cpp < prev    next >
C/C++ Source or Header  |  1998-05-15  |  14KB  |  353 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. // NAME.......: MaxWizard.CPP                                               
  3. // PURPOSE....: Defines exported functions for the DLL(Wizard)
  4. // WRITTEN....: 96/09/27 by Darko Juvan
  5. // DESCRIPTION: Defines the initialization routines (entry point for dll) 
  6. //              and exported functions for the DLL
  7. //
  8. // This code and information is provided "as is" without warranty of any
  9. // kind, either expressed or implied, including but not limited to the
  10. // implied warranties of merchantability and/or fitness for a particular
  11. // purpose..
  12. //
  13. // Copyright (c) 1998  Multiactive Software Inc.  All Rights Reserved.
  14. //
  15. //////////////////////////////////////////////////////////////////////////////
  16.  
  17. #include "stdafx.h"
  18. #include <afxdllx.h>
  19. #include "MaxInterface.h"   
  20. #include "WizPropertySheet.h"
  21. #include "WizPages.h"
  22. #include "MaxWizard.h"   
  23.  
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29.  
  30. //aplication and wizard resource handle
  31. HINSTANCE   g_hAppResources;
  32. HINSTANCE   g_hDllResources;
  33.  
  34. //Maximizer Automation objects
  35. IMaxApp*        g_pApplication;
  36. ICurrentRec*    g_pCurrentRecord;
  37.  
  38. //user information structure
  39. WIZ_STRUCT* g_pWizSsuBuf;
  40.  
  41. //state of extension DLL module
  42. static AFX_EXTENSION_MODULE MaxWizardDLL = { NULL, NULL };
  43.  
  44. //////////////////////////////////////////////////////////////////////////////
  45. //                        
  46. // FUNCTION...: DllMain()
  47. //                                                  
  48. // DESCRIPTION: Dll(wizard) entry point 
  49. //
  50. //////////////////////////////////////////////////////////////////////////////
  51. extern "C" int APIENTRY
  52. DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  53. {
  54.     if (dwReason == DLL_PROCESS_ATTACH)
  55.     {
  56.         TRACE0("MAXWIZARD.DLL Initializing!\n");
  57.         
  58.         // Extension DLL one-time initialization
  59.         AfxInitExtensionModule(MaxWizardDLL, hInstance);
  60.         
  61.         g_hDllResources = MaxWizardDLL.hModule;
  62.         
  63.         //This function (now commented out)
  64.         //inserts this DLL into the resource chain.
  65.         //We are not going to do that, instead we will
  66.         //change pointer(handle) to resource 
  67.         //with SetAppResources() and SetDllResources()
  68.         //depending what resources we need at that moment.
  69.         
  70.         //new CDynLinkLibrary(MaxWizardDLL);
  71.     }
  72.     else if (dwReason == DLL_PROCESS_DETACH)
  73.     {
  74.         TRACE0("MAXWIZARD.DLL Terminating!\n");
  75.     }
  76.     return 1;   // OK
  77. }
  78.  
  79.  
  80.  
  81. //////////////////////////////////////////////////////////////////////////////
  82. //                        
  83. // FUNCTION...: GetWizardAVI() exprted function
  84. //                                                  
  85. // DESCRIPTION: return AVI file path (in this version always return empty string)
  86. //
  87. //////////////////////////////////////////////////////////////////////////////
  88. void GetWizardAVI(CString& str)
  89. {
  90.     str = "";
  91. }
  92.  
  93. //////////////////////////////////////////////////////////////////////////////
  94. //                        
  95. // FUNCTION...: GetWizardBMP() exprted function
  96. //                                                  
  97. // DESCRIPTION: return BMP file path. 
  98. //              That bmp will be displayed 
  99. //              in Wizard Menu Dialog 
  100. //              (Yellow dialog with list of available wizards)
  101. //
  102. //////////////////////////////////////////////////////////////////////////////
  103. void GetWizardBMP(CString& str)
  104. {
  105.     //set to dll resources to load string
  106.     SetDllResources();
  107.     str.LoadString(IDS_WIZ_BMP);
  108.  
  109.     //return back to App resources
  110.     SetAppResources();
  111. }
  112.  
  113. //////////////////////////////////////////////////////////////////////////////
  114. //                        
  115. // FUNCTION...: GetWizardTitle() exprted function
  116. //                                                  
  117. // DESCRIPTION: return wizard title string
  118. //              That bmp will be displayed 
  119. //              in Wizard Menu Dialog 
  120. //
  121. //////////////////////////////////////////////////////////////////////////////
  122. void GetWizardTitle(CString& str)
  123. {
  124.     //set to dll resources to load string
  125.     SetDllResources();
  126.     str.LoadString(IDS_WIZ_TITLE);
  127.  
  128.     //return back to App resources
  129.     SetAppResources();
  130.  
  131. }
  132.  
  133.  
  134. //////////////////////////////////////////////////////////////////////////////
  135. //                        
  136. // FUNCTION...: GetWizardDescription() exprted function
  137. //                                                  
  138. // DESCRIPTION: return wizard description text
  139. //              That bmp will be displayed 
  140. //              in Wizard Menu Dialog 
  141. //
  142. //////////////////////////////////////////////////////////////////////////////
  143. void GetWizardDescription(CString& str)
  144. {
  145.     //set to dll resources to load string
  146.     SetDllResources();
  147.     str.LoadString(IDS_WIZ_DESCRIPTION);
  148.  
  149.     //return back to App resources
  150.     SetAppResources();
  151.  
  152. }
  153.  
  154. //////////////////////////////////////////////////////////////////////////////
  155. //                        
  156. // FUNCTION...: StartWizard() exprted function
  157. //                                                  
  158. // DESCRIPTION: start wizard as wizard property sheet dialog
  159. //                sending IDispatch pointers of Application and CurrentRecord object, and
  160. //                pointer of WIZ_STRUCT structure which has 
  161. //              SSUREC pointer inside (user rights, user ID,...).
  162. //
  163. //////////////////////////////////////////////////////////////////////////////
  164. void StartWizard(void* pAppDisp, void* pCurRecDisp, void* pWizStruct)
  165. {
  166.     //structure sent from Maximizer with user information
  167.        g_pWizSsuBuf =  (WIZ_STRUCT*)pWizStruct;
  168.  
  169.     //=================================================================================================================
  170.     //at this point using user record sent in pWizStruct, 
  171.     //you can check user data (for example user rights).
  172.     //We don't need this information cause adding appointment doesn't have assign rights
  173.     //Next lines are just example of checking different user access rights
  174.  
  175.     //------------------------------------------------------------
  176.     //Exaple of checking user Access rights for Address Book, Documents,
  177.     //User Defined Field and  User Defined Field Setup(creation, modification and deletion of UDFs)                    
  178.  
  179.     //Access rights     (Menu: File/Preferences/Security page)
  180.  
  181.     //this will check user rights for address book
  182.     BOOL bAddressBookReadRights =        (BOOL)(g_pWizSsuBuf->pSsuBufCopy->UserData.rightsClient & READRIGHTS); 
  183.     BOOL bAddressBookInsertRights =        (BOOL)(g_pWizSsuBuf->pSsuBufCopy->UserData.rightsClient & INSERTRIGHTS); 
  184.     BOOL bAddressBookModufyRights =        (BOOL)(g_pWizSsuBuf->pSsuBufCopy->UserData.rightsClient & MODIFYRIGHTS); 
  185.     BOOL bAddressBookDeleteRights =        (BOOL)(g_pWizSsuBuf->pSsuBufCopy->UserData.rightsClient & DELETERIGHTS); 
  186.  
  187.  
  188.     //this will check user rights for Documents
  189.     BOOL bDocumentReadRights=            (BOOL)(g_pWizSsuBuf->pSsuBufCopy->UserData.rightsDocuments & READRIGHTS); 
  190.     BOOL bDocumentInsertRights=            (BOOL)(g_pWizSsuBuf->pSsuBufCopy->UserData.rightsDocuments & INSERTRIGHTS); 
  191.     BOOL bDocumentModufyRights=            (BOOL)(g_pWizSsuBuf->pSsuBufCopy->UserData.rightsDocuments & MODIFYRIGHTS); 
  192.     BOOL bDocumentDeleteRights=            (BOOL)(g_pWizSsuBuf->pSsuBufCopy->UserData.rightsDocuments & DELETERIGHTS); 
  193.  
  194.     //this will check user rights for User Defined Fields
  195.     BOOL bUdfReadRights=                (BOOL)(g_pWizSsuBuf->pSsuBufCopy->UserData.rightsUDF & READRIGHTS); 
  196.     BOOL bUdfInsertRights=                (BOOL)(g_pWizSsuBuf->pSsuBufCopy->UserData.rightsUDF & INSERTRIGHTS); 
  197.     BOOL bUdfModufyRights=                (BOOL)(g_pWizSsuBuf->pSsuBufCopy->UserData.rightsUDF & MODIFYRIGHTS); 
  198.     BOOL bUdfDeleteRights=                (BOOL)(g_pWizSsuBuf->pSsuBufCopy->UserData.rightsUDF & DELETERIGHTS); 
  199.     
  200.     //this will check user rights for User Defined Fields in User Defined Fields setup.
  201.     BOOL bUdfSetupReadRights=            (BOOL)(g_pWizSsuBuf->pSsuBufCopy->UserData.rightsUDFSet & READRIGHTS); 
  202.     BOOL bUdfSetupInsertRights=            (BOOL)(g_pWizSsuBuf->pSsuBufCopy->UserData.rightsUDFSet & INSERTRIGHTS); 
  203.     BOOL bUdfSetupModufyRights=            (BOOL)(g_pWizSsuBuf->pSsuBufCopy->UserData.rightsUDFSet & MODIFYRIGHTS); 
  204.     BOOL bUdfSetupDeleteRights=            (BOOL)(g_pWizSsuBuf->pSsuBufCopy->UserData.rightsUDFSet & DELETERIGHTS); 
  205.  
  206.     //checking access rights for Contact, Notes, Dates, 
  207.     //Alt. Address, Documents, Strategy Libraries and Opportunities are the same
  208.  
  209.     //------------------------------------------------------------
  210.     
  211.     //Exaple of checking user Privileges (File menu/Preferences/Security page) 
  212.  
  213.     //Allow global edit               
  214.     //default on    
  215.     BOOL bAllowGlobalEdit =                (BOOL)(g_pWizSsuBuf->pSsuBufCopy->UserData.globalEdit == ALLOW_GLOBAL_EDIT); 
  216.  
  217.     //Private entries allowed         
  218.     //default on
  219.     BOOL bPrivateEntriesAllowed =        (BOOL)!(g_pWizSsuBuf->pSsuBufCopy->UserData.rightsClient & ALLOW_PRIVATE_ENTRIES); 
  220.     
  221.     //Open other users' private entries 
  222.     //default off
  223.     BOOL bOpenPrivateEntries =            (BOOL)(g_pWizSsuBuf->pSsuBufCopy->UserData.rightsClient & ALLOW_SEE_ALL); 
  224.     
  225.     //Modify/delete other user notes    
  226.     //default on
  227.     BOOL bModifyDeleteOtherUserNotes =    (BOOL)(g_pWizSsuBuf->pSsuBufCopy->UserData.noModDelOtherNotes == ALLOW_MODIFY_NOTES); 
  228.     
  229.     //Other users who can view my calendar
  230.     //APPT_RIGHTS_NONE                  0//default
  231.     //APPT_RIGHTS_MASTER                1
  232.     //APPT_RIGHTS_ALL                   2
  233.     UINT iAppointmentRights =            (g_pWizSsuBuf->pSsuBufCopy->UserData.apptRights); 
  234.     
  235.     //Add or modify group appointments  
  236.     //default on
  237.     BOOL bGroupAppointmentRights =        (BOOL)(g_pWizSsuBuf->pSsuBufCopy->UserData.groupApptRights == GROUP_APPT); 
  238.  
  239.     //------------------------------------------------------------
  240.  
  241.     //Exaple of checking user Log options (File menu/Preferences/History page)
  242.     
  243.     //NOLOG                             0
  244.     //LOG_TO_NOTES                      1//default
  245.     //LOG_TO_DIARY                      2
  246.     //LOG_TO_BOTH                       3
  247.  
  248.     //Log Documents
  249.     UINT iLogDocuments =                (g_pWizSsuBuf->pSsuBufCopy->UserData.logDocuments); 
  250.     //Log Phone Calls
  251.     UINT iPhoneCalls =                    (g_pWizSsuBuf->pSsuBufCopy->UserData.logPhoneCalls); 
  252.     //Log Scheduled tasks
  253.     UINT iLogScheduledTasks =            (g_pWizSsuBuf->pSsuBufCopy->UserData.logSchTasks); 
  254.  
  255.     //=================================================================================================================
  256.  
  257.     //create Application object from IDispatch pointer we get from Maximizer
  258.     IMaxApp Application((LPDISPATCH)pAppDisp);
  259.     Application.m_bAutoRelease = FALSE;     //Maximizer will take care of desctruction/deletion
  260.     
  261.     //create CurrentRecord object from IDispatch pointer we get from Maximizer
  262.     ICurrentRec CurrentRecord((LPDISPATCH)pCurRecDisp);
  263.     CurrentRecord.m_bAutoRelease = FALSE;   //Maximizer will take care of desctruction/deletion
  264.  
  265.     //assign to globals
  266.     g_pApplication = &Application;
  267.     g_pCurrentRecord = &CurrentRecord;
  268.  
  269.     //set alarm off while we are in wizard
  270.       g_pApplication->SetAlarm("Off");
  271.  
  272.     //set resources to dll(wizard)
  273.     //we will soon start wizard dialog
  274.     SetDllResources();
  275.  
  276.     CWizPropertySheet wiz;
  277.  
  278.     //construct pages
  279.     CPage1 page1(&wiz);
  280.     CPage2 page2(&wiz);
  281.     CPage3 page3(&wiz);
  282.     CPage4 page4(&wiz);
  283.  
  284.     //add pages to wizard
  285.     wiz.AddPage(&page1);
  286.     wiz.AddPage(&page2);
  287.     wiz.AddPage(&page3);
  288.     wiz.AddPage(&page4);
  289.  
  290.     //set CWizPropertySheet to be in wizard mode
  291.     wiz.SetWizardMode();
  292.  
  293.     //start wizard dialog
  294.     if(wiz.DoModal() == ID_WIZFINISH)
  295.     {
  296.         //return back to application(Maximizer) resources
  297.         SetAppResources();
  298.   
  299.         //ole automation uses VARIANT type to send parameters.
  300.         //convert all data we colect in wizard (stored in CWizPropertySheet)
  301.         COleVariant    var_personal(wiz.m_personal, VT_I2);
  302.         COleVariant    var_alarm(wiz.m_alarm, VT_I2);
  303.         COleVariant    var_alarm_time(wiz.m_alarm_time, VT_I2);
  304.         COleVariant    var_iconType(wiz.m_iconType, VT_I2);
  305.         COleVariant var_priority(wiz.m_priority, VT_BSTR);
  306.         COleVariant    var_completed(wiz.m_completed, VT_I2);
  307.   
  308.         //this will add our appointment to current user
  309.         g_pCurrentRecord->AddAppointment(   wiz.m_date, wiz.m_time1, wiz.m_time2, 
  310.                                             wiz.m_text, var_personal, var_alarm, 
  311.                                             var_alarm_time, var_iconType, 
  312.                                             var_priority, var_completed);
  313.     }
  314.     else
  315.     {
  316.         //return back to application(Maximizer) resources
  317.         SetAppResources();
  318.     }
  319.  
  320.     //set alarm back on
  321.       g_pApplication->SetAlarm("On");
  322. }
  323.  
  324.  
  325.  
  326. //////////////////////////////////////////////////////////////////////////////
  327. //INTERNAL HELPER FUNCTIONS
  328.  
  329. //////////////////////////////////////////////////////////////////////////////
  330. //                        
  331. // FUNCTION...: SetAppResources()
  332. //                                                  
  333. // DESCRIPTION: set application resource instance handle
  334. //
  335. //////////////////////////////////////////////////////////////////////////////
  336. void SetAppResources()
  337. {
  338.     AfxSetResourceHandle(g_hAppResources); // restore the App resource
  339. }
  340.  
  341. //////////////////////////////////////////////////////////////////////////////
  342. //                        
  343. // FUNCTION...: SetDllResources()
  344. //                                                  
  345. // DESCRIPTION: set dll resource instance handle 
  346. //
  347. //////////////////////////////////////////////////////////////////////////////
  348. void SetDllResources()
  349. {
  350.     g_hAppResources = AfxGetResourceHandle();
  351.     AfxSetResourceHandle(g_hDllResources);
  352. }
  353.