CreateWindow function Explanation
After registering the window class, you need to create the window, the function used is CreateWindow (), and this function is based on the window class, so you also need to specify a few parameters to make a specific window. And it's pretty tricky to create a window that doesn't have a border, like a window without a frame, and then draw the program's content in the client area to create a personalized application.
API explanation
This function creates an overlapping window, pop-up window, or child window. It specifies the window class, window caption, window style, and the initial position and size of the window (optional). The function also refers to the window's parent window or its owning window (if one exists), and the window's menu.
To use an out-of-style extension style that is supported by the CreateWindow function, use the CREATEWINDOWEX function instead of the CreateWindow function.
API function Prototypes:
HWND WINAPI CreateWindow (
_in_opt_ lpctstrlpclassname,//window class name
_in_opt_ lpctstrlpwindowname,//window title
_in_ DWORD dwstyle,//window style, or window format
_in_ int x,//initial X coordinate
_in_ int y,//initial y-coordinate
_in_ int nwidth,//initial X-direction size
_in_ int nheight,//initial y-direction dimensions
_in_opt_ Hwndhwndparent,//parent window Handle
_in_opt_ hmenuhmenu,//Window menu handle
_in_opt_ hinstancehinstance,//program instance handle
_in_opt_ Lpvoidlpparam//Create Parameters
);
Note: _in_ indicates that the parameter is input, _opt_ that the parameter is an optional parameter (instead of having no arguments, you can take advantage of the macro collocation parameter).
Parameter resolution:
Parameters |
Meaning |
Lpclassname |
1. Window class name, which can be a NULL-terminated string or an integer value 2. If it is a string, it specifies the window's class name. This class name can be any class name registered with the function registerclass, or any predefined control class name 3. As an integer, it is the global amount generated by the previous call to the Theglobaladdatom function. This 16-digit number less than 0xc000 must be a low 16-bit of the lpclassname parameter word, and the high-key must be 0 |
Lpwindowname |
1. Window caption, a pointer to NULL-terminated string 2. If the window style specifies a title bar, the window caption pointed to by Lpwindowname will be displayed on the title bar 3. When using the CreateWindow function to create controls such as buttons, selection boxes, and static controls, you can use Lpwindowname to specify control text |
Dwstyle |
Specifies the style of the creation window (see below ↓) |
X |
1. Specify the initial horizontal position of the window (x-coordinate) 2. For a cascading or pop-up window, the x parameter is the initial x-coordinate of the upper-left corner of the screen coordinate system's window 3. For child windows, X is the initial x-coordinate of the upper-left corner of the child window relative to the upper-left corner of the parent window's client area 4. If the parameter is set to Cw_usedefault, the system selects the default upper-left coordinate for the window and ignores the y-parameter, Cw_usedefault is only valid for the Cascade window, and if set for a pop-up window or Subwindow, the x and Y parameters are set to zero. |
Y |
1. Specify the initial vertical position of the window (y-coordinate) 2. For a cascading or pop-up window, the y parameter is the initial y-coordinate of the upper-left corner of the screen coordinate system's window 3. For child windows, Y is the initial y-coordinate of the upper-left corner of the child window relative to the upper-left corner of the parent window's client area 4. For the list box, Y is the initial y-coordinate of the upper-left corner of the customer area of the list box relative to the parent window's upper-left corner 5. If the Cascade window is created using the ws_visible style bit and the x parameter is set to Cw_usedefault, the system ignores the y parameter |
Nwidth |
1. Specify the width of the window in device units 2. For cascading windows, the value of nwidth or the window width of screen coordinates or Cw_usedefault 3. If nwidth is Cw_usedefault, the system selects a default height and width for the window (the default width is from the initial X coordinate to the right edge of the screen, and the default height is from the initial y-coordinate to the top of the target area.) ), Cw_usedefault is only valid for cascading windows, and nwidth and nheight are set to zero if the CW_USEDEFAULT flag is set for pop-up windows and child windows |
Nheight |
1. Specify the height of the window in device units 2. For cascading windows, nheight is the window width of screen coordinates 3. If nwidth is set to Cw_usedefault, the system ignores the nheight parameter and automatically sets default parameters for Nwidth and nheight. |
hWndParent |
1. Handle to the parent window or owner window of the created window 2. To create a child window or a subordinate window, provide a valid window handle 3. Create a simple message window that can provide hwnd_message or provide a handle to a message window that already exists |
HMenu |
1. point to the Window menu handle, or specify a subwindow identifier according to the window style 2. For cascading or pop-up windows, HMenu specifies the menu used by the window: HMenu can be NULL if a menu class is used 3. For a subwindow, hMenu specifies the child window identifier (an integer), and a dialog box uses this integer value to notify the parent class of the event. The application determines the child window ID, which must be unique for all child windows of the same parent window |
HInstance |
Handle to the module instance associated with the window |
Lpparam |
1. A pointer to a value that is passed to the window wm_create message. This value is passed through the CREATESTRUCT structure in the Iparam parameter 2. If the application calls CreateWindow to create an MDI client window, the Lpparam must point to a clientcreatestruct structure |
Dwstyle window Style parsing
Window style |
Meaning |
Ws_border |
Create a window with a border |
Ws_caption |
Create a window with a title box (Ws_boder style included) |
Ws_child |
Create a sub-window, this style of the window can not have a menu and can not be combined with ws_popup style |
Ws_childwindow |
Same as Ws_child |
Ws_clipchildren |
Excludes child window areas when drawing within the parent window, using this style when creating a parent window |
Ws_clipsiblings |
1. Exclude the relative area between sub-windows, that is, when a particular window receives a WM_PAINT message, the ws_clipsiblings style excludes all cascading windows from the drawing and redraws only the specified child window 2. If the style is not specified and the child window is stacked, the adjacent child window is redrawn when the client area of the child window is redrawn |
Ws_disabled |
1. Create a child window with an initial status of forbidden, a window with no status can not accept input from the user 2. After the window is created, you can call the EnableWindow function to enable the window |
Ws_dlgframe |
Create a window with a dialog border style that cannot be styled with a title bar |
Ws_group |
1. Specify the first control window for a set of control windows 2. This "Control window" group consists of the first "control window" and the "control window" defined subsequently, and each "control window" has a ws_group style starting from the second control window. 3. The first "control window" for each group has a ws_tabstop style, which allows the user to move between groups 4. The user can then use the cursor to change keyboard focus between controls within the group |
Ws_hscroll |
Create a window with a horizontal scroll bar |
Ws_iconic |
Create a window with the initial state minimized, the same as the ws_minimize style |
Ws_maximize |
Creates a window with an initial state of maximized state |
Ws_maximizebox |
Creates a window with a maximized button that does not appear at the same time as the Ws_ex_contexthelp style, and must specify the Ws_sysmenu style |
Ws_minimize |
Create a window with the initial state minimized, the same as the Ws_iconic style |
Ws_minimizebox |
Create a window with a minimized button that does not appear at the same time as the Ws_ex_contexthelp style and must specify the Ws_sysmenu style |
Ws_overlapped |
Produces a cascade of Windows, a cascading window with a title bar and a border, the same as the ws_tiled style |
Ws_overlappedwindow |
Equivalent (ws_overlapped | ws_caption | Ws_sysmenu | Ws_thickframe | Ws_minimizebox | Ws_maximizebox), the same as the Ws_tiledwindow style |
Ws_popup |
Creates a pop-up window that cannot be used in conjunction with the Ws_child style. |
Ws_popupwindow |
Equivalent (Ws_popup | Ws_border | Ws_sysmenu), but ws_caption and Ws_popupwindow must be set at the same time to make the window a single visible |
Ws_sizebox |
Create a window with adjustable border, same as Ws_thickframe style |
Ws_sysmenu |
To create a window with a Window menu on the title bar, you must also set the Ws_caption style |
Ws_tabstop |
1. Create a control window to get keyboard focus when the user presses the Tab key. 2. Press the TAB key to move the keyboard focus to the next control window with the Ws_tabstop style |
Ws_thickframe |
Create a window with adjustable border, same as Ws_sizebox style |
Ws_tiled |
Produces a cascade of Windows with a cascading window with a caption and a border, the same as the ws_overlapped style |
Ws_tiledwindow |
Equivalent (ws_overlapped | ws_caption | Ws_sysmenu | Ws_thickframe | Ws_minimizebox | Ws_maximizebox), the same as the Ws_overlappedwindow style |
Ws_visible |
Create a window with an initial state of visible |
Ws_vscroll |
Create a window with a vertical scroll bar |
return value:
1. If the function succeeds, the return value is a handle to the new window.
2. If the function fails, the return value is NULL.
Application examples
Create a window program with a vertical scrollbar and a horizontal scroll bar
HWND =createwindow (Szappname,
TEXT ("vertical and horizontal scroll bars"),
Ws_overlappedwindow | Ws_hscroll | Ws_vscroll,//| The above two parameters can be
Cw_usedefault,
Cw_usedefault,
Cw_usedefault,
Cw_usedefault,
Null
Null
HINSTANCE,
NULL);
Create a Win32 program that the user cannot manipulate
HWND =createwindow (Szappname,
TEXT ("vertical and horizontal scroll bars"),
ws_disabled,//modify as a loss-of-energy parameter
Cw_usedefault,
Cw_usedefault,
Cw_usedefault,
Cw_usedefault,
Null
Null
HINSTANCE,
NULL);
Three use pop-up windows to create a window without Borders and title bars
HWND =createwindow (Szappname,
TEXT ("vertical and horizontal scroll bars"),
Ws_popup,//pop-up window, and to modify the length-width
Cw_usedefault,
Cw_usedefault,
Cw_usedefault,
Cw_usedefault,
Null
Null
HINSTANCE,
NULL);
Four pop-up windows with borders
HWND =createwindow (Szappname,
TEXT ("vertical and horizontal scroll bars"),
Ws_popup | Ws_sizebox,//pop-up window, and to modify the length-width
Cw_usedefault,
Cw_usedefault,
Cw_usedefault,
Cw_usedefault,
Null
Null
HINSTANCE,
NULL);