In this example:
Resource file (testres. Rc) used in this example ):
Mymenu1 menuexbegin menuitem "file", 101 menuitem "add", 102end
This exampleCodeFile:
Program project1; {$ R 'testres. res ''testres. RC '} uses Windows, messages; var I: Word = 1; {work required to receive the wm_command message} procedure oncommand (H: hwnd; wparam: integer); var s: string; begin case loword (wparam) of 102: begin {102 is the menu identifier specified in the resource file} STR (I, S); s: = 'newmenu _ '+ S; appendmenu (getmenu (H), mft_string or mft_menubreak, I, pchar (s); drawmenubar (h); Inc (I); end; else begin STR (wparam, S); MessageBox (0, pchar (s), '', 0); 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 wm_command message received} 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.