home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / S12733.ZIP / COMMAND.C next >
Text File  |  1990-10-17  |  6KB  |  199 lines

  1. #define INCL_DOS
  2. #define INCL_PM
  3.  
  4. #include <os2.h>
  5. #include <stddef.h>
  6. #include "string.h"
  7. #include "stdio.h"
  8. #include "stdlib.h"
  9. #include "hello.h"
  10.  
  11. /* The ALLOCED macro is used to determine whether to dynamically
  12. allocate the menu template structure or whether to just get it from a
  13. global variable */
  14.  
  15. #define ALLOCED 0
  16. BOOL bHelp=TRUE;
  17.  
  18. extern HWND    hwndHelloFrame;
  19. extern HWND    hwndInfo;
  20.  
  21. HWND        hSubMenu, hWndSysSubMenu;
  22. MENUCREATETEMPLATE  mt;
  23. MENUCREATETEMPLATE far * pmt;
  24.  
  25. USHORT        ActionBarID = 1000;
  26. BOOL        bPopCreated;    /* flag to only allow one popup menu at a time */
  27.  
  28. void HelloCommand( hWnd, Menu)
  29. HWND    hWnd;
  30. USHORT Menu;
  31. {
  32. char  buffer[10];
  33. HWND hWndSysMenu,hMenu;
  34. MENUITEM    mi,miSysMenu;
  35. SHORT        idSysMenu;
  36. HBITMAP hBitmap;
  37. HPS hpsMenu;
  38.  
  39. switch (Menu) {
  40.     case IDM_DELPOPUP:
  41.     /* can't delete it if it hasn't been created */
  42.  
  43.     if (bPopCreated) {
  44.         hMenu = WinWindowFromID(hwndHelloFrame,FID_MENU);
  45.         WinSendMsg(hMenu,MM_DELETEITEM, MPFROM2SHORT((USHORT) ActionBarID, (BOOL) FALSE),0L);
  46.         bPopCreated=FALSE;
  47.         }
  48.     break;
  49.  
  50.     case IDM_NEWMENU:
  51.     if (!bPopCreated) {
  52.  
  53. #if ALLOCED
  54.         SEL sel;
  55.         DosAllocSeg(100, &sel, 0);
  56.         pmt=MAKEP(sel,0);
  57.  
  58.         pmt->size = 0;       /* length of menu template ???????? */
  59.         pmt->version = 0;       /* template version. currently 0 */
  60.         pmt->codepage = 850;   /* codepage used for text items within the menu
  61.                       (but not any submenus) */
  62.         pmt->mnemonic = 0;       /* set to 0 for OS/2 v1.1 */
  63.         pmt->itemcount = 1;    /* one new submenu item */
  64.  
  65.         pmt->item[0].afStyle     = MIS_TEXT; /* text item */
  66.         pmt->item[0].afAttribute = 0;    /* no initial attributes */
  67.  
  68.                                         /* produces WM_COMMAND message with ID_SUBMENU value */
  69.             pmt->item[0].id          = ID_FIRSTITEM;
  70.         strcpy(pmt->item[0].text, "New menu item");
  71. #else
  72.                  /* initialize popup menu template; use defaults */
  73.         mt.size = 0;     /* length of menu template ???????? */
  74.         mt.version = 0;     /* template version. currently 0 */
  75.         mt.codepage = 850;     /* codepage used for text items within the menu
  76.                    (but not any submenus) */
  77.             mt.mnemonic = 0;     /* set to 0 for OS/2 v1.1 */
  78.         mt.itemcount = 1;     /* one new submenu item */
  79.  
  80.         mt.item[0].afStyle       = MIS_TEXT; /* text item */
  81.         mt.item[0].afAttribute = 0;    /* no initial attributes */
  82.                                            /* produces WM_COMMAND message with ID_FIRSTITEM value */
  83.             mt.item[0].id          = ID_FIRSTITEM;
  84.         strcpy(mt.item[0].text, "New menu item");
  85. #endif
  86.         /* get a handle to the windows menu */
  87.         hMenu = WinWindowFromID(hwndHelloFrame,FID_MENU);
  88.  
  89.         /* create a popup menu using template information */
  90.  
  91. #if ALLOCED
  92.         hSubMenu = WinCreateWindow(HWND_OBJECT,WC_MENU,NULL,WS_CLIPSIBLINGS | WS_SAVEBITS,
  93.               0,0,0,0,
  94.             hMenu,HWND_BOTTOM,0x3000,(PCH) pmt,0);
  95.         DosFreeSeg(sel);
  96. #else
  97.         hSubMenu = WinCreateWindow(HWND_OBJECT,WC_MENU,NULL,WS_CLIPSIBLINGS | WS_SAVEBITS,
  98.               0,0,0,0,
  99.             hMenu,HWND_BOTTOM,0x3000,(PCH)&mt,0);
  100. #endif
  101.  
  102.         hpsMenu=WinGetPS(hMenu);
  103.             hBitmap=GpiLoadBitmap(hpsMenu, (HMODULE) 0, 13, 0L, 0L);
  104.         WinReleasePS(hpsMenu);
  105.  
  106.         mi.iPosition = 1;              /* append item to end */
  107.         mi.afStyle     = MIS_BITMAP | MIS_SUBMENU;  /* text and menu style */
  108.         mi.afAttribute = 0;             /* no initial attributes */
  109.         mi.id     = ActionBarID;         /* ID of action bar menu item */
  110.         mi.hwndSubMenu = hSubMenu;            /* window handle of popup menu */
  111.         mi.hItem     = hBitmap;               /* handle for owner or bitmap item */
  112.  
  113.         /* insert the new action bar item */
  114.         WinSendMsg(hMenu,MM_INSERTITEM,(MPARAM) &mi,NULL);
  115.  
  116. /*        The following line adds the text to the action bar item,  not
  117. /*        needed when the action bar item is a bitmap
  118. /*
  119. /*         (MPARAM)(PCH)itoa(ActionBarID++,buffer,10)
  120. */
  121.         bPopCreated=TRUE;
  122.         }
  123.  
  124.     break;
  125.  
  126.     case ID_FIRSTITEM:
  127.     mi.iPosition = MIT_END;      /* append item to end */
  128.     mi.afStyle   = MIS_TEXT;     /* text style */
  129.     mi.afAttribute = 0;         /* no initial attributes */
  130.         mi.id        = ID_NEWITEM;             /* ID of action bar menu item */
  131.     mi.hwndSubMenu = NULL;
  132.         mi.hItem     = 0;                /* handle for owner or bitmap item */
  133.  
  134.     WinSendMsg(hSubMenu,MM_INSERTITEM,(MPARAM)&mi,
  135.           (MPARAM)(PCH)"Newly added item");
  136.     break;
  137.  
  138.     case ID_ADDTOSYSMENU:
  139.     /* Get handle of the [-] System Menu */
  140.     hWndSysMenu = WinWindowFromID (hwndHelloFrame, FID_SYSMENU);
  141.  
  142.     /* Get the id of the zeroth item of the system menu */
  143.         idSysMenu = (SHORT) (LONG) WinSendMsg (hWndSysMenu,
  144.                     MM_ITEMIDFROMPOSITION, 0L, 0L);
  145.  
  146.     /* Get the MENUITEM structure for the system menu */
  147.     WinSendMsg (hWndSysMenu,
  148.             MM_QUERYITEM,
  149.             (MPARAM)MAKEULONG (idSysMenu, FALSE),
  150.             (MPARAM)(PMENUITEM)&miSysMenu);
  151.  
  152.     /* Get handle of the system sub menu */
  153.     hWndSysSubMenu = miSysMenu.hwndSubMenu;
  154.  
  155.     mi.iPosition=0;     /* add to top of system menu */
  156.     mi.afStyle=MIS_TEXT;
  157.     mi.afAttribute=0;
  158.     mi.id=101;
  159.     mi.hwndSubMenu=NULL;
  160.         mi.hItem = 0;
  161.  
  162.     WinSendMsg(hWndSysSubMenu,
  163.            MM_INSERTITEM,
  164.            (MPARAM) &mi,
  165.            MPFROMP((PSZ) "Item text")
  166.           );
  167.     break;
  168.  
  169.     case ID_DELSYS:
  170.      WinSendMsg(hWndSysSubMenu,
  171.             MM_DELETEITEM,
  172.             MPFROM2SHORT((USHORT) 101, (BOOL) FALSE),
  173.             0L);    /* not used, must be zero */
  174.      break;
  175.  
  176.     case ID_TOGGLEHELP:
  177.         if (bHelp) {
  178.             /* Help is on now, turn it off */
  179.             bHelp=FALSE;
  180.             WinSetParent(hwndInfo, HWND_OBJECT, FALSE);
  181.             WinSendMsg(hwndHelloFrame, WM_UPDATEFRAME, FCF_MENU,0L);
  182.             }
  183.         else {
  184.             /* Help is off now, turn it on */
  185.             bHelp=TRUE;
  186.             WinSetParent(hwndInfo, hwndHelloFrame, FALSE);
  187.             WinSendMsg(hwndHelloFrame, WM_UPDATEFRAME, 0L,0L);
  188.             }
  189.  
  190.         break;
  191.  
  192.  
  193.     default:             /* show id of menu item selected */
  194.     MessageInt(hWnd,Menu,(PCH)"menuitem selected");
  195.     break;
  196.   }
  197. }
  198. 
  199.