TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Will Morgan
from: Peter Fitzsimmons
date: 1995-12-30 05:38:16
subject: Permission to use your co

WM> My question -- I tried adding some code to make the four menu items
 WM> actually do something (snip & clipping from another PM programming

A menu (popup or normal) sends a WM_COMMAND message,  with the menu id,to
the "owner" window when the user selects a menu item.  Here is a
modified sample of my original "small" program.

Note that I fixed the "WM_BUTTON2DOWN" message with
WM_CONTEXTMENU,  as someone here suggested.


--[small.c]--
 #define INCL_WIN
 #include 
 #include "small.h"

 #define ID_WINDOW 1

 void pop(HWND hwnd, MPARAM mp1)
 {
     HWND hwndMenu;
     POINTS *p;
     hwndMenu = WinLoadMenu(hwnd, 0, ID_POPUPMENU);

     p = (POINTS *)&mp1;

     WinPopupMenu(hwnd, hwnd, hwndMenu, p->x, p->y, 0,
         PU_KEYBOARD | PU_MOUSEBUTTON1);

 }

 MRESULT EXPENTRY MyWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
 {
     char *str;
     switch (msg) {
         case WM_ERASEBACKGROUND:
             return (MRESULT) (TRUE);
         case WM_CONTEXTMENU:
             WinAlarm(HWND_DESKTOP, WA_NOTE);
             pop(hwnd, mp1);
             break;
         case WM_COMMAND:
             switch(SHORT1FROMMP(mp1)){
                 case ID_ONE  : str = "One" ; break;
                 case ID_TWO  : str = "Two" ; break;
                 case ID_THREE: str = "Three" ; break;
                 case ID_FOUR : str = "Four" ; break;
               default: str = "Error" ; break;
             }
             WinMessageBox(HWND_DESKTOP, hwnd, str, "Sample App",
0, MB_OK | MB_MOVEABLE);
             break;
         default:
             return WinDefWindowProc(hwnd, msg, mp1, mp2);
     }
     return 0;
 }

 int main(void)
 {
     HAB hab;
     HMQ hmq;
     HWND hwndClient;
     HWND hwndFrame;
     ULONG flCreate;
     QMSG qmsg;

     if (!(hab = WinInitialize(0)))
         return 1;

     if (!(hmq = WinCreateMsgQueue(hab, 0)))
         return 1;

     if (!WinRegisterClass(hab, (PSZ) "MyWindow", (PFNWP)
MyWindowProc, 0, 0))
         return 1;

     flCreate = FCF_SHELLPOSITION | FCF_SIZEBORDER | FCF_TASKLIST |
         FCF_SYSMENU | FCF_TITLEBAR;


     hwndFrame = WinCreateStdWindow(HWND_DESKTOP, WS_VISIBLE, &flCreate,
         "MyWindow", NULL, 0, 0, ID_WINDOW, &hwndClient);

     if (!hwndFrame || !hwndClient)
         return 1;                       /* couldn't create window for some
                                          * reason. */


     while (WinGetMsg(hab, &qmsg, 0L, 0, 0))
         WinDispatchMsg(hab, &qmsg);

     WinDestroyWindow(hwndFrame);
     WinDestroyMsgQueue(hmq);
     WinTerminate(hab);

     return 0;
 }

--[small.h]--
 #define ID_POPUPMENU 99
 #define ID_ONE    100
 #define ID_TWO    101
 #define ID_THREE  102
 #define ID_FOUR   103

--[small.rc]--
 #include "small.h"

 MENU ID_POPUPMENU
 {
     MENUITEM "One",     ID_ONE
     MENUITEM "Two",     ID_TWO
     MENUITEM "Three",   ID_THREE
     MENUITEM "Four",    ID_FOUR
 }

--[g.cmd]--
  icc /Kb+ /B"/pm:pm" small.c
  rc small.rc


--- Maximus/2 3.00
* Origin: Sol 3 * Toronto * V.32 * (905)858-8488 (1:259/414)
SEEN-BY: 270/101 620/243 711/401 409 410 413 430 808 809 934 955 712/407 515
SEEN-BY: 712/517 628 713/888 800/1 7877/2809
@PATH: 259/414 400 99 250/99 3615/50 396/1 270/101 712/515 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.