This reading note series I once sent it to the school BBS, now go here. The Windows program running mechanism and the VC programming Win32 program consists of "program code" and "user interface resources", and the two parts are finally integrated into a .exe program with the RC compiler, where user interface resources include a variety of dialogue, Program icon, cursor, etc.
The library and header file Windows program must load the Windows.h header file, which contains GDI32.DLL, User32.dll, Kernel32.dll three modules, and most of the WIN APIs, they correspond to the three major functions library GDI32. LIB, user32.lib, kernel32.lib. Of course, there are many other APIs included in other modules, such as Commdlg.dll, Mapi.dll, Tapi.dll, Toolhelp.dll, and more.
Of course, it will not have a C Runtime library, he has two versions: one is a static version, one is to support the dynamic connection library (MSVCRT40.DLL), with a total of 6 versions of the library.
The WIN32 program process is in general, the Windows program is driven by the external event, and the message is transmitted through the message, that is, a message is based on the event. The mechanism is: external hardware or other forms of messages, which are loaded into the preset message queue, or called message mapping network, and the program passes the message to different message mapping functions with the help of the system USER module. The simple process is: 1) The program loaded in WinMain () is the same as the main () of C. 2) After the program is loaded, the window class is first registered (registerclass ()), including window processing functions, window class name, window menu name, window background color icon, cursor, etc., these are. There is a detailed correspondence between the RE file. 3) Further, create a form, including a Le Form Title, an associated window class, a form overlap, and the like, the function returns the form handle. At this time, the WM_CREATE message is sent, and the work is initialized by the form function. Then display (ShowWindow ()), and call Update (), generate WM_PAINT messages to redraw forms! 4) Since then, the program main thread constantly loops to obtain different messages getMessage () and proceeds to the corresponding process function. Of course helps by the USER module. 5) When the program is turned off, the program sends WM_CLOSE, the process function is processed by defWindowsproc () by default, he tested with the destroyWindows () function, this function sent a WM_DESTROY message, this message continues to be progranted PostquitMessage (), he issued again WM_quit message, this message is terminated in the upper step, the program ends. Also note that the program is not ending when there is no message, but is ended when it is wm_quit, please note that there is a problem that the so-called idle time: OnIdle (). In order to achieve other things, GetMessage () must be changed to the peekmessage () function, so that the control will not slip. :) The process executed by the program is above, in the previous process: 1), such as the user double-clicking the icon start program, at this time by the Windows Shell, call the CreateProcess () activation program. 2) Generate the Kernel Object (Process Core Object), count plus 1, the operating system allocates the address space, generally 4G. 3) Program loader load code into this space, and performs relevant processing, then establish the primary thread, this thread is the continuous loop to obtain the news. 4) The system calls the Startup code of the C Runtime library, which is called WinMain (). 5) At the end of the program, return to Startup code, return to the system, the system ends the process through the EXITPROCESS (), and the thread is of course revoked.