Windows Programming [6]-process 6 of learning form generation: Final code!

Source: Internet
Author: User
Tags case statement
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.
 
  
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.