Win32 Windows Programming Four

Source: Internet
Author: User
Tags win32 window

A Window registration and window creation process

1 WIN32 Window Program creation steps

Definition of 1.1 WinMain entry function

Definition of 1.2 windowsproc function

1.3 Registration window

Registerclass/registerclassex

1.4 Creating windows

Createwindow/createwindowex

1.5 Display Refresh Window

Showwindow/updatewindow

1.6 Message Processing

Getmessage/disptchmessage

1.7 Window Exit

Wm_destroy:postquitmessage

2 Registration of Windows

2.1 Categories of Windows

2.1.1 System global Class button text Box toolbar

The 2.1.2 Application Global window class, which can be used in EXE and DLL Windows.

2.1.3 The local window class. A window class that can be used only in this module.

2.2 Registration of the implementation window

2.2.1 System Global window class, no need to register for direct use. Using the CreateWindow function, specify the window type name that the system has defined in the classname

The 2.2.2 application's global window class, which needs to be implemented in code, requires an additional Cs_globalclass definition implementation at the time of registration:

Wndclass WC = {0};

Wc.style = Cs_globalclass;

.....

RegisterClass (&WC);

2.2.3 Local window class, cannot add Cs_globalclass definition

Register with Registerclass/registerclassex

typedef struct _WNDCLASSEX {     UINT       cbsize;    //Structure size    UINT           WNDPROC    lpfnwndproc;     int        Cbclsextra;     int        Cbwndextra;     HInstance  hinstance;     Hicon      Hicon;     Hcursor    hcursor;     Hbrush     Hbrbackground;     LPCTSTR    Lpszmenuname;     LPCTSTR    lpszClassName;     Hicon      
   2.2.4 The style of the window class
Cs_hredraw window         Horizontal change, redraw window
Cs_vredraw    window changes vertically, redraws the window
Cs_globalclass    Creating a Program Global window class
   You can accept the mouse double-click message
Cs_bytealignclient Customer area alignment in multiples of 8
Cs_bytealignwindow window Alignment
CS_CLASSDC  All windows of this type use a DC (Device description table drawing used)
CS_OWNDC  Each window has its own DC
CS_PARENTDC     using the parent window's DC
is to save the window with a bitmap to improve the refresh performance of the window interface.
Cs_noclose  prohibit close command
   2.2.5 Additional data for the window class  Cbclsextra Add your own information to the data information of the window class
Cbclsextra the size of the memory used to add information, typically a multiple of 4
Setclasslong Saving information to memory
Getclasslong the information out of memory
DWORD Getclasslong (  hwnd  hwnd,  //Handle to Windowint NIndex  Offset of value to retrieve);
   
Add your own information to the window's data message
Cbwndextra The amount of memory used to add information
SetWindowLong
LONG SetWindowLong (  hwnd  hwnd,       //Handle to Windowint  NIndex,      //offset of value to setLONG  dwnewlong   //New Value);
GetWindowLong
LONG GetWindowLong (  hwnd  hwnd,  //Handle to Windowint  nIndex  //offset of value to retrieve);

2.3 Window class-related functions

Registerclass/registerclassex Registration

Unregisterclass logoff

Getclassinfo/getclassinfoex Getting Information

GetClassName get the name of the window class

Getclasslong/setclasslong setting up and getting additional data

Getwindowlong/setwindowlong setting up and getting additional data

2.4 How to locate a window class when creating a window

2.4.1 Find the application's local window class. If execution 2.4.2 is found, perform 2.4.3

2.4.2 If a window class with a consistent name is found, compare the hinstance handle, and if so, create a window using the found window class information, and if different, continue to find

2.4.3 If a window class with a consistent name is not found, it will continue to be found in the Application Global window class, or execute if 2.4.4 is located 2.4.5

2.4.4 Global window found consistent, create window using Find window class information

2.4.5 if not found, go to the System Global window class to find, if found, create window, otherwise return failed

3. Window creation

3.1 Window creation function

Createwindow/createwindowex

HWND CreateWindowEx (DWORDdwExStyle, Extended extended styles for window style windowsLPCTSTRLpclassname, Registered class nameLPCTSTRLpwindowname, Window nameDWORDdwstyle, Window styleintx, Horizontal position of windowinty, Vertical position of windowintnwidth, Window widthintnheight, Window heightHWNDhwndparent, Handle to Parent or owner windowHMENUHMenu, Menu handle or child identifierhinstancehinstance, Handle to Application instancelpvoidLpparamWindow-creation data);

3.2 window style and extended style

Window style: Ws_xxxx defined style, is the basic style of the window

Extended style: Ws_ex_xxxx defined style is the extension style of the window

Extended style requires the use of Crearewindowex

Ws_overlappedwindow Cascade window

Ws_popup Pop-up window

Ws_child Window child window


3.3 Parent window and child window

3.3.1 CreateWindow when specifying a parent window

3,3.2 adds the style of the window Ws_child

3.3.3 can use the setparent and GetParent functions to set and get the specified parent window

You can specify a parent window when CreateWindow

Ws_child

SetParent

GetParent

Other: MoveWindow Mobile window

3.4 Creating an MDI window

3.4.1 Main Window

3.4.2 Creating a mdiclinet window

3.4.3 Creating a child window of an MDI



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.