Below is my understanding: create global object theApp, then call the object in the afxwmain InitInstance method, in this method creates a dialog box (here with the dialog box procedure for example),
Domodal dialog operation, stop in there (block), from the point of this order, is the main thread all the way to perform these actions, but why the run can also run news cycle?
This problem is very confused, foundation is poor, cannot understand,
The second big question, CWinApp inherited from CWinThread, and CWinThread should belong to the thread class, is with the thread of a special class, I don't understand is, from the above analysis, as a main thread running, does not seem to be open new thread (if yes), why CWinApp to inherit CWinThread? The inheritance has what meaning?
For 50 points, if answered carefully and completely, thank you,
CodePudding user response:
DLG program is a thread,CodePudding user response:
#include
//callback function: receiving and processing messages
LRESULT a CALLBACK WndProc (HWND HWND, UINT message, WPARAM WPARAM, LPARAM LPARAM)
{
The switch (the message)
{
Case WM_CREATE message handler:
return 0;
Case WM_DESTROY:
The PostQuitMessage (0);
return 0;
}
Return DefWindowProc (HWND, message, wParam, lParam);
}
Int WINAPI WinMain (HINSTANCE HINSTANCE, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow)
{
MSG MSG.
The HWND HWND;
The static TCHAR szAppName []=TEXT (" HelloWindow ");
WNDCLASS WNDCLASS;
Wndclass. Style=CS_HREDRAW | CS_VREDRAW;
Wndclass. CbClsExtra=0;
Wndclass. CbWndExtra=0;
Wndclass. HInstance=hInstance;
Wndclass. HIcon=LoadIcon (NULL, IDI_APPLICATION);
Wndclass. HCursor=LoadCursor (NULL, IDC_ARROW);
Wndclass. HbrBackground=(HBRUSH) GetStockObject (WHITE_BRUSH);
Wndclass. LpszMenuName=NULL;
Wndclass. LpfnWndProc=WndProc;
Wndclass. LpszClassName=szAppName;
if (! RegisterClass (& amp; Wndclass))//registration form
{
MessageBox (NULL, TEXT (" This program requires Windows NT!" ), szAppName, MB_ICONERROR);
return 0;
}
//Creates an overlapped, pop - up, or child window
HWnd=CreateWindow (
SzAppName,//A null - terminated string or A class atom created by A previous call to the RegisterClass or RegisterClassEx function
The TEXT (" The Hello Windows Program "),//The Window name
WS_OVERLAPPEDWINDOW,//The style of The window being created
CW_USEDEFAULT,//The initial horizontal position of The window
CW_USEDEFAULT,//The initial vertical position of The window
CW_USEDEFAULT,//The width, in device units, of The window
CW_USEDEFAULT,//The height, in device units, of The window
NULL,//A handle to the parent or owner window of the window being created
NULL,//A handle to A menu, or specifies A child window identifier - depending on the window style
HInstance,//program instance handle
NULL);
ShowWindow (hWnd, iCmdShow);
UpdateWindow (hWnd);
While (GetMessage (& amp; MSG, NULL, 0, 0))
{
TranslateMessage (& amp; MSG);
DispatchMessage (& amp; MSG);
}
return 0;
}
This code is useless MFC can also create a window, the code is simpler, can be simple to understand, to pay special attention to the following:
LRESULT a CALLBACK WndProc (HWND HWND, UINT message, WPARAM WPARAM, LPARAM LPARAM)
Wndclass. LpfnWndProc=WndProc;//set the callback function that receives the message processing
While (GetMessage (& amp; MSG, NULL, 0, 0))
{
While (GetMessage (& amp; MSG, NULL, 0, 0))
DispatchMessage (& amp; MSG);
}
MFC simple encapsulation of WINAPI
Guide the common code was generated according to choose
Familiar with MFC, especially among them "message map", "event-driven", use rise more convenient and visual development efficiency is high, but the self-study up can be a bit difficult,
Can try to learn about this code, simple to see the MFC code generated by the wizard, it may easily the
Don't know what to say right, for reference only
CodePudding user response: