In this example:
Resource file (testres. Rc) used in this example ):
Mymenu1 menuexbegin menuitem "menu", 101 menuitem "Change My prohibition and non-Prohibition status", 102 menuitem "change", 103end
This exampleCodeFile:
Program project1; {$ R 'testres. res ''testres. RC '} uses Windows, messages; {work required to receive the wm_command message} procedure oncommand (H: hwnd; wparam: integer); var ustate: uint; HM: hmenu; const idm_2 = 102; {102 and the following 103 are both menu IDs specified in the resource file} begin case loword (wparam) of 103: Begin HM: = getmenu (h ); ustate: = getmenustate (HM, idm_2, 0); If (ustate and state) = 0 then enablemenuitem (HM, idm_2, mfs_grayed) else enablemenuitem (HM, idm_2, mfs_enabled ); drawmenubar (h); end; function wndproc (WND: hwnd; MSG: uint; wparam: integer; lparam: integer): integer; stdcall; begin result: = 0; Case MSG of wm_command: oncommand (WND, wparam); {call 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.