Windows Programming [3]-process 3 of learning form generation

Source: Internet
Author: User
According to the previous theory, the Framework generated by a window should look like this:
 
Program project1; uses Windows; {all the previously mentioned functions come from Windows units} var hwnd: thandle; {declaration window handle} mywndclass: twndclass; {declare a window type} begin // set the mywndclass parameters (such as window icons, cursors, and painter) here ), including specifying "Class Name" {then registering} registerclass (mywndclass); {creating and returning handle} hwnd: = createwindow (class name, title, style, X, Y, width, high, 0, 0, hinstance, nil); {display} showwindow (hwnd, sw_shownormal); end.

  

The window type twndclass is actually a structure, which is the rename of the tagwndclassa structure.

{Tagwndclassa structure:} tagwndclassa = packed record style: uint; {window style, see the table below} lpfnwndproc: tfnwndproc; {pointer to the window callback function, which should be analyzed in detail later} cbclsextra: integer; {extra space allocated for the window class, generally 0} cbwndextra: integer; {extra space allocated for the window instance, generally 0} hinstance: hinst; {Window Location Program The handle of the instance, that is, hinstance} hicon: hicon; {specify the window icon, which is generally loaded with loadicon; do not specify 0} hcursor: hcursor; {specify the window cursor, generally, loadcursor is used for loading. If this parameter is not specified, it can be set to 0} hbrbackground: hbrush; {specify the window background for image painting. You need to use the getstockobject function for retrieval. You can also specify the system color.} lpszmenuname; {menu resource name; generally set to nil, indicating that the window has no default menu} lpszclassname: pansichar; {name the window class; createwindow function will use this name} end; // optional window style parameter value: cs_vredraw = DWORD (1); {the window height will be repainted} cs_hredraw = DWORD (2 ); {The window width will be repainted} cs_keycvtwindow = 4; {} cs_dblclks = 8; {do not ignore the message of double-clicking the mouse} cs_owndc = $20; {assign an independent device DC to each window created with this class} cs_classdc =40 40; {share a device DC with all windows of this class} cs_parentdc = $80; {subwindows allowed to inherit some common features} cs_nokeycvt = $100 ;{} cs_noclose =$ 200; {disable the close command of the System menu, at the same time, the window is not closed.} cs_savebits = $800; {when the window is overwritten, a bitmap is used to cache the coverage area to avoid wm_paint messages. This is generally used in menus or dialogs.} cs_bytealignclient = $1000; {enhancing the Drawing Performance of the customer zone through byte alignwindow} cs_bytealignwindow = $2000; {enhancing the Drawing Performance of the window through byte alignwindow} cs_globalclass = $4000; {global window class, this option is generally used for DLL. Without this option, the instance handle specified in the window class and window creation function must be the same} // For the window background painter: {some painter is predefined by the system, getstockobject needs to be used for retrieval based on the specified constant;} {but the handle returned by getstockobject may be a paint brush, paint brush, color palette, or system font handle ,} {therefore, you also need to convert the type of the handle returned by getstockobject, for example, hbrush (getstockobject (constant)} // The following is the optional value of the getstockobject function parameter: white_brush = 0; ltgray_brush = 1; gray_brush = 2; dkgray_brush = 3; black_brush = 4; null_brush = 5; hollow_brush = null_brush; white_pen = 6; black_pen = 7; null_pen = 8; Limit = 10; keys = 11; ansi_var_font = 12; system_font = 13; device_default_font = 14; default_palette = 15; system_fixed_font = $10; keys = 17; dc_brush = 18; dc_pen = 19; stock_last = 19; {In addition, you can use Windows to define system color constants, for example, hbrush (color_window + 1)} color_scrollbar = 0; color_background = 1; color_activecaption = 2; 3; color_menu = 4; color_window = 5; color_windowframe = 6; color_menutext = 7; color_windowtext = 8; color_captiontext = 9; color_activeborder = 10; color_inactiveborder = 11; color_appworkspace = 12; color_highlight = 13; color_highlighttext = 14; color_btnface = 15; color_btnshadow = $10; color_graytext = 17; color_btntext = 18; gradient = 19; gradient = 20; color_3ddkshadow = 21; color_3dlight = 22; color_infotext = 23; color_infobk = 24; color_hotlight = 26; rows = 27; rows = 28; rows = 29; color_menubar = 30; color_endcolors = color_menubar; color_desktop = color_background; color_3dface = color_btnface; color_3dshadow = color_btnshadow; color_3dhighlight = color_btnhighlight; color_3dhilight = color_btnhighlight; color_btnhilight = color_btnhighlight;
 
   
 

Sort out the following ideas:

To display a window, you must first create a window;
To create a window, you must first register a window type;
Before registration, you must specify various features for the window type. The most important of these features is to specify the "window callback function "!
This callback function must follow the format specified by Windows (only the function name and parameter name can be changed ):

 
Function wndproc (WND: hwnd; MSG: uint; wparam: integer; lparam: integer): integer; stdcall; begin... end;

  

The callback function processes all messages sent to the window;

However, there are a lot of messages that cannot be processed at all. unwanted messages must be processed by default using the defwindowproc function.

The parameters of the defwindowproc function and the callback function remain unchanged, and return the returned values required by the callback function.

For example, we only process the wm_destroy message:

 
Function wndproc (WND: hwnd; MSG: uint; wparam: integer; lparam: integer): integer; stdcall; begin if MSG = wm_destroy then... else result: = defwindowproc (WND, MSG, wparam, lparam); end;

  
Related Article

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.