# include & lt; Windows. H>//the underlying implementation of the window header file
//6 processing window process
//CALLBACK representative __stdcall parameter order: order into the stack from right to left, and before the function returns the empty stack
LRESULT a CALLBACK WindowProc (
The HWND HWND,//the window handle of the message belongs to
UINT uMsg,//specific message name WM_XXXX message name
WPARAM WPARAM,//keyboard attached message
LPARAM LPARAM//mouse attached message
)
{
The switch (uMsg)
{
Case WM_CLOSE:
//all xxxWindow as at the end of the method, not into the message queue, but direct execution
The DestroyWindow (HWND);//DestroyWindow sends another message WM_DESTROY
break;
Case WM_DESTROY:
The PostQuitMessage (0);
break;
Case WM_LBUTTONDOWN://mouse the left key press
{
Int xPos=LOWORD (lParam);
Int yPos=HIWORD (lParam);
Char buf [1024].
Wsprintf (buf, TEXT (" x=% d, y=% d "), xPos, yPos);
MessageBox (HWND, buf, TEXT (" the left mouse button pressed "), MB_OK);
break;
}
Case WM_KEYDOWN://keyboard
MessageBox (HWND, TEXT (" the keyboard by pressing "), TEXT (" the keyboard by pressing "), MB_OK);
break;
Case the WM_PAINT://drawing
{
PAINTSTRUCT ps;//drawing structure
HDC HDC=BeginPaint (HWND, & amp; Ps);
TextOut (HDC, 100, 100, TEXT (" HELLO "), strlen (" HELLO "));
EndPaint (HWND, & amp; Ps);
}
break;
}
//the return value with the default handling
Return DefWindowProc (HWND, uMsg wParam, lParam);
}
//program entrance function
//WINAPI representative __stdcall parameter order: order into the stack from right to left, and before the function returns the empty stack
Int WINAPI WinMain (
HINSTANCE HINSTANCE,//the application instance handle
HINSTANCE hPrevInstance,//handle to an application, under the win32 environment parameters in general is NULL, do not work
LPSTR lpCmdLine,//char * argv []
Int nShowCmd)//show command to maximize, minimize normal
{
//1, the design window
//2, registration window
//3, create window
//4, display and update
//5, cycle through taking message
//6, process the message (window procedure)
//1, the design window
WNDCLASS wc.
Wc. CbClsExtra=0;//class additional memory
Wc. CbWndExtra=0;//window extra memory
Wc. HbrBackground=(HBRUSH) GetStockObject (WHITE_BRUSH);//set the background
Wc. HCursor=LoadCursor (NULL, IDC_HAND);//set the cursor if the first parameter is NULL, on behalf of the use of the system to provide the cursor
Wc. HIcon=LoadIcon (NULL, IDI_ERROR);//icon if the first parameter is NULL, on behalf of the use of the system to provide the cursor
The wc. The hInstance=hInstance;//application instance handle incoming in WinMain parameter can
Wc. LpfnWndProc=WindowProc;//callback function window procedure
Wc. LpszClassName=TEXT (" WIN ");//specified window class name
Wc. LpszMenuName=NULL;//the menu name
Wc. Style=0;//show 0 (the default style
//2, a registered window class
RegisterClass (& amp; Wc);
//3, create window
/*
LpClassName, class name
LpWindowName, title name
DwStyle, WS_OVERLAPPEDWINDOW style
Coordinates x, show CW_USEDEFAULT default
Y,
NWidth, wide high
NHeight,
HWndParent, parent window NULL
HMenu, menu NULL
Handle hInstance hInstance, instance
LpParam) added value NULL
*/
HWND HWND=CreateWindow (wc) lpszClassName, TEXT (" WINDOWS "), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
//4, display and update
ShowWindow (HWND, SW_SHOWNORMAL);
UpdateWindow (HWND);
//5, cycle through taking message
/*
The HWND HWND; The main window handle
UINT message; The specific message name
WPARAM WPARAM. Additional messages keyboard
LPARAM LPARAM; Additional messages mouse
DWORD time; Message generated time
POINT pt; Additional messages the mouse x y
*/
MSG MSG.
While (GetMessage (& amp; MSG, NULL, 0, 0))
{
/*
_Out_ LPMSG LPMSG, message
_In_opt_ HWND HWND, filling capture window NULL represent captures all window
_In_ UINT wMsgFilterMin,//the news of the minimum and maximum filtering generally fill 0
_In_ UINT wMsgFilterMax)//fill 0 (capture all messages
*/
//if (GetMessage (& amp; MSG, NULL, 0, 0)==FALSE)
//{
//break;
//}
//translation message
TranslateMessage (& amp; MSG);
//not to false
//distribute news
DispatchMessage (& amp; MSG);
}
return 0;
}
CodePudding user response:
What is the problem?If simple window procedure with MFC directly or QT
It is not necessary to use winmain to painting,
CodePudding user response:
You just began to learn the basic winmain to write, understand the operation mechanism,CodePudding user response:
I want to know what's the use of MFC specific, basic knowledge of what is requiredCodePudding user response:
MFC in WINDOWS powerful, need a c + +, WINDOWS operating mechanism..."Yi jin jing" slowly practice

CodePudding user response: