In this example:
Program project1; uses Windows, messages; {custom process for wm_lbuttondown message calling} procedure onlbuttondown (H: hwnd); var brushhandle: hbrush; rect: trect; begin getclientrect (H, rect); {obtain the client rectangle} brushhandle: = createsolidbrush (RGB (255, 0); {build a red brush} fillrect (getdc (H), rect, brushhandle ); {fill customer area} deleteobject (brushhandle); {Delete brush} end; {custom process called by the wm_lbuttonup message} procedure onlbuttonup (H: hwnd); var rect: trect; begin getclientrect (H, rect); {obtain the client region rectangle} invalidaterect (H, @ rect, true); {force re-draw} end because the client region is invalid; {custom process for wm_mousemove message call} procedure onmousemove (H: hwnd; lparam: integer); var PT: tpoint; Buf: array [0 .. 255] of char; begin PT. x: = loword (lparam); {the lower two digits in lparam are X coordinates} PT. y: = hiword (lparam); {the height two digits in lparam are Y coordinates} wvsprintf (BUF, '% d, % d', @ pt ); {format to buffer} setwindowtext (H, Buf); {display in title} end; function wndproc (WND: hwnd; MSG: uint; wparam: integer; lparam: integer ): integer; stdcall; begin result: = 0; Case MSG of wm_lbuttondown: onlbuttondown (WND); {message pressed by the left mouse button} wm_lbuttonup: onlbuttonup (WND ); {left-mouse-lifted message} wm_mousemove: onmousemove (WND, lparam); {cursor-moved message, coordinate in lparam} 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: = nil; 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.