In this example:
When you click any menu item, a wm_command message is sent. The lower two digits of the wparam parameter of the message are the integers that identify the menu item!
Resource file (testres. Rc) used in this example ):
# Define idm_new 101 # define idm_open 102 # define idm_save 103 # define idm_exit 104 # define idm_cut 201 # define idm_copy 202 # define idm_paste 203 # define idm_about extends menuex extends popup "& file ", 65535 begin menuitem "& New", idm_new menuitem "& Open", idm_open menuitem "& Save", idm_save menuitem separator menuitem "E & xit", idm_exit end popup "& edit ", 65535 begin menuitem "Cu & T", idm_cut menuitem "& copy", idm_copy menuitem "& Paste", idm_paste end popup "& help", 65535 begin menuitem "& about ", idm_about endend
This exampleCodeFile:
Program project1; {$ R 'testres. res ''testres. RC '} uses Windows, messages; {custom process for wm_command message call} procedure oncommand (wparam: integer); begin case loword (wparam) of 101: MessageBox (0, 'Is new', '', 0); 102: MessageBox (0, 'is open','', 0); 103: MessageBox (0, 'is save ', '', 0); 104: MessageBox (0, 'is exit ','', 0); end; function wndproc (WND: hwnd; MSG: uint; wparam, lparam: integer): integer; stdcall; begin result: = 0; Case MSG of wm_command: oncommand (wparam); {call the oncommand process after receiving the wm_command message} wm_destroy: postquitmessage (0); else result: = defwindowproc (WND, MSG, wparam, lparam); end; function regmywndclass: Boolean; var CLS: twndclass; begin Cls. style: = cs_hredraw or cs_vredraw; Cls. lpfnwndproc: = @ wndproc; Cls. cbclsextra: = 0; Cls. cbwndextra: = 0; Cls. hinstance: = hinstance; Cls. hicon: = 0; Cls. hcursor: = loadcursor (0, idc_arrow); Cls. hbrbackground: = hbrush (color_window + 1); Cls. lpszmenuname: = 'mymenu1'; Cls. lpszclassname: = 'mywnd'; Result: = registerclass (CLS) 0; end ;{Program Entry} const tit = 'new form'; Ws = ws_overlappedwindow; X = 100; y = 100; W = 300; H = 180; var hwnd: thandle; MSG: tmsg; begin regmywndclass; hwnd: = createwindow ('mywnd', tit, WS, X, Y, W, H, 0, 0, hinstance, nil); showwindow (hwnd, sw_shownormal ); updatewindow (hwnd); While (getmessage (MSG, 0, 0, 0) do begin translatemessage (MSG); dispatchmessage (MSG); end.