Program project1; uses Windows, messages; {callback function; among them, there are many messages to be processed. It is best to use the case statement} function wndproc (WND: hwnd; MSG: uint; wparam: integer; lparam: integer): integer; stdcall; begin result: = 0; Case MSG of wm_destroy: postquitmessage (0); {after receiving wm_destroy, send wm_quit message to indicate to exit} else {other messages are delivered to defwindowproc for processing; defwindowproc will return the returned value required by the callback function} result: = defwindowproc (WND, MSG, wparam, lparam); end; end; {function for registering and registering window classes} function regmywndclass: Boolean; var mywndclass: twndclass; begin {specified window type} mywndclass. style: = cs_hredraw or cs_vredraw; {re-paint after changing the size} mywndclass. lpfnwndproc: = @ wndproc; {callback function pointer} mywndclass. cbclsextra: = 0; {No additional window class information} mywndclass. cbwndextra: = 0; {No additional window information} mywndclass. hinstance: = hinstance ;{ Program Instance handle} mywndclass. hicon: = 0; {No icon specified} mywndclass. hcursor: = loadcursor (0, idc_arrow); {the pointer provided by the system is selected} mywndclass. hbrbackground: = hbrush (color_btnface + 1); {use the default Windows button color for the background color} mywndclass. lpszmenuname: = nil; {default menu not specified} mywndclass. lpszclassname: = 'mywindowclass'; {name the window type} result: = registerclass (mywndclass) 0; {register the window type} end; {main program} var hwnd: thandle; MSG: tmsg; begin {call the function in the registration and registration window} if not regmywndclass Then begin MessageBox (0, 'window class registration failed! ',' Hint ', mb_ OK + mb_iconerror); exit; end; {create a window and return a handle. Since createmediawex exists, createwindow is not used.} hwnd: = createmediawex (0, {do not use extended style} 'mywindowclass', {window type name} 'new Window', {Title} ws_overlappedwindow, {regular window style} INTEGER (cw_usedefault ), {default horizontal position} INTEGER (cw_usedefault), {default vertical position} INTEGER (cw_usedefault), {default width} INTEGER (cw_usedefault), {default height} 0, {No parent window} 0, {No Main Menu} hinstance, {instance handle} nil {no additional information}); If hwnd = 0 then {If window Interface creation failed} begin MessageBox (0, 'window creation failed! ',' Hprompt ', mb_ OK + mb_iconerror); exit; end; {display window and update window} showwindow (hwnd, sw_shownormal); updatewindow (hwnd); {message loop; getmessage will return false upon receiving the wm_quit message to terminate the loop} while (getmessage (MSG, 0, 0, 0) do begin translatemessage (MSG ); {re-processing of some keyboard messages} dispatchmessage (MSG); {send the message to the callback function} end; halt (MSG. wparam); {the message loop program will naturally exit without it. In addition, the program will automatically exit} End Based on the exit code.