4.win32 registering window classes and creating windows

Source: Internet
Author: User

1. registering window class functions

(1) Registerclass/registerclassex

ATOM registerclass (CONST wndclass *lpwndclass);

ATOM registerclassex (CONST wndclassex *lpwcx);

After successful registration, a non-0 digital ID is returned, and the failure returns 0.

(2) style of window class

Cs_globalclass-Application Global window class

Cs_bytealignclient-Horizontal position of window client area 8 full-fold data alignment

Cs_bytealignwindow-Horizontal position of the window 8 full-fold data alignment

Cs_hredraw-the window redraws when the window level changes

Cs_vredraw-the window redraws when the window changes vertically

CS_CLASSDC-the type of window that has the same drawing (DC) device

CS_PARENTDC-a drawing (DC) device that uses its parent window for that type of window

CS_OWNDC-the type of window that each window is using its own drawing (DC) device

Cs_savebits-Allows the window to be saved as a graph (bitmap), improving the efficiency of the drawing window, but consuming memory resources

Cs_dblclks-Allow window to receive mouse double-click

Cs_noclose-Window does not have a close button

The following is a simple example code:

#include"stdafx.h"voidAppreg () {//Register window classWndclassex WCE = {0 }; Wce.cbsize=sizeof(WCE);//sizeWce.cbclsextra =0;//the size of the window class additional data bufferWce.cbwndextra =0;//The size of the additional data buffer for the windowWce.hbrbackground = (hbrush) (color_window+1);//background is whiteWce.hcursor = NULL;//default CursorWce.hicon = NULL;//Default Large IconWCE.HICONSM = NULL;//Default Small iconWce.hinstance = g_hinstance;//Current Program Instance handleWce.lpfnwndproc = DefWindowProc;//System Default window handler functionWce.lpszclassname ="Main";//window class nameWce.lpszmenuname = NULL;//Window MenuWce.style = Cs_hredraw | Cs_vredraw;//window Style//write the above assignment to the operating systemATOM Natom = RegisterClassEx (&WCE); if(Natom = =0) {MessageBox (NULL,"Registration Failed","Info", MB_OK); return; } HWND hwnd= CreateWindow ("Main","Window", Ws_overlappedwindow, -, -, -, -, NULL, NULL, g_hinstance, NULL);    ShowWindow (HWnd, sw_show);    UpdateWindow (HWND); MSG umsg= {0 };  while(GetMessage (&umsg, NULL,0,0) {translatemessage (&umsg); DispatchMessage (&umsg); }}intapientry WinMain (hinstance hinstance, hinstance hprevinstance, LPSTR LpC Mdline,intccmdshow) {g_hinstance=hinstance;Appreg (); return 0;}

2. Create a window

(1) Create window function CreateWindow

(2) Internal execution process

CreateWindow uses two of these parameters to determine the window, CreateWindow ("Main", ..., g_hinstance, ...), which is the window class name and the current program instance handle.

A. The system looks in the application's local window class based on the name of the incoming window class and executes C if it finds execution B.

B. Compare the local window class with the HINSTANCE variable that was passed in when the window was created. If found equal, create and register the window in the same module, create the window to return. Otherwise, c is executed.

C. Look in the Application Global window class, if found, execute D, otherwise execute e.

D. Using the found window class information, create a window to return.

E. Look in the System window class, if found, create window, otherwise the window creation fails.

If the creation window succeeds, then CreateWindow requests the memory, writes the passed in memory, and returns the handle to the memory.

4.win32 registering window classes and creating windows

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.