Reprinted please indicate the source: http://blog.csdn.net/mxway/article/details/39581119
This article is based on the source code 2.06 of the Flying Pigeon text
The source code running process of the Flying Pigeon family is as follows. This article only describes the Starting Process of the Flying Pigeon family. The message mechanism and menu loading functions of the Flying Pigeon family are not included in this article.
1. winmain Function
int WINAPI WinMain(HINSTANCE hI, HINSTANCE, LPSTR cmdLine, int nCmdShow){TMsgAppapp(hI, cmdLine, nCmdShow);returnapp.Run();}
2. Some source code of tapp class definition
class TApp{protected:<span style="white-space:pre"></span>virtual BOOLInitApp(void);<span style="white-space:pre"></span>TWin*mainWnd;public:virtual voidInitWindow() = 0;virtual intRun();};
3. Definition of tmsgapp class
class TMsgApp : public TApp {<span style="white-space:pre"></span>public:<span style="white-space:pre"></span>TMsgApp(HINSTANCE _hI, LPSTR _cmdLine, int _nCmdShow);virtual ~TMsgApp();virtual voidInitWindow(void);};
The winmain function defines the object app and app of tmsgapp. run because tmsgapp inherits tapp, while tmsgapp does not override the run method, the run method of the parent class Tapp is called at this time. The method has the following two statements in the header:
Initapp ();
Initwindow ();
These two statements are equivalent to the following statements.
This-> initapp ();
This-> initwindow ();
It means to call the initapp () and initwindow () Methods of tmsgapp. Because tmsgapp does not override the initapp () method, it calls the initapp method of the parent class. Initwindow defined in Tapp is a pure virtual function, so this-> initwindow () calls the initwindow () method in tmsgapp.
Initwindow source code
void TMsgApp::InitWindow(void){<span style="white-space:pre"></span>mainWnd = new TMainWin(nicAddr, port_no);mainWnd->Create(class_name, IP_MSG, WS_OVERLAPPEDWINDOW | (IsNewShell() ? WS_MINIMIZE : 0));}
4. Some source code of the twin class definition
class TWin {public:virtual BOOLCreate(LPCSTR className=NULL, LPCSTR title="", DWORD style=(WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN), DWORD exStyle=0, HMENU hMenu=NULL);virtual BOOLEvCreate(LPARAM lParam);};
5. tmainwin Class Definition source code
class TMainWin : public TWin {virtual BOOLEvCreate(LPARAM lParam);};In initwindow, The mainwnd-> Create () method is executed. tmainwin inherits twin. Because tmainwin does not override the create method, the create method calls the CREATE, twin: Create source code in twin as follows:
BOOL TWin::Create(LPCSTR className, LPCSTR title, DWORD style, DWORD exStyle, HMENU hMenu){if (className == NULL)className = TApp::defaultClass;TApp::AddWin(this);if ((hWnd = ::CreateWindowEx(exStyle, className, title, style, rect.left, rect.top, rect.right, rect.bottom, parent ? parent->hWnd : NULL, hMenu, TApp::hI, NULL)) == NULL)returnTApp::DelWin(this), FALSE;elsereturnTRUE;}
This method calls the createmediawex method of the Windows API function. After this method is called, a wm_create message is triggered. The message processing function is evcreate (the message mechanism of the Flying Pigeon book will be explained later)
In tmainwin, The evcreate method in twin of the parent class is overwritten. Therefore, the evcreate method in tmainwin is called below. The source code of the evcreate method is as follows:
BOOL TMainWin::EvCreate(LPARAM lParam){if (IsNewShell()){Show(SW_HIDE);while (TaskBar(NIM_ADD, hMainIcon, IPMSG_MSGSTR) != TRUE)Sleep(1000);// for logon script}elseShow(SW_MINIMIZE);}
The function of this method is that if the operating system allows the application to run in a tray as a task, otherwise the window will run in a small way. So far, the main interface of the Flying Pigeon book has been started.
Source code analysis-program Startup Process