Windows program internal operating mechanism overview

  

Windows
Operating system
Providing application programming interface (Application Programming Interface)–API function

All major Windows functions are declared in the Windows.h header file.


Handle — the identification number of the resource.

The message is represented by the MSG structure.
typedef struct tagMSG {
HWND hwnd; //Message belongs to window
UINT message; //Message identifier 1
WPARAM wParam; //Message additional message unsigned 2
LPARAM lParam; //Additional message for message long
DWORD time; //time(int)
POINT pt; //cursor position
} MSG, *PMSG, *LPMSG;
1 Windows will correspond to the message The value is defined as the form of the WM_XXX macro
2 Example: the ascii code of the keyboard pressing the key

Basic win32 program implementation steps:

I: Definition of the WinMain function

II: Create a window

III: Make a message loop

IV: Write a window procedure function


WinMain function
int WINAPI WinMain(
HINSTANCE hInstance, //handle of the current running instance
HINSTANCE hPrevInstance, //handle of the previous instance
LPSTR lpCmdLine, //null-terminated string specifying the command line passed to the application Parameters
int nCmdShow //Window display status
);

1 In Win32 environment, this parameter is always NULL


Create a window specific Step:

I: Design one Window class

II: Register window class

III: Create window

IV: Display and update window


WNDCLASS structure Implement window class design

typedef struct tagWNDCLASS {
 UINT style; //Window style (you can use &~ to remove unwanted styles)
 WNDPROC lpfnWndProc; //point to window procedure function ( Callback function) pointer 
 int cbClsExtra; //class window additional memory, generally set to 0 
 int cbWndExtra; //window additional memory, generally 0 
 HINSTANCE hInstance; //instance handle 
 HICON hIcon; //icon handle 1
 HCURSOR hCursor; //mouse handle 2
 HBRUSH hbrBackground; //background brush handle 3
 LPCTSTR lpszMenuName;//menu name, NULL no window, menu Not a window 
 LPCTSTR lpszClassName; window class name 
} WNDCLASS, *PWNDCLASS;



Copyright © Windows knowledge All Rights Reserved