home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / wpprg184.zip / WPPRGEXT.C < prev    next >
Text File  |  1994-04-17  |  26KB  |  817 lines

  1. /*************************************************************************
  2.  *
  3.  * This file was generated by the SOM Compiler.
  4.  * FileName: wpprgext.c.
  5.  * Generated using:
  6.  *     SOM Precompiler spc: 1.22
  7.  *     SOM Emitter emitc: 1.24
  8.  *
  9.  *************************************************************************/
  10.  
  11. /*************************************************************************
  12.  * 
  13.  * 
  14.  *   Module Name : WPPRGEXT
  15.  * 
  16.  *   Description : OS/2 Workplace Shell WPProgram Object Extension.
  17.  *                 This extension adds the option to close the folder
  18.  *                 to which the launching program belongs.
  19.  * 
  20.  *   Programmer  : Yong D. Lee
  21.  *   Date        : Nov 21, 1993
  22.  * 
  23.  *   Disclaimer of warranties:
  24.  *       The code is provided "AS IS", without warranty of any kind.  I shall
  25.  *       not be liable for any damages arising out of your use of this code.
  26.  * 
  27.  *************************************************************************/
  28.  
  29. #define WPPrgExt_Class_Source
  30. #define M_WPPrgExt_Class_Source
  31.  
  32. #include "wpprgext.ih"
  33. #include "wpprgext.ph"
  34.  
  35. #include <string.h>
  36. #include <stdio.h>
  37. #include <memory.h>
  38. #include <stdlib.h>
  39.  
  40. /*************************************************************************/
  41. /*                                                                       */
  42. /*                     Non-method function prototype                     */
  43. /*                                                                       */
  44. /*************************************************************************/
  45.  
  46. MRESULT EXPENTRY FolderDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  47. MRESULT EXPENTRY CloseKeyDlgProc(HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2);
  48.  
  49. /*************************************************************************/
  50. /*                                                                       */
  51. /*               Global/Static (Non-Instance) Data Section               */
  52. /*                                                                       */
  53. /*************************************************************************/
  54.  
  55. UCHAR szWPPrgExtClassTitle[CCHMAXPATH] = "";
  56. HMODULE hmod = NULLHANDLE;
  57. LONG virtualKey;
  58.  
  59. /*************************************************************************/
  60. /*                                                                       */
  61. /*                         Method Implementation                         */
  62. /*                                                                       */
  63. /*************************************************************************/
  64.  
  65. /*************************************************************************
  66.  * 
  67.  *  METHOD: QueryFolderClose                               ( ) PRIVATE
  68.  *                                                         (X) PUBLIC
  69.  *  DESCRIPTION:
  70.  * 
  71.  *    Query state of folder close flag
  72.  * 
  73.  *  RETURN:
  74.  * 
  75.  *    ULONG - folder closing option
  76.  * 
  77.  *************************************************************************/
  78.  
  79. SOM_Scope ULONG   SOMLINK wpprgext_QueryFolderClose(WPPrgExt *somSelf)
  80. {
  81.     WPPrgExtData *somThis = WPPrgExtGetData(somSelf);
  82.     WPPrgExtMethodDebug("WPPrgExt","wpprgext_QueryFolderClose");
  83.  
  84.     return (ULONG) _folderClose;
  85. }
  86.  
  87. /*************************************************************************
  88.  *
  89.  *  METHOD: SetFolderClose                                 ( ) PRIVATE
  90.  *                                                         (X) PUBLIC
  91.  *  DESCRIPTION:
  92.  *
  93.  *    Set state of folder close flag
  94.  *
  95.  *************************************************************************/
  96.  
  97. SOM_Scope VOID   SOMLINK wpprgext_SetFolderClose(WPPrgExt *somSelf, ULONG flag)
  98. {
  99.     WPPrgExtData *somThis = WPPrgExtGetData(somSelf);
  100.     WPPrgExtMethodDebug("WPPrgExt","wpprgext_SetFolderClose");
  101.  
  102.     _folderClose = flag;
  103. }
  104.  
  105. /*************************************************************************
  106.  * 
  107.  *  METHOD: AddFolderOptionPage                            ( ) PRIVATE
  108.  *                                                         (X) PUBLIC
  109.  *  DESCRIPTION:
  110.  * 
  111.  *    Add the folder page to the settings notebook
  112.  * 
  113.  *  RETURN:
  114.  * 
  115.  *    0              Unsuccessful
  116.  *    ulPageId       Identifier for the inserted page
  117.  * 
  118.  * 
  119.  *    Methods from the WPObject class
  120.  * 
  121.  *************************************************************************/
  122.  
  123. SOM_Scope ULONG   SOMLINK wpprgext_AddFolderOptionPage(WPPrgExt *somSelf, HWND hwndNotebook)
  124. {
  125.     PAGEINFO pageinfo;
  126.     ULONG pageId;
  127.  
  128.     WPPrgExtData *somThis = WPPrgExtGetData(somSelf);
  129.     WPPrgExtMethodDebug("WPPrgExt","wpprgext_AddFolderOptionPage");
  130.  
  131.     memset((PCH)&pageinfo, 0, sizeof(PAGEINFO));
  132.     pageinfo.cb = sizeof(PAGEINFO);
  133.     pageinfo.hwndPage = NULLHANDLE;
  134.     pageinfo.usPageStyleFlags = BKA_MAJOR | BKA_STATUSTEXTON;
  135.     pageinfo.usPageInsertFlags = BKA_LAST;
  136.     pageinfo.pfnwp = FolderDlgProc;
  137.     pageinfo.resid = hmod;
  138.     pageinfo.dlgid = IDD_FOLDER;
  139.     pageinfo.pszName = "Folder";
  140.     pageinfo.pCreateParams = somSelf;
  141.  
  142.     /*
  143.      * Insert folder key page
  144.      */
  145.     pageId = _wpInsertSettingsPage(somSelf, hwndNotebook, &pageinfo);
  146.  
  147.     /*
  148.      * Insert status line text
  149.      */
  150.     WinSendMsg(hwndNotebook, BKM_SETSTATUSLINETEXT, (MPARAM)pageId, MPFROMP("Folder - Page 1 of 2 "));
  151.  
  152.     return pageId;
  153.  
  154. }
  155.  
  156. /*************************************************************************
  157.  *
  158.  *  METHOD: AddFolderKeyPage                               ( ) PRIVATE
  159.  *                                                         (X) PUBLIC
  160.  *  DESCRIPTION:
  161.  *
  162.  *    Add the folder key selection page to the settings notebook
  163.  *
  164.  *  RETURN:
  165.  *
  166.  *    0              Unsuccessful
  167.  *    ulPageId       Identifier for the inserted page
  168.  *
  169.  *************************************************************************/
  170.  
  171. SOM_Scope ULONG   SOMLINK wpprgext_AddFolderKeyPage(WPPrgExt *somSelf, HWND hwndNotebook)
  172. {
  173.     PAGEINFO pageinfo;
  174.     ULONG pageId;
  175.  
  176.     WPPrgExtData *somThis = WPPrgExtGetData(somSelf);
  177.     WPPrgExtMethodDebug("WPPrgExt","wpprgext_AddFolderKeyPage");
  178.  
  179.     memset((PCH)&pageinfo, 0, sizeof(PAGEINFO));
  180.     pageinfo.cb = sizeof(PAGEINFO);
  181.     pageinfo.hwndPage = NULLHANDLE;
  182.     pageinfo.usPageStyleFlags = BKA_STATUSTEXTON;
  183.     pageinfo.usPageInsertFlags = BKA_LAST;
  184.     pageinfo.pfnwp = CloseKeyDlgProc;
  185.     pageinfo.resid = hmod;
  186.     pageinfo.dlgid = IDD_FOLDERKEY;
  187.     pageinfo.pCreateParams = somSelf;
  188.  
  189.     /*
  190.      * Insert folder key page
  191.      */
  192.     pageId = _wpInsertSettingsPage(somSelf, hwndNotebook, &pageinfo);
  193.  
  194.     /*
  195.      * Insert status line text
  196.      */
  197.     WinSendMsg(hwndNotebook, BKM_SETSTATUSLINETEXT, (MPARAM)pageId, MPFROMP("Folder - Page 2 of 2 "));
  198.  
  199.     return pageId;
  200. }
  201.  
  202. /*************************************************************************
  203.  *
  204.  *  METHOD: FindKeyFromScancode                            ( ) PRIVATE
  205.  *                                                         (X) PUBLIC
  206.  *  DESCRIPTION:
  207.  *
  208.  *    Find key name from scancode
  209.  *
  210.  *************************************************************************/
  211.  
  212. SOM_Scope VOID SOMLINK wpprgext_FindKeyFromScancode(WPPrgExt *somSelf, LONG scanCode, CHAR *str)
  213. {
  214.     SHORT keyID;
  215.  
  216.     WPPrgExtData *somThis = WPPrgExtGetData(somSelf);
  217.     WPPrgExtMethodDebug("WPPrgExt","wpprgext_FindKeyFromScancode");
  218.  
  219.     switch (scanCode) {
  220.         case VK_SHIFT:
  221.             keyID = IDSC_SHIFT;
  222.             break;
  223.  
  224.         case VK_F1:
  225.             keyID = IDSC_F1;
  226.             break;
  227.  
  228.         case VK_F2:
  229.             keyID = IDSC_F2;
  230.             break;
  231.  
  232.         case VK_F3:
  233.             keyID = IDSC_F3;
  234.             break;
  235.  
  236.         case VK_F4:
  237.             keyID = IDSC_F4;
  238.             break;
  239.  
  240.         case VK_F5:
  241.             keyID = IDSC_F5;
  242.             break;
  243.  
  244.         case VK_F6:
  245.             keyID = IDSC_F6;
  246.             break;
  247.  
  248.         case VK_F7:
  249.             keyID = IDSC_F7;
  250.             break;
  251.  
  252.         case VK_F8:
  253.             keyID = IDSC_F8;
  254.             break;
  255.  
  256.         case VK_F9:
  257.             keyID = IDSC_F9;
  258.             break;
  259.  
  260.         case VK_F10:
  261.             keyID = IDSC_F10;
  262.             break;
  263.  
  264.         case VK_F11:
  265.             keyID = IDSC_F11;
  266.             break;
  267.  
  268.         case VK_F12:
  269.             keyID = IDSC_F12;
  270.             break;
  271.  
  272.     }
  273.  
  274.     WinLoadString(WinQueryAnchorBlock(HWND_DESKTOP), _clsQueryModuleHandle((M_WPPrgExt *)_somGetClass(somSelf)), (ULONG)keyID, CCHMAXPATH, str);
  275. }
  276.  
  277. /*************************************************************************
  278.  *
  279.  *  METHOD: FindScancodeFromKey                            ( ) PRIVATE
  280.  *                                                         (X) PUBLIC
  281.  *  DESCRIPTION:
  282.  *
  283.  *    Find scancode from keyname
  284.  *
  285.  *  RETURN
  286.  *    key scancode
  287.  *
  288.  *************************************************************************/
  289.  
  290. SOM_Scope ULONG   SOMLINK wpprgext_FindScancodeFromKey(WPPrgExt *somSelf, CHAR *str)
  291. {
  292.     SHORT sCount;
  293.     CHAR keyStr[CCHMAXPATH];
  294.  
  295.     WPPrgExtData *somThis = WPPrgExtGetData(somSelf);
  296.     WPPrgExtMethodDebug("WPPrgExt","wpprgext_FindScancodeFromKey");
  297.  
  298.     for (sCount = 0; sCount < MAXKEY; sCount++) {
  299.         WinLoadString(WinQueryAnchorBlock(HWND_DESKTOP), _clsQueryModuleHandle((M_WPPrgExt *)_somGetClass(somSelf)), (ULONG)(IDSC_SHIFT + sCount), CCHMAXPATH, keyStr);
  300.  
  301.         if (strcmp(str, keyStr) == 0)
  302.             break;
  303.  
  304.     }
  305.  
  306.     switch (IDSC_SHIFT + sCount) {
  307.         case IDSC_SHIFT:
  308.             return VK_SHIFT;
  309.  
  310.         case IDSC_F1:
  311.             return VK_F1;
  312.  
  313.         case IDSC_F2:
  314.             return VK_F2;
  315.  
  316.         case IDSC_F3:
  317.             return VK_F3;
  318.  
  319.         case IDSC_F4:
  320.             return VK_F4;
  321.  
  322.         case IDSC_F5:
  323.             return VK_F5;
  324.  
  325.         case IDSC_F6:
  326.             return VK_F6;
  327.  
  328.         case IDSC_F7:
  329.             return VK_F7;
  330.  
  331.         case IDSC_F8:
  332.             return VK_F8;
  333.  
  334.         case IDSC_F9:
  335.             return VK_F9;
  336.  
  337.         case IDSC_F10:
  338.             return VK_F10;
  339.  
  340.         case IDSC_F11:
  341.             return VK_F11;
  342.  
  343.         case IDSC_F12:
  344.             return VK_F12;
  345.  
  346.     }
  347.  
  348.     return 0;
  349. }
  350.  
  351. /*************************************************************************/
  352. /*                                                                       */
  353. /*                     Override Method Implementation                    */
  354. /*                                                                       */
  355. /*************************************************************************/
  356.  
  357. /*************************************************************************
  358.  * 
  359.  *  OVERRIDE: wpInitData
  360.  * 
  361.  *  DESCRIPTION:
  362.  * 
  363.  *    Initialize the state variables and allocate any extra memory
  364.  *    that might be needed
  365.  * 
  366.  *************************************************************************/
  367.  
  368. SOM_Scope void   SOMLINK wpprgext_wpInitData(WPPrgExt *somSelf)
  369. {
  370.     WPPrgExtData *somThis = WPPrgExtGetData(somSelf);
  371.     WPPrgExtMethodDebug("WPPrgExt","wpprgext_wpInitData");
  372.  
  373.     memset((PVOID)somThis, 0, sizeof(WPPrgExtData));
  374.     _folderClose = DONOTCLOSE;
  375.  
  376.     parent_wpInitData(somSelf);
  377. }
  378.  
  379. /*************************************************************************
  380.  * 
  381.  *  OVERRIDE: wpSaveState
  382.  * 
  383.  *  DESCRIPTION:
  384.  * 
  385.  *    Save state variable (folder close flag)
  386.  * 
  387.  *************************************************************************/
  388.  
  389. SOM_Scope BOOL   SOMLINK wpprgext_wpSaveState(WPPrgExt *somSelf)
  390. {
  391.     WPPrgExtData *somThis = WPPrgExtGetData(somSelf);
  392.     WPPrgExtMethodDebug("WPPrgExt","wpprgext_wpSaveState");
  393.  
  394.     _wpSaveLong(somSelf, szWPPrgExtClassTitle, IDKEY_FOLDER, _folderClose);
  395.  
  396.     return (parent_wpSaveState(somSelf));
  397. }
  398.  
  399. /*************************************************************************
  400.  * 
  401.  *  OVERRIDE: wpRestoreState
  402.  * 
  403.  *  DESCRIPTION:
  404.  * 
  405.  *    Restore saved state variable
  406.  * 
  407.  *************************************************************************/
  408.  
  409. SOM_Scope BOOL   SOMLINK wpprgext_wpRestoreState(WPPrgExt *somSelf, ULONG ulReserved)
  410. {
  411.     WPPrgExtData *somThis = WPPrgExtGetData(somSelf);
  412.     WPPrgExtMethodDebug("WPPrgExt","wpprgext_wpRestoreState");
  413.  
  414.     _wpRestoreLong(somSelf, szWPPrgExtClassTitle, IDKEY_FOLDER, &_folderClose);
  415.  
  416.     return (parent_wpRestoreState(somSelf,ulReserved));
  417. }
  418.  
  419. /*************************************************************************
  420.  * 
  421.  *  OVERRIDE: wpAddSettingsPages
  422.  * 
  423.  *  DESCRIPTION:
  424.  * 
  425.  *    Add folder settings page to let the user alter the flag
  426.  * 
  427.  *************************************************************************/
  428.  
  429. SOM_Scope BOOL   SOMLINK wpprgext_wpAddSettingsPages(WPPrgExt *somSelf, HWND hwndNotebook)
  430. {
  431.     WPPrgExtData *somThis = WPPrgExtGetData(somSelf);
  432.     WPPrgExtMethodDebug("WPPrgExt","wpprgext_wpAddSettingsPages");
  433.  
  434.     if (parent_wpAddSettingsPages(somSelf, hwndNotebook) && _AddFolderOptionPage(somSelf, hwndNotebook) && _AddFolderKeyPage(somSelf, hwndNotebook)) {
  435.         return (TRUE);
  436.     } else {
  437.         return (FALSE);
  438.     }
  439.   
  440. }
  441.  
  442. /*************************************************************************
  443.  * 
  444.  *   METHOD: wpOpen                                        
  445.  *                                                         
  446.  *   DESCRIPTION:
  447.  * 
  448.  *     Opens the program object window. Close folder upon openning 
  449.  *     according to folderClose flag
  450.  * 
  451.  *************************************************************************/
  452.  
  453. SOM_Scope HWND   SOMLINK wpprgext_wpOpen(WPPrgExt *somSelf, HWND hwndCnr, ULONG ulView, ULONG param)
  454. {
  455.     ULONG longSize = sizeof(LONG);
  456.     LONG keyState;
  457.     BOOL closeIt = FALSE;
  458.     BOOL okToClose = FALSE;
  459.     HWND hwndTop;
  460.     HWND hwndCurrent;
  461.     HWND hwndClient;
  462.     CHAR className[CCHMAXPATH];
  463.  
  464.     WPPrgExtData *somThis = WPPrgExtGetData(somSelf);
  465.     WPPrgExtMethodDebug("WPPrgExt","wpprgext_wpOpen");
  466.  
  467.     /*
  468.      * Get close key scancode from system profile
  469.      */
  470.  
  471.     if (!PrfQueryProfileData(HINI_USERPROFILE, "WPPrgExt", "WPPrgExt", (PVOID)&virtualKey, &longSize))
  472.         virtualKey = VK_SHIFT;
  473.  
  474.     /*
  475.      * Get the state of shift keys so that we can close the parent
  476.      * folder if shift key is pressed
  477.      */
  478.     keyState = WinGetKeyState(HWND_DESKTOP, virtualKey);
  479.  
  480.     if (keyState & 0x8000)
  481.         closeIt = TRUE;
  482.     else {
  483.  
  484.         /*
  485.          * Check for the flags in the Folder page in settings notebook
  486.          */
  487.         switch (ulView) {
  488.  
  489.             case OPEN_SETTINGS:
  490.  
  491.                 if (_folderClose & CLOSENOTEBOOK)
  492.                     closeIt = TRUE;
  493.  
  494.                 break;
  495.  
  496.             case OPEN_RUNNING:
  497.  
  498.                 if (_folderClose & CLOSEPROGRAM)
  499.                     closeIt = TRUE;
  500.  
  501.                 break;
  502.  
  503.         }
  504.     }
  505.  
  506.     if (closeIt) {
  507.         /*
  508.          * The active window before opening the new program must be
  509.          * the parent folder. If it's not the desktop window (if there
  510.          * are no window below the parent folder in z-order), close the
  511.          * parent window
  512.          */
  513.         if (((hwndTop = WinQueryActiveWindow(HWND_DESKTOP)) != NULLHANDLE) && (WinQueryWindow(hwndTop, QW_NEXT) != NULLHANDLE)) {
  514.  
  515.             if ((hwndClient = WinWindowFromID(hwndTop, FID_CLIENT)) != NULLHANDLE) {
  516.                 WinQueryClassName(hwndClient, sizeof(className), className);
  517.  
  518.                 if (strcmp(className, "#37") == 0)
  519.                     okToClose = TRUE;
  520.  
  521.             }
  522.         }
  523.     }
  524.  
  525.     /*
  526.      * Call the original wpOpen before close the folder. Otherwise if multiple window is open, 
  527.      * window focus is got lost
  528.      */
  529.     hwndCurrent = parent_wpOpen(somSelf, hwndCnr, ulView, param);
  530.  
  531.     if (closeIt && okToClose)
  532.         WinSendMsg(hwndTop, WM_CLOSE, (MPARAM)0, (MPARAM)0);
  533.  
  534.     return hwndCurrent;
  535. }
  536.  
  537. #undef SOM_CurrentClass
  538. #define SOM_CurrentClass SOMMeta
  539.  
  540. /*************************************************************************/
  541. /*                                                                       */
  542. /*                      Class Method Implementation                      */
  543. /*                                                                       */
  544. /*************************************************************************/
  545.  
  546. /*************************************************************************
  547.  *
  548.  *  METHOD: clsQueryModuleHandle                         ( ) PRIVATE
  549.  *                                                       (X) PUBLIC
  550.  *  DESCRIPTION:
  551.  *
  552.  *    This method returns the module handle of this class.
  553.  *
  554.  *  RETURN:
  555.  *
  556.  *    0          Unsuccessful
  557.  *    non-zero   Module handle
  558.  *
  559.  *************************************************************************/
  560.  
  561. SOM_Scope HMODULE   SOMLINK wpprgextM_clsQueryModuleHandle(M_WPPrgExt *somSelf)
  562. {
  563.     zString zsPathName;
  564.     APIRET rc;
  565.  
  566.     /* M_WPPrgExtData *somThis = M_WPPrgExtGetData(somSelf); */
  567.     M_WPPrgExtMethodDebug("M_WPPrgExt","wpprgextM_clsQueryModuleHandle");
  568.  
  569.     if (hmod == NULLHANDLE) {
  570.  
  571.        /*
  572.         *   Retrieve registered pathname of our module (DLL) and query the
  573.         *   module handle.
  574.         */
  575.        zsPathName = _somLocateClassFile(SOMClassMgrObject,
  576.                                         SOM_IdFromString("WPPrgExt"),
  577.                                         WPPrgExt_MajorVersion,
  578.                                         WPPrgExt_MinorVersion);
  579.        rc = DosQueryModuleHandle(zsPathName, &hmod);
  580.     }
  581.  
  582.     return (hmod);
  583. }
  584.  
  585. /*************************************************************************/
  586. /*                                                                       */
  587. /*                  Override Class Method Implementation                 */
  588. /*                                                                       */
  589. /*************************************************************************/
  590.  
  591. /*************************************************************************
  592.  * 
  593.  *  METHOD: wpclsInitData
  594.  * 
  595.  *  DESCRIPTION:
  596.  * 
  597.  *    Initialize the class data
  598.  * 
  599.  *************************************************************************/
  600.  
  601. SOM_Scope void   SOMLINK wpprgextM_wpclsInitData(M_WPPrgExt *somSelf)
  602. {
  603.  
  604.     /* M_WPPrgExtData *somThis = M_WPPrgExtGetData(somSelf); */
  605.     M_WPPrgExtMethodDebug("M_WPPrgExt","wpprgextM_wpclsInitData");
  606.  
  607.     parent_wpclsInitData(somSelf);
  608.  
  609.     /* 
  610.      * Get class title
  611.      */
  612.  
  613.     if (!WinLoadString(WinQueryAnchorBlock(HWND_DESKTOP), 
  614.                        _clsQueryModuleHandle(somSelf),  
  615.                        ID_TITLE,        
  616.                        sizeof(szWPPrgExtClassTitle),
  617.                        szWPPrgExtClassTitle))
  618.         strcpy(szWPPrgExtClassTitle, parent_wpclsQueryTitle(somSelf));
  619. }
  620.  
  621. /*************************************************************************
  622.  *
  623.  *  METHOD: wpclsQueryTitle                                
  624.  *                                                         
  625.  *  DESCRIPTION:
  626.  *
  627.  *    Return the string "Extended Program".
  628.  *
  629.  *************************************************************************/
  630.  
  631. SOM_Scope PSZ   SOMLINK wpprgextM_wpclsQueryTitle(M_WPPrgExt *somSelf)
  632. {
  633.     /* M_WPPrgExtData *somThis = M_WPPrgExtGetData(somSelf); */
  634.     M_WPPrgExtMethodDebug("M_WPPrgExt","wpprgextM_wpclsQueryTitle");
  635.  
  636.     /* 
  637.      * Return the class title for a WPPrgExt
  638.      */
  639.     if (szWPPrgExtClassTitle[0])
  640.         return (szWPPrgExtClassTitle);
  641.     else 
  642.         return (parent_wpclsQueryTitle(somSelf));
  643.  
  644. }
  645.  
  646. /*************************************************************************/
  647. /*                                                                       */
  648. /*                   Non-method function implementation                  */
  649. /*                                                                       */
  650. /*************************************************************************/
  651.  
  652. MRESULT EXPENTRY FolderDlgProc(HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2)
  653. {
  654.    PFOLDEROPTION pFolder;
  655.    MRESULT rc;
  656.  
  657.    switch(msg) {
  658.       case WM_INITDLG:
  659.          pFolder = (PFOLDEROPTION)_wpAllocMem((WPPrgExt *)mp2, sizeof(FOLDEROPTION), NULL);
  660.  
  661.          if (pFolder) {
  662.             memset((PVOID)pFolder, 0, sizeof(FOLDEROPTION));
  663.             pFolder->cb = sizeof(FOLDEROPTION);
  664.             pFolder->somSelf = (WPPrgExt *)mp2;
  665.             pFolder->save = FALSE;
  666.             pFolder->closeFolder = _QueryFolderClose(pFolder->somSelf);
  667.          }
  668.          else 
  669.             break;
  670.  
  671.          WinSetWindowPtr(hwndDlg, QWL_USER, pFolder);
  672.  
  673.          if (pFolder->closeFolder & CLOSENOTEBOOK)
  674.             WinSendMsg(WinWindowFromID(hwndDlg, IDCHECK_CLOSENOTEBOOK), BM_SETCHECK, MPFROMSHORT(1), (MPARAM)0);
  675.          else
  676.             WinSendMsg(WinWindowFromID(hwndDlg, IDCHECK_CLOSENOTEBOOK), BM_SETCHECK, MPFROMSHORT(0), (MPARAM)0);
  677.  
  678.          if (pFolder->closeFolder & CLOSEPROGRAM)
  679.             WinSendMsg(WinWindowFromID(hwndDlg, IDCHECK_CLOSEPROGRAM), BM_SETCHECK, MPFROMSHORT(1), (MPARAM)0);
  680.          else
  681.             WinSendMsg(WinWindowFromID(hwndDlg, IDCHECK_CLOSEPROGRAM), BM_SETCHECK, MPFROMSHORT(0), (MPARAM)0);
  682.  
  683.          return (MRESULT)TRUE;
  684.  
  685.       case WM_DESTROY:
  686.          pFolder = WinQueryWindowPtr(hwndDlg, QWL_USER);
  687.  
  688.          if (pFolder == NULL) 
  689.              break;
  690.  
  691.          if (pFolder->save) 
  692.             _wpSaveDeferred(pFolder->somSelf);
  693.  
  694.          _wpFreeMem(pFolder->somSelf, (PBYTE)pFolder);
  695.          return (WinDefDlgProc(hwndDlg, msg, mp1, mp2));
  696.  
  697.       case WM_CONTROL:
  698.          pFolder = WinQueryWindowPtr(hwndDlg, QWL_USER);
  699.  
  700.          if (pFolder == NULL) 
  701.             break;
  702.  
  703.          switch (SHORT1FROMMP(mp1)) {
  704.  
  705.             case IDCHECK_CLOSENOTEBOOK:
  706.  
  707.                if (SHORT2FROMMP(mp1) == BN_CLICKED) {
  708.                   rc = WinSendMsg(WinWindowFromID(hwndDlg, IDCHECK_CLOSENOTEBOOK), BM_QUERYCHECK, (MPARAM)0, (MPARAM)0);
  709.  
  710.                   if ((USHORT)rc == 1)
  711.                      pFolder->closeFolder |= CLOSENOTEBOOK;
  712.                   else if ((USHORT)rc == 0)
  713.                      pFolder->closeFolder &= ~CLOSENOTEBOOK;
  714.  
  715.                   _SetFolderClose(pFolder->somSelf, pFolder->closeFolder);
  716.                   pFolder->save = TRUE;
  717.                }
  718.  
  719.                break;
  720.             case IDCHECK_CLOSEPROGRAM:
  721.  
  722.                if (SHORT2FROMMP(mp1) == BN_CLICKED) {
  723.                   rc = WinSendMsg(WinWindowFromID(hwndDlg, IDCHECK_CLOSEPROGRAM), BM_QUERYCHECK, (MPARAM)0, (MPARAM)0);
  724.  
  725.                   if ((USHORT)rc == 1)
  726.                      pFolder->closeFolder |= CLOSEPROGRAM;
  727.                   else if ((USHORT)rc == 0)
  728.                      pFolder->closeFolder &= ~CLOSEPROGRAM;
  729.  
  730.                   _SetFolderClose(pFolder->somSelf, pFolder->closeFolder);
  731.                   pFolder->save = TRUE;
  732.                }
  733.  
  734.                break;
  735.  
  736.          }
  737.  
  738.          WinSetWindowPtr(hwndDlg, QWL_USER, pFolder);
  739.          return (MRESULT)TRUE;
  740.    }
  741.  
  742.    return (WinDefDlgProc(hwndDlg, msg, mp1, mp2));
  743.  
  744. /*************************************************************************
  745.  *
  746.  * Window procedure : CloseKeyDlgProc
  747.  *
  748.  *************************************************************************/
  749.  
  750. MRESULT EXPENTRY CloseKeyDlgProc(HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2)
  751. {
  752.    SHORT sCount;
  753.    CHAR str[CCHMAXPATH];
  754.    PFOLDERKEY pFolder;
  755.  
  756.    switch (msg) {
  757.       case WM_INITDLG:
  758.          pFolder = (PFOLDERKEY)_wpAllocMem((WPPrgExt *)mp2, sizeof(FOLDERKEY), NULL);
  759.  
  760.          if (pFolder) {
  761.             memset((PVOID)pFolder, 0, sizeof(FOLDERKEY));
  762.             pFolder->cb = sizeof(FOLDERKEY);
  763.             pFolder->somSelf = (WPPrgExt *)mp2;
  764.          }
  765.          else
  766.             break;
  767.  
  768.          WinSetWindowPtr(hwndDlg, QWL_USER, pFolder);
  769.  
  770.          for (sCount=0; sCount < MAXKEY; sCount++) {
  771.             WinLoadString(WinQueryAnchorBlock(HWND_DESKTOP), _clsQueryModuleHandle((M_WPPrgExt *)_somGetClass(pFolder->somSelf)), (ULONG)(IDSC_SHIFT + sCount), CCHMAXPATH, str);
  772.  
  773.             WinSendMsg(WinWindowFromID(hwndDlg, IDCOMBO_KEYSELECTION), LM_INSERTITEM, MPFROMSHORT(LIT_END), MPFROMP(str));
  774.          }
  775.  
  776.          _FindKeyFromScancode(pFolder->somSelf, virtualKey, str);
  777.          WinSetWindowText(WinWindowFromID(hwndDlg, IDCOMBO_KEYSELECTION), str);
  778.          return (MRESULT)TRUE;
  779.  
  780.       case WM_DESTROY:
  781.  
  782.          pFolder = WinQueryWindowPtr(hwndDlg, QWL_USER);
  783.  
  784.          if (pFolder == NULL)
  785.              break;
  786.  
  787.          _wpFreeMem(pFolder->somSelf, (PBYTE)pFolder);
  788.          return (WinDefDlgProc(hwndDlg, msg, mp1, mp2));
  789.  
  790.       case WM_CONTROL:
  791.  
  792.          pFolder = WinQueryWindowPtr(hwndDlg, QWL_USER);
  793.  
  794.          if (pFolder == NULL)
  795.             break;
  796.  
  797.          switch (SHORT1FROMMP(mp1)) {
  798.  
  799.             case IDCOMBO_KEYSELECTION:
  800.  
  801.                if (SHORT2FROMMP(mp1) == CBN_ENTER) {
  802.                   WinQueryWindowText(WinWindowFromID(hwndDlg, IDCOMBO_KEYSELECTION), CCHMAXPATH, str);
  803.                   virtualKey = _FindScancodeFromKey(pFolder->somSelf, str);
  804.                   PrfWriteProfileData(HINI_USERPROFILE, "WPPrgExt", "WPPrgExt", &virtualKey, sizeof(LONG));
  805.                }
  806.  
  807.                break;
  808.          }
  809.  
  810.          return (MRESULT)TRUE;
  811.    }
  812.  
  813.    return (WinDefDlgProc(hwndDlg, msg, mp1, mp2));
  814. }
  815.  
  816.