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

Source: Internet
Author: User
I have done the simplest windows Program : Create a New Delphi console program and paste the following Code To run.

 
Program project1; uses Windows; begin MessageBox (0, pchar ('OK! '), Pchar ('title'), 0); end.

  

Code analysis: the system function MessageBox can generate a message window. Because this function comes from a Windows unit, uses Windows is required;

Similarly, we can use the shellabout in the shellapi unit to call a window:

 
Program project1; uses shellapi; begin shellabout (0, 'in case of Delphi blog', 'copyright: In case ', 0); end.

  

However, these are windows fixed mode and fixed function windows. What if I create a normal window?

The idea of using the forms. tform class is abandoned for the moment, so that everything starts from the beginning, that is, from the Windows API.

The code we can think of now should be like this:

Program project1; begin // create window createwindow // display window showwindowend.

  

Know the showwindow function:

 
Showwindow (hwnd: hwnd; {handle of the window to be displayed} ncmdshow: INTEGER {option, in the table below}): bool; // optional value of the ucmdshow parameter: sw_hide = 0; {hide, and the taskbar is not minimized.} sw_shownormal = 1; {display with the nearest size and position. Activate} sw_normal = 1; {same as sw_shownormal} sw_showminimized = 2; {minimize, activation} sw_showmaximized = 3; {maximize, activation} sw_maximize = 3; {same as sw_showmaximized} sw_shownoactivate = 4; {display with the nearest size and position, not activated} sw_show = 5; {same as sw_shownormal} sw_minimize = 6; {minimized, not activated} sw_showminnoactive = 7; {same as sw_minimize} sw_showna = 8; {same as sw_shownoactivate} sw_restore = 9; {same as sw_shownormal} sw_showdefault = 10; {same as sw_shownormal} sw_max = 10; {same as sw_shownormal}

  

Understand the createwindow function:

Createwindow (lpclassname: pchar; {window class name} lpwindowname: pchar; {window title} dwstyle: DWORD; {window style, in the following Table} X, Y: integer; {position; the default X and Y values can be specified as: INTEGER (cw_usedefault)} nwidth, nheight: integer; {size; default width and height can be specified as: INTEGER (cw_usedefault)} hwndparent: hwnd; {parent window handle} hmenu: hmenu; {main menu handle} hinstance: hinst; {module instance handle, that is, the current EXE handle} lpparam: pointer {additional parameter, it is used only when the multi-document interface is created, generally set to nil}): hwnd; {return the handle of the created window} // optional value of the dwstyle window style parameter: ws_overlapped = 0; {overlapping window, with title bar and border} ws_popup = DWORD ($80000000); {pop-up window, cannot be used with ws_child} ws_child = $40000000; {Child window, cannot be used with ws_popup} ws_minimize = $20000000; {minimal window} ws_visible = $10000000; {visible at initial time} ws_disabled = $8000000; {forbidden input} ws_clipsiblings = $4000000; {crop the child window, that is, the re-painting of the Child Window does not affect other child windows that overlap. It should be used with ws_child.} ws_clipchildren = $2000000; {when drawing in the parent window, bypass the Child Window area. When creating the parent window, use} ws_maximize = $1000000; {maximum window} ws_caption = $ c00000; {Title bar} ws_border = $800000; {thin border} ws_dlgframe = $400000; {dialog box} ws_vscroll = $200000; {vertical scroll bar} ws_hscroll = $100000; {horizontal scroll bar} ws_sysmenu = $80000; {with system title bar, ws_caption must be specified at the same time} ws_thickframe = $40000; {bandwidth border, wide border is used to change the window size} ws_group = $20000; {focus can be transferred using the direction key} ws_tabstop = $10000; {focus can be transferred using tab} ws_minimizebox = $20000; {minimized button} ws_maximizebox = $10000; {maximized button} ws_tiled = ws_overlapped; ws_iconic = ws_minimize; ws_sizebox = ws_thickframe; partition = (partition or ws_caption or partition or ws_thickframe or ws_minimizebox or partition); ws_tiledwindow = partition; ws_popupwindow = (ws_popup or ws_border or partition); ws_childwindow = (ws_child ); // There are also some extended styles: ws_ex_dlgmodalframe = 1; {specify the dual border window; Specify ws_caption to create the title bar} ws_ex_noparentnotify = 4; {do not send the wm_parentnotify message to the parent window when the window is created or canceled} ws_ex_topmost = 8; {above all non-top-level windows} ws_ex_acceptfiles = $10; {acceptable drag-and-drop file} ws_ex_transparent = $20; {transparent style. This window can be repainted only when the same window has been repainted} ws_ex_mdichild = $40; {create an MDI subwindow} ws_ex_toolwindow = $80; {tool window} ws_ex_javaswedge = $100; {border with a stereo} ws_ex_clientedge = $200; {shadow border} ws_ex_contexthelp = $400; {the title contains a question mark and cannot be used with ws_maximizebox or ws_minimizebox.} ws_ex_right = $1000; {window has right alignment attribute} ws_ex_left = 0; {window has left alignment attribute, ws_ex_left is the default setting} ws_ex_rtlreading = $2000; {window text from right to left} ws_ex_ltrreading = 0; {window text from left to right, ws_ex_ltrreading is the default setting} ws_ex_leftscrollbar = $4000; {the vertical scroll bar is on the left border, used only for special language environments} ws_ex_rightscrollbar = 0, ws_ex_rightscrollbar is the default setting} ws_ex_controlparent = $10000; {allows you to use the tab key to search between window subwindows} ws_ex_staticedge = $20000; {create a 3D border when the window is unavailable} ws_ex_appwindow = $40000; {place a top-level window on the job bar when the window is visible} ws_ex_overlappedwindow = (ws_ex_shortwedge or ws_ex_clientedge ); {stereo border with shadow} ws_ex_palettewindow = (ws_ex_javaswedge or ws_ex_toolwindow or ws_ex_topmost); {stereo border, toolbar window style, top layer} ws_ex_layered = $00080000; {layered or transparent window, this style can use mixed effects} ws_ex_noinheritlayout = $00100000; {Child Window does not inherit the layout of the parent window} ws_ex_layoutrtl = $00400000; {layout from right to left} ws_ex_composited = $02000000; {draw all descendants of the window from bottom to top with double buffering} ws_ex_noactivate = $08000000; {on top but not activated}
 
   
 

Analysis:

You must create a window using createwindow before using showwindow to display the window; Because showwindow requires the handle returned by createwindow.

In the parameters of createwindow, the position and size and the window title are needless to say;
The parent window and menu are not required at the moment. You can set them to 0 first;
The handle of the program instance. Delphi has prepared the hinstance for US (see the original instructions)
In the previous example, we used ws_overlappedwindow, which represents a combination of several features and a regular window.

Createwindow also has an important parameter (the first parameter is the name of the window class.
For Windows, you must register and register a window class before using createwindow to create a window!

For details about the control style, refer:
 es_left = 0; {left alignment} es_center = 1; {Center} es_right = 2; {right alignment} es_multiline = 4; {multiple rows} es_uppercase = 8; {all uppercase} es_lowercase = $10; {all lowercase} es_password = $20; {mask character} es_autovscroll = $40; {auto vertical scroll} es_autohscroll = $80; {auto horizontal scroll} es_nohidesel = $100; {always show selected part} es_oemconvert = $400; {enable conversion between ANSI and OEM} es_readonly = $800; {read-only} es_wantreturn = $1000; {line breaks are acceptable} es_number = $2000; {only digit input is allowed}

   

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.