In this example:
Create a new console program and paste the following code to run it:
Program project1; uses Windows, messages; {the process of waiting for calling, used to draw text on the form} procedure onpaint (H: HDC); const S = 'codegear Delphi 2007 '; begin textout (H, 10, 10, pchar (s), length (s); end; {window callback process} function wndproc (WND: hwnd; MSG: uint; wparam: integer; lparam: integer): integer; stdcall; var handle: HDC; PS: paintstruct; begin case MSG of wm_paint: Begin handle: = beginpaint (WND, PS ); onpaint (handle); endpaint (WND, PS); Result: = 0; end; wm_destroy: Begin postquitmessage (0); Result: = 0; end; else result: = defwindowproc (WND, MSG, wparam, lparam); end; {main program} var hwnd: thandle; MSG: tmsg; mywndclass: twndclass; begin mywndclass. style: = cs_hredraw or cs_vredraw; mywndclass. lpfnwndproc: = @ wndproc; mywndclass. cbclsextra: = 0; mywndclass. cbwndextra: = 0; mywndclass. hinstance: = hinstance; mywndclass. hicon: = loadicon (0, idi_question); mywndclass. hcursor: = loadcursor (0, idc_arrow); mywndclass. hbrbackground: = hbrush (getstockobject (white_brush); mywndclass. lpszmenuname: = nil; mywndclass. lpszclassname: = 'mywindowclass'; registerclass (mywndclass); hwnd: = createwindow ('mywindowclass', 'This is the window title', ws_overlappedwindow, 100,100,250,150, 0, 0, hinstance, nil ); showwindow (hwnd, sw_shownormal); updatewindow (hwnd); While (getmessage (MSG, 0, 0, 0) do begin translatemessage (MSG); dispatchmessage (MSG); end; end.
We plan to start from here to learn more about the underlying things. First, let's understand the code!