I have been studying VC recently, because there are self-study, there are many problems to be solved by a hard look, now, introduce these learning VCs, just getting the problem, I hope I can get more advice. If you can help people with the same confusion with me, that is, fortunate!
In the VC, you can easily create a Windows application with MFC, but you have to figure out that the MFC's coming dragon is really not easy. First, you need to know the basic framework of the Windows program, and then you can learn about Windows in the MFC framework. program.
First, SDK application structure
Write a WINDOWS program with a classic SDK, although it is slightly trouble, it is a feeling that it brings to me. It has a row of cloud-like running contest, and it is very clear to run the process. Let me understand it very easy. Let's take a look at a classic SDK. Source code for written Windows programs:
Lresult Callback WndProc (HWND, UINT, WPARAM, LPARAM);
Int apientry Winmain (Hinstance Hinstance,
Hinstance Hprevinstance,
LPSTR LPCMDLINE,
INT ncmdshow)
{
// Todo: Place Code Here.
MSG msg;
..................................
MyRegisterClass (Hinstance);
IF (! initinstance (hinstance, ncmdshow))
{
Return False;
}
// main message loop:
While (GetMessage (& MSG, NULL, 0, 0))
{
IF (! TranslateAccelerator (Msg.hwnd, HaccelTable, & MSG))
{
TranslateMessage (& MSG);
DispatchMessage (& MSG);
}
}
Return msg.wparam;
}
Bool InitInstance (Hinstance Hinstance, Int ncmdshow)
{
........................
Return True;
}
// Window function WndProc (), callback function
Lresult Callback WndProc (HWND HWND, UINT MESSAGE, WPARAM WPARAM, LPARAM LPARAM)
{
Int Wmid, WMEVENT;
........................
Switch (Message)
{
Case WM_COMMAND:
..................
Break;
Case WM_Paint:
HDC = BeginPaint (HWND, & PS);
// Todo: add any drawing code here ...
RECT RT;
GetClientRect (hwnd, & rt);
DrawText (HDC, Szhello, Strlen (Szhello), & RT, DT_CENTER
Endpaint (hwnd, & ps);
Break;
Case WM_DESTROY:
......
DEFAULT:
Return DefWindowProc (Hwnd, Message, WPARAM, LPARAM);
}
Return 0;
}
SDK "Hello World" source
First let's take a look at the structure of this program, WinMain () is the entry point of the function, the main task of this function is to complete some initialization work and maintain a message loop. Their workflow is as follows: entrance ()) --- à myregister () ---> InitInstance () -àwhile message loop. The function is executed by the entrance. After calling the MyRegisterClass () registration window class, then INITINSTANCE () generates and displays the window. After that, the initialization of a window is completed (of course, in MyRegisterClass (), INITINSTANCE () Call the corresponding API function to specifically implement, but I focus on his structure, so don't consider his specific implementation details), then the maintenance message loop, you can see that this program is simply named, step by step One step is performed, which is fully in line with our thinking. However, there is something to pay attention to, that is, the structure of the message loop, in the example program, I let the program output a "Hello World" in the window. In the main program, the framework of the application has been built, and all controls and other information are processed during the window processing sent by the message loop, and the output information is output when the WM_PAINT information is accepted.
The Windows application written directly using SDK is so straightforward, but all these things in the MFC don't seem to exist, but some of them are some inexplicable macro, then these macro is amazing, how do they achieve a Windows program? ? (to be continued)