home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / desk.zip / DESKTOP.C next >
Text File  |  1994-01-10  |  12KB  |  265 lines

  1. /****************************************************************************/
  2. /* Sends messages to Desktop - OS/2 2.x                                     */
  3. /* Instructions:  Find the modifiable section to add desktop popup          */
  4. /* menu items and follow the comments.                                      */
  5. /* Author:  Brian McManamon CIS - 73243,166                                 */
  6. /* To compile this program using IBM CSET/2 - icc /B"/pmtype:pm" desktop.c  */
  7. /* Warning:  This program is provided as is.  It has hung my desktop in     */
  8. /* some cases becauses some messages have been lost.  This is a temporary   */
  9. /* solution for a specific problem until the WPS development team publishes */
  10. /* a supported solution.                                                    */
  11. /**** Make sure all program names are present and can be found in the    ****/
  12. /**** path before running this program or your desktop will hang.        ****/
  13. /****************************************************************************/
  14. #define INCL_WIN
  15. #include <os2.h>
  16.  
  17. #include <string.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20.  
  21. #define OS2_DESKTOP "Desktop"
  22. #define MENU_ITEM_SETTINGS "Menu Item Settings"
  23. #define FIELD2 0x0245            /* Id of program name entry field          */
  24. #define IDM_LOCKUP  0x02C1       /* This id can be used to lock the Desktop */
  25. #define IDM_OPEN_SETTINGS 0x0070 /* Id to open the settings notebook        */
  26. #define IDM_CREATE 0x023D        /* Id of create pushbutton on menu page    */
  27. #define IDM_OK 0x00B9            /* Id of OK pushbutton in create dialog    */
  28. #define SORT 0x138B              /* Id of sort checkbox on sort page        */
  29.  
  30. #define QUERYPAGEID(Itemid1, Itemid2)                                         \
  31.  WinSendMsg(Itemid1, BKM_QUERYPAGEID, (MPARAM)Itemid2,          \
  32.                                       MPFROM2SHORT(BKA_PREV, BKA_MAJOR))
  33.  
  34. #define array_size sizeof(menu) / (sizeof(menu[0][0]) + sizeof(menu[0][1]))
  35.  
  36. /****************************************************************************/
  37. /* Modifiable section                                                       */
  38. /* The following array defines the menu names and their                     */
  39. /* corresponding program names as they would appear in the desktop popup    */
  40. /* menu.  You can add or edit this array for your own items.                */
  41. /****************************************************************************/
  42. char menu[][2][30]={
  43.    "OS/2 ~Window", "CMD.EXE"
  44. /****************************************************************************/
  45. /* End modifiable section                                                   */
  46. /****************************************************************************/
  47. };
  48. /***************************************************************************/
  49. /*                                                                         */
  50. /*   FUNCTION CreateMenuItem:                                              */
  51. /*        DESCRIPTION:                                                     */
  52. /*             Creates Menu Items on the Desktop Popup menu                */
  53. /*                                                                         */
  54. /***************************************************************************/
  55.  
  56. void CreateMenuItem
  57.   (
  58.   PSZ pszItem1, 
  59.   PSZ pszItem2,
  60.   HWND hwndmenu,
  61.   HWND hwndmenupage
  62.   )
  63.  
  64. {
  65.   HWND hwndentry1,
  66.        hwndentry2;
  67.  
  68. /****************************************************************************/
  69. /* Send a message to access the Menu Item Settings dialog                   */
  70. /****************************************************************************/
  71.   WinSendMsg (hwndmenupage, WM_COMMAND, 
  72.                             MPFROMSHORT(IDM_CREATE),
  73.                             MPFROM2SHORT (CMDSRC_PUSHBUTTON, TRUE));
  74.  
  75. /****************************************************************************/
  76. /* Retrieve the handle to the description entry field and set its text      */
  77. /****************************************************************************/
  78.   hwndentry1 = WinQueryFocus(HWND_DESKTOP);
  79.   WinSetWindowText(hwndentry1, pszItem1);
  80.  
  81. /****************************************************************************/
  82. /* Retrieve the handle to the Menu Item Settings dialog and use it to       */
  83. /* retrieve the handle to the second entry field, then set its text         */
  84. /****************************************************************************/
  85.   hwndmenu = WinQueryWindow(hwndentry1, QW_PARENT);
  86.   hwndentry2 = WinWindowFromID(hwndmenu, FIELD2);
  87.   WinSetFocus(HWND_DESKTOP, hwndentry2);
  88.   WinSetWindowText(hwndentry2, pszItem2);
  89.  
  90. /****************************************************************************/
  91. /* Send a message to close the dialog                                       */
  92. /****************************************************************************/
  93.   WinSendMsg (hwndmenu, WM_COMMAND, 
  94.                         MPFROMSHORT(IDM_OK),
  95.                         MPFROM2SHORT (CMDSRC_PUSHBUTTON, TRUE));
  96.   return;
  97. }
  98.  
  99.  
  100. /***************************************************************************/
  101. /*                                                                         */
  102. /*   FUNCTION SortCheck:                                                   */
  103. /*        DESCRIPTION:                                                     */
  104. /*             Checks the sort menu items checkbox on the sort page        */
  105. /*                                                                         */
  106. /***************************************************************************/
  107.  
  108. HWND SortCheck
  109.   (
  110.   HWND  hwndNotebookFrame,
  111.   HWND  hwndNotebookClient,
  112.   ULONG sort_page
  113.   )
  114.  
  115. {
  116.   HWND hwndsortpage,
  117.        hwndsortcheck;
  118.   BOOL fsuccess;
  119. /****************************************************************************/
  120. /* Turn to Sort page in the notebook and retrieve its window handle         */
  121. /****************************************************************************/
  122.   fsuccess = (ULONG)WinSendMsg(hwndNotebookClient, 
  123.                                BKM_TURNTOPAGE, 
  124.                                MPFROMLONG(sort_page), 
  125.                                MPVOID);
  126.  
  127.   hwndsortpage = (ULONG)WinSendMsg(hwndNotebookFrame, 
  128.                                    BKM_QUERYPAGEWINDOWHWND, 
  129.                                    (MPARAM)sort_page, 
  130.                                    MPVOID);
  131.  
  132. /****************************************************************************/
  133. /* Get the checkbox window handle and set its state to on                   */
  134. /****************************************************************************/
  135.   hwndsortcheck = WinWindowFromID(hwndsortpage, SORT);
  136.   WinSendMsg (hwndsortcheck, BM_SETCHECK, MPFROMSHORT(1), MPVOID); 
  137.   WinSendMsg (hwndsortpage, 
  138.               WM_CONTROL, 
  139.               MPFROM2SHORT(SORT, BN_CLICKED),
  140.               MPFROMLONG(hwndsortcheck));
  141.  
  142.   return hwndsortpage;
  143. }
  144.  
  145.  
  146. /***************************************************************************/
  147. /*                                                                         */
  148. /*   Main Procedure                                                        */
  149. /*                                                                         */
  150. /***************************************************************************/
  151. int main 
  152.   (
  153.   int argc, 
  154.   char *argv[]
  155.   )
  156.  
  157. {
  158.   HAB     hab;
  159.   HMQ     hmq;
  160.   HENUM   henum;
  161.   HWND    hwndDesktopFrame;
  162.   HWND    hwndNotebookFrame;
  163.   HWND    hwndNotebookClient;
  164.   HWND    hwndmenupage;
  165.   HWND    hwndmenu;
  166.   HWND    hwndsortpage;
  167.   ULONG   lockup_page;
  168.   ULONG   general_page;
  169.   ULONG   window_page;
  170.   ULONG   file_page;
  171.   ULONG   menu_page;
  172.   ULONG   background_page;
  173.   ULONG   sort_page;
  174.   BOOL    fsuccess;
  175.   APIRET  rc;
  176.   INT i;
  177.   static CHAR szBuffer[128];
  178.   static CHAR *pszDesktop = OS2_DESKTOP;
  179.   static CHAR *pszMenu = MENU_ITEM_SETTINGS;
  180.  
  181.   hab = WinInitialize (0);
  182.   hmq = WinCreateMsgQueue (hab, 0);
  183.  
  184. /****************************************************************************/
  185. /* Get window handle of Workplace Shell Desktop Frame                       */
  186. /****************************************************************************/
  187.   henum = WinBeginEnumWindows (HWND_DESKTOP);
  188.   hwndDesktopFrame = WinGetNextWindow (henum);
  189.   while (hwndDesktopFrame)
  190.     {
  191.     WinQueryWindowText (hwndDesktopFrame, sizeof szBuffer, szBuffer);
  192.     if (strcmp (szBuffer, pszDesktop) == 0)
  193.       break;
  194.     hwndDesktopFrame = WinGetNextWindow (henum);
  195.     }
  196.   WinEndEnumWindows (henum);
  197.  
  198. /****************************************************************************/
  199. /* Send a message to Desktop Frame Window to Open Settings                  */
  200. /****************************************************************************/
  201.   WinSendMsg (hwndDesktopFrame, WM_COMMAND, MPFROMSHORT(IDM_OPEN_SETTINGS),
  202.                                        MPFROM2SHORT (CMDSRC_MENU, TRUE));
  203.  
  204. /****************************************************************************/
  205. /* Get window handle of Desktop Settings Notebook Frame Window              */
  206. /****************************************************************************/
  207.   henum = WinBeginEnumWindows (HWND_DESKTOP);
  208.   hwndNotebookFrame = WinGetNextWindow (henum);
  209.   while (hwndNotebookFrame)
  210.     {
  211.     WinQueryWindowText (hwndNotebookFrame, sizeof szBuffer, szBuffer);
  212.     if (strcmp (szBuffer, pszDesktop) == 0)
  213.       break;
  214.     hwndNotebookFrame = WinGetNextWindow (henum);
  215.     }
  216.   WinEndEnumWindows (henum);
  217.  
  218. /****************************************************************************/
  219. /* Get window handles and pageids of Settings notebook                      */
  220. /****************************************************************************/
  221.   hwndNotebookClient = WinQueryWindow(hwndNotebookFrame, QW_TOP);
  222.   lockup_page = (ULONG)WinSendMsg(hwndNotebookClient, 
  223.                                   BKM_QUERYPAGEID,
  224.                                   MPVOID, 
  225.                                   MPFROM2SHORT(BKA_LAST, BKA_MAJOR));
  226.   general_page = (ULONG)QUERYPAGEID(hwndNotebookClient, lockup_page);
  227.   window_page = (ULONG)QUERYPAGEID(hwndNotebookClient, general_page);
  228.   file_page = (ULONG)QUERYPAGEID(hwndNotebookClient, window_page);
  229.   menu_page = (ULONG)QUERYPAGEID(hwndNotebookClient, file_page);
  230.   background_page = (ULONG)QUERYPAGEID(hwndNotebookClient, menu_page);
  231.   sort_page = (ULONG)QUERYPAGEID(hwndNotebookClient, background_page);
  232.  
  233. /****************************************************************************/
  234. /* Turn to Menu page in the notebook and retrieve its window handle         */
  235. /****************************************************************************/
  236.   fsuccess = (ULONG)WinSendMsg(hwndNotebookClient, 
  237.                                BKM_TURNTOPAGE, 
  238.                                MPFROMLONG(menu_page), 
  239.                                MPVOID);
  240.  
  241.   hwndmenupage = (ULONG)WinSendMsg(hwndNotebookFrame, 
  242.                                    BKM_QUERYPAGEWINDOWHWND, 
  243.                                    (MPARAM)menu_page, 
  244.                                    MPVOID);
  245.  
  246. /****************************************************************************/
  247. /* Call the CreateMenuItem function to create the separate menu items       */
  248. /****************************************************************************/
  249.   for (i=0; i<array_size; i++)
  250.      CreateMenuItem(menu[i][0], menu[i][1], hwndmenu, hwndmenupage);
  251.  
  252. /****************************************************************************/
  253. /* Call the SortCheck function to set the checkbox state on                 */
  254. /****************************************************************************/
  255.   hwndsortpage = SortCheck(hwndNotebookFrame, hwndNotebookClient, sort_page);
  256.  
  257. /****************************************************************************/
  258. /* Close the Settings notebook and terminate the process                    */
  259. /****************************************************************************/
  260.   WinPostMsg (hwndNotebookFrame, WM_CLOSE, MPVOID, MPVOID); 
  261.   WinDestroyMsgQueue (hmq);
  262.   WinTerminate (hab);
  263.   return 0;
  264. }
  265.