青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

隨筆 - 42  文章 - 3  trackbacks - 0
<2025年12月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

常用鏈接

留言簿(2)

隨筆檔案

文章檔案

網(wǎng)頁(yè)收藏

搜索

  •  

最新評(píng)論

閱讀排行榜

評(píng)論排行榜

例子是一個(gè)mfc的對(duì)話框,用vc調(diào)試器查看了一個(gè)程序從生成初始化到接受消息的流程。從產(chǎn)生到結(jié)束的基本流程是這樣的:
KERNEL32->WinMainCRTStartup()->_tWinMain(開(kāi)始)->AfxWinMain(開(kāi)始)->AfxGetThread()->AfxWinInit()->InitApplication()->InitInstance()->DoModal()->RunModalLoop()->ExitInstance()->AfxWinMain(結(jié)束)->_tWinMain(結(jié)束)

1、KERNEL32
kernel32.dll是Windows9x/Me中非常重要的32位動(dòng)態(tài)鏈接庫(kù)文件,屬于內(nèi)核級(jí)文件。它控制著系統(tǒng)的內(nèi)存管理、數(shù)據(jù)的輸入輸出操作和中斷處理,當(dāng)Windows啟動(dòng)時(shí),kernel32.dll就駐留在內(nèi)存中特定的寫保護(hù)區(qū)域,使別的程序無(wú)法占用這個(gè)內(nèi)存區(qū)域。

2、WinMainCRTStartup()函數(shù)
  程序默認(rèn)的基地址(EXE文件默認(rèn)為0x400000,DLL默認(rèn)為x10000000),操作系統(tǒng)裝載一個(gè)程序時(shí)總是試著先從這個(gè)基地址開(kāi)始。一般Win32的程序,EXE的入口為WinMain,DLL的入口為DllEntryPoint。默認(rèn)情況下,通過(guò)一個(gè)C的運(yùn)行時(shí)庫(kù)函數(shù)來(lái)實(shí)現(xiàn):控制臺(tái)程序采用mainCRTStartup (或wmainCRTStartup)去調(diào)用程序的main (或wmain)函數(shù);Windows程序采用WinMainCRTStartup (或 wWinMainCRTStartup)調(diào)用程序的WinMain (或 wWinMain,必須采用__stdcall調(diào)用約定);DLL采用_DllMainCRTStartup調(diào)用DllMain函數(shù)(必須采用__stdcall調(diào)用約定)。
它負(fù)責(zé):
  * 檢索指向新進(jìn)程的完整命令行指針;
  * 檢索指向新進(jìn)程的環(huán)境變量的指針;
  * 對(duì)c/c++運(yùn)行時(shí)的全局變量進(jìn)行初始化;
  * 對(duì)c運(yùn)行期的內(nèi)存單元分配函數(shù)(比如malloc,calloc)和其他低層I/O例程使用的內(nèi)存棧     進(jìn)行初始化。
  * 為C++的全局和靜態(tài)類調(diào)用構(gòu)造函數(shù)。
  當(dāng)這些初始化工作完成后,該啟動(dòng)函數(shù)就調(diào)用wWinMain函數(shù)進(jìn)入應(yīng)用程序的執(zhí)行。
當(dāng)wWinMain函數(shù)執(zhí)行完畢返回時(shí),wWinMainCRTStartup啟動(dòng)函數(shù)就調(diào)用c運(yùn)行期的exit()函
數(shù),將返回值(nMainRetVal)傳遞給它。
  之后exit()便開(kāi)始收尾工作:
  * 調(diào)用由_onexit()函數(shù)調(diào)用和注冊(cè)的任何函數(shù)。
  * 為C++的全局和靜態(tài)類調(diào)用析構(gòu)函數(shù);
  * 調(diào)用操作系統(tǒng)的ExitProcess函數(shù),將nMainRetVal傳遞給它,這使得操作系統(tǒng)能夠撤銷     進(jìn)程并設(shè)置它的exit  代碼。
最小體積的win32程序:(不要編譯缺省庫(kù))
#pragma comment (linker, "/SUBSYSTEM:WINDOWS")
#pragma comment (linker, "/NODEFAULTLIB")
int WinMainCRTStartup()
{
 return 0;
}

3、WinMain()函數(shù)
_tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
 LPTSTR lpCmdLine, int nCmdShow)
{
 // call shared/exported WinMain
 return AfxWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
}

4、AfxWinMain()函數(shù)
int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
 LPTSTR lpCmdLine, int nCmdShow)
{
 ASSERT(hPrevInstance == NULL);

 int nReturnCode = -1;
 CWinThread* pThread = AfxGetThread();
 CWinApp* pApp = AfxGetApp();

 // AFX internal initialization
 if (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow))
  goto InitFailure;

 // App global initializations (rare)
 if (pApp != NULL && !pApp->InitApplication())
  goto InitFailure;

 // Perform specific initializations
 if (!pThread->InitInstance())
 {
  if (pThread->m_pMainWnd != NULL)
  {
   TRACE0("Warning: Destroying non-NULL m_pMainWnd\n");
   pThread->m_pMainWnd->DestroyWindow();
  }
  nReturnCode = pThread->ExitInstance();
  goto InitFailure;
 }
 nReturnCode = pThread->Run();

InitFailure:
#ifdef _DEBUG
 // Check for missing AfxLockTempMap calls
 if (AfxGetModuleThreadState()->m_nTempMapLock != 0)
 {
  TRACE1("Warning: Temp map lock count non-zero (%ld).\n",
   AfxGetModuleThreadState()->m_nTempMapLock);
 }
 AfxLockTempMaps();
 AfxUnlockTempMaps(-1);
#endif

 AfxWinTerm();
 return nReturnCode;
}

5、AfxGetThread()函數(shù)
CWinThread* AFXAPI AfxGetThread()
{
 // check for current thread in module thread state
 AFX_MODULE_THREAD_STATE* pState = AfxGetModuleThreadState();
 CWinThread* pThread = pState->m_pCurrentWinThread;

 // if no CWinThread for the module, then use the global app
 if (pThread == NULL)
  pThread = AfxGetApp();

 return pThread;
}

6、AfxWinInit()函數(shù)
BOOL AFXAPI AfxWinInit(HINSTANCE hInstance, HINSTANCE hPrevInstance,
 LPTSTR lpCmdLine, int nCmdShow)
{
 ASSERT(hPrevInstance == NULL);

 // handle critical errors and avoid Windows message boxes
 SetErrorMode(SetErrorMode(0) |
  SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);

 // set resource handles
 AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
 pModuleState->m_hCurrentInstanceHandle = hInstance;
 pModuleState->m_hCurrentResourceHandle = hInstance;

 // fill in the initial state for the application
 CWinApp* pApp = AfxGetApp();
 if (pApp != NULL)
 {
  // Windows specific initialization (not done if no CWinApp)
  pApp->m_hInstance = hInstance;
  pApp->m_hPrevInstance = hPrevInstance;
  pApp->m_lpCmdLine = lpCmdLine;
  pApp->m_nCmdShow = nCmdShow;
  pApp->SetCurrentHandles();
 }

 // initialize thread specific data (for main thread)
 if (!afxContextIsDLL)
  AfxInitThread();

 return TRUE;
}

7、InitApplication() 函數(shù)
BOOL CMy1App::InitApplication()
{
 // TODO: Add your specialized code here and/or call the base class
 AfxMessageBox("InitApplication");
 return CWinApp::InitApplication();
}
BOOL CWinApp::InitApplication()
{
 if (CDocManager::pStaticDocManager != NULL)
 {
  if (m_pDocManager == NULL)
   m_pDocManager = CDocManager::pStaticDocManager;
  CDocManager::pStaticDocManager = NULL;
 }

 if (m_pDocManager != NULL)
  m_pDocManager->AddDocTemplate(NULL);
 else
  CDocManager::bStaticInit = FALSE;

 return TRUE;
}

8、InitInstance()函數(shù)
AfxWinMain函數(shù)里面的if (!pThread->InitInstance())會(huì)調(diào)用程序CMy1App的InitInstance函數(shù):
BOOL CMy1App::InitInstance()
{
 AfxEnableControlContainer();
AfxMessageBox("InitInstance");
 // Standard initialization
 // If you are not using these features and wish to reduce the size
 //  of your final executable, you should remove from the following
 //  the specific initialization routines you do not need.

#ifdef _AFXDLL
 Enable3dControls();   // Call this when using MFC in a shared DLL
#else
 Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif

 CMy1Dlg dlg;//調(diào)用CMy1Dlg的構(gòu)造函數(shù)
 m_pMainWnd = &dlg;
 int nResponse = dlg.DoModal();
 if (nResponse == IDOK)
 {
  // TODO: Place code here to handle when the dialog is
  //  dismissed with OK
 }
 else if (nResponse == IDCANCEL)
 {
  // TODO: Place code here to handle when the dialog is
  //  dismissed with Cancel
 }

 // Since the dialog has been closed, return FALSE so that we exit the
 //  application, rather than start the application's message pump.
 return FALSE;
}

9、AfxWinMain()函數(shù)里面的主要的循環(huán)體,在這里:
        if (!pThread->InitInstance())//主要是模式對(duì)話框調(diào)用,對(duì)話框關(guān)閉以后InitInstance函數(shù)才會(huì)結(jié)束
 {
  if (pThread->m_pMainWnd != NULL)
  {
   TRACE0("Warning: Destroying non-NULL m_pMainWnd\n");
   pThread->m_pMainWnd->DestroyWindow();
  }
  nReturnCode = pThread->ExitInstance();
  goto InitFailure;
 }
 nReturnCode = pThread->Run();//非模式對(duì)話框和一般程序調(diào)用這個(gè)循環(huán)

InitInstance函數(shù)調(diào)用了dlg.DoModal()函數(shù),以下是DoModal()函數(shù):
int CDialog::DoModal()
{
 // can be constructed with a resource template or InitModalIndirect
 ASSERT(m_lpszTemplateName != NULL || m_hDialogTemplate != NULL ||
  m_lpDialogTemplate != NULL);

 // load resource as necessary
 LPCDLGTEMPLATE lpDialogTemplate = m_lpDialogTemplate;
 HGLOBAL hDialogTemplate = m_hDialogTemplate;
 HINSTANCE hInst = AfxGetResourceHandle();
 if (m_lpszTemplateName != NULL)
 {
  hInst = AfxFindResourceHandle(m_lpszTemplateName, RT_DIALOG);
  HRSRC hResource = ::FindResource(hInst, m_lpszTemplateName, RT_DIALOG);
  hDialogTemplate = LoadResource(hInst, hResource);
 }
 if (hDialogTemplate != NULL)
  lpDialogTemplate = (LPCDLGTEMPLATE)LockResource(hDialogTemplate);

 // return -1 in case of failure to load the dialog template resource
 if (lpDialogTemplate == NULL)
  return -1;

 // disable parent (before creating dialog)
 HWND hWndParent = PreModal();
 AfxUnhookWindowCreate();
 BOOL bEnableParent = FALSE;
 if (hWndParent != NULL && ::IsWindowEnabled(hWndParent))
 {
  ::EnableWindow(hWndParent, FALSE);
  bEnableParent = TRUE;
 }

 TRY
 {
  // create modeless dialog
  AfxHookWindowCreate(this);
  if (CreateDlgIndirect(lpDialogTemplate,
      CWnd::FromHandle(hWndParent), hInst))//創(chuàng)建對(duì)話框的窗口
  {
   if (m_nFlags & WF_CONTINUEMODAL)
   {
    // enter modal loop
    DWORD dwFlags = MLF_SHOWONIDLE;
    if (GetStyle() & DS_NOIDLEMSG)
     dwFlags |= MLF_NOIDLEMSG;
    VERIFY(RunModalLoop(dwFlags) == m_nModalResult);//這里是真正的循環(huán)RunModalLoop
   }

   // hide the window before enabling the parent, etc.
   if (m_hWnd != NULL)
    SetWindowPos(NULL, 0, 0, 0, 0, SWP_HIDEWINDOW|
     SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
  }
 }
 CATCH_ALL(e)
 {
  DELETE_EXCEPTION(e);
  m_nModalResult = -1;
 }
 END_CATCH_ALL

 if (bEnableParent)
  ::EnableWindow(hWndParent, TRUE);
 if (hWndParent != NULL && ::GetActiveWindow() == m_hWnd)
  ::SetActiveWindow(hWndParent);

 // destroy modal window
 DestroyWindow();
 PostModal();

 // unlock/free resources as necessary
 if (m_lpszTemplateName != NULL || m_hDialogTemplate != NULL)
  UnlockResource(hDialogTemplate);
 if (m_lpszTemplateName != NULL)
  FreeResource(hDialogTemplate);

 return m_nModalResult;
}

模式對(duì)話框調(diào)用的循環(huán)函數(shù)RunModalLoop()函數(shù)如下:
int CWnd::RunModalLoop(DWORD dwFlags)
{
 ASSERT(::IsWindow(m_hWnd)); // window must be created
 ASSERT(!(m_nFlags & WF_MODALLOOP)); // window must not already be in modal state

 // for tracking the idle time state
 BOOL bIdle = TRUE;
 LONG lIdleCount = 0;
 BOOL bShowIdle = (dwFlags & MLF_SHOWONIDLE) && !(GetStyle() & WS_VISIBLE);
 HWND hWndParent = ::GetParent(m_hWnd);
 m_nFlags |= (WF_MODALLOOP|WF_CONTINUEMODAL);
 MSG* pMsg = &AfxGetThread()->m_msgCur;

 // acquire and dispatch messages until the modal state is done
 for (;;)
 {
  ASSERT(ContinueModal());

  // phase1: check to see if we can do idle work
  while (bIdle &&
   !::PeekMessage(pMsg, NULL, NULL, NULL, PM_NOREMOVE))
  {
   ASSERT(ContinueModal());

   // show the dialog when the message queue goes idle
   if (bShowIdle)
   {
    ShowWindow(SW_SHOWNORMAL);
    UpdateWindow();
    bShowIdle = FALSE;
   }

   // call OnIdle while in bIdle state
   if (!(dwFlags & MLF_NOIDLEMSG) && hWndParent != NULL && lIdleCount == 0)
   {
    // send WM_ENTERIDLE to the parent
    ::SendMessage(hWndParent, WM_ENTERIDLE, MSGF_DIALOGBOX, (LPARAM)m_hWnd);
   }
   if ((dwFlags & MLF_NOKICKIDLE) ||
    !SendMessage(WM_KICKIDLE, MSGF_DIALOGBOX, lIdleCount++))
   {
    // stop idle processing next time
    bIdle = FALSE;
   }
  }

  // phase2: pump messages while available
  do
  {
   ASSERT(ContinueModal());

   // pump message, but quit on WM_QUIT
   if (!AfxGetThread()->PumpMessage())//主要在這里循環(huán)
   {
    AfxPostQuitMessage(0);
    return -1;
   }

   // show the window when certain special messages rec'd
   if (bShowIdle &&
    (pMsg->message == 0x118 || pMsg->message == WM_SYSKEYDOWN))
   {
    ShowWindow(SW_SHOWNORMAL);
    UpdateWindow();
    bShowIdle = FALSE;
   }

   if (!ContinueModal())
    goto ExitModal;

   // reset "no idle" state after pumping "normal" message
   if (AfxGetThread()->IsIdleMessage(pMsg))
   {
    bIdle = TRUE;
    lIdleCount = 0;
   }

  } while (::PeekMessage(pMsg, NULL, NULL, NULL, PM_NOREMOVE));
 }

ExitModal:
 m_nFlags &= ~(WF_MODALLOOP|WF_CONTINUEMODAL);
 return m_nModalResult;
}

一般程序調(diào)用的循環(huán)函數(shù)Run函數(shù)如下:
int CWinThread::Run()
{
 ASSERT_VALID(this);

 // for tracking the idle time state
 BOOL bIdle = TRUE;
 LONG lIdleCount = 0;

 // acquire and dispatch messages until a WM_QUIT message is received.
 for (;;)
 {
  // phase1: check to see if we can do idle work
  while (bIdle &&
   !::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE))
  {
   // call OnIdle while in bIdle state
   if (!OnIdle(lIdleCount++))
    bIdle = FALSE; // assume "no idle" state
  }

  // phase2: pump messages while available
  do
  {
   // pump message, but quit on WM_QUIT
   if (!PumpMessage())
    return ExitInstance();

   // reset "no idle" state after pumping "normal" message
   if (IsIdleMessage(&m_msgCur))
   {
    bIdle = TRUE;
    lIdleCount = 0;
   }

  } while (::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE));
 }

 ASSERT(FALSE);  // not reachable
}

==========
我認(rèn)為是更加完整的應(yīng)該是_DllMainCRTStartup-> WinMainCRTStartup(void)->()->_tWinMain(開(kāi)始)->AfxWinMain(開(kāi)始)->AfxGetThread()->AfxWinInit()->InitApplication()->InitInstance()->DoModal()->RunModalLoop()->ExitInstance()->AfxWinMain(結(jié)束)->_tWinMain(結(jié)束)

參考http://m.shnenglu.com/citywanderer/articles/8716.html
posted on 2009-10-01 22:51 鷹擊長(zhǎng)空 閱讀(1629) 評(píng)論(0)  編輯 收藏 引用

只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            国产精品亚洲不卡a| 黄色成人av网站| 日韩一级精品| 亚洲精品中文字幕在线观看| 欧美福利视频网站| 91久久综合| 亚洲精品国产精品久久清纯直播| 欧美美女bb生活片| 午夜精品国产精品大乳美女| 亚洲免费小视频| 激情久久影院| 亚洲精品欧美极品| 国产精品日韩欧美一区二区三区| 久久精品一区二区国产| 可以看av的网站久久看| 99热在线精品观看| 国产精品99久久久久久久女警| 国产精品亚洲综合久久| 久久影院午夜论| 欧美日韩亚洲一区在线观看| 性欧美xxxx大乳国产app| 久久久亚洲精品一区二区三区 | 久久久午夜电影| 亚洲美女中文字幕| 亚洲女同在线| 亚洲激情在线| 亚洲欧美日韩一区二区三区在线| 亚洲大胆女人| 国产免费亚洲高清| 久久成人18免费观看| 久久这里只精品最新地址| 亚洲深夜av| 久久人人爽人人爽爽久久| 亚洲视频播放| 美女被久久久| 久久se精品一区二区| 免费一级欧美片在线观看| 午夜精品久久久久久99热软件| 久久久久久久久综合| 亚洲欧美在线观看| 欧美久久在线| 欧美jjzz| 国产一区二区三区在线观看免费 | 久久精品日韩| 欧美午夜电影在线| 亚洲黄色免费电影| 红桃视频一区| 亚洲资源av| 亚洲小视频在线| 麻豆九一精品爱看视频在线观看免费| 亚洲自拍电影| 欧美日韩国产高清视频| 欧美第一黄网免费网站| 国产一区二区精品久久99| 亚洲视频成人| 一道本一区二区| 免费亚洲电影在线| 麻豆精品在线视频| 一区二区三区在线看| 午夜在线观看免费一区| 欧美中文在线观看| 欧美小视频在线| 99国产欧美久久久精品| 艳女tv在线观看国产一区| 久久国产精品久久久久久电车 | 怡红院精品视频| 欧美一区二区三区日韩视频| 午夜视频精品| 国产精品一区二区三区四区| 亚洲一区二区成人| 亚洲综合色在线| 欧美网站在线观看| 亚洲午夜在线视频| 欧美一区二区在线观看| 国产一区二区三区久久| 久久成人精品无人区| 久久免费黄色| 在线观看一区| 免费在线成人av| 亚洲韩国精品一区| 一本色道久久综合亚洲精品高清| 欧美日韩1区| 亚洲视频 欧洲视频| 欧美一级久久久久久久大片| 国产日韩在线播放| 久久久一区二区| 欧美黄色日本| 日韩亚洲欧美一区二区三区| 国产精品大片wwwwww| 亚洲欧美国产77777| 浪潮色综合久久天堂| 亚洲国产综合在线| 欧美另类高清视频在线| 亚洲综合大片69999| 蜜桃av综合| 日韩亚洲精品在线| 国产日韩欧美在线看| 久久人体大胆视频| 99成人在线| 久久天堂av综合合色| 亚洲精选一区| 国产日韩精品电影| 男女激情视频一区| 亚洲一区二区三区影院| 欧美高清视频| 香蕉久久国产| 亚洲精品在线观看免费| 国产精品一区二区三区四区五区| 久热精品视频| 亚洲一区二区三区国产| 亚洲高清免费在线| 欧美影视一区| 99精品福利视频| 国内激情久久| 欧美视频在线观看一区| 久久久另类综合| 亚洲综合成人在线| 亚洲国产精品久久| 久久久久青草大香线综合精品| 亚洲深夜福利在线| 91久久精品国产91性色tv| 欧美成人四级电影| 国产伪娘ts一区| 亚洲一区二区三区免费视频| 欧美成年人视频网站| 欧美精品福利在线| 久久在线免费观看| 欧美一区二区三区免费看| 9久草视频在线视频精品| 亚洲丰满少妇videoshd| 久久国产福利| 亚洲第一视频| 狠狠色综合播放一区二区| 国产精品夫妻自拍| 欧美另类久久久品| 欧美精品久久久久a| 玖玖综合伊人| 久久久久成人网| 欧美夜福利tv在线| 香蕉久久夜色精品| 亚洲欧美成人在线| 午夜一区二区三区在线观看 | 91久久黄色| 樱桃国产成人精品视频| 国产一区二区三区在线观看免费视频 | 久久久久久亚洲精品杨幂换脸| 亚洲综合国产激情另类一区| 一区二区三区导航| 制服丝袜亚洲播放| 亚洲影音一区| 午夜精品av| 久久久精品动漫| 久久先锋影音| 欧美激情亚洲国产| 欧美日本免费一区二区三区| 欧美日韩三区四区| 国产精品久久久爽爽爽麻豆色哟哟 | 久久一二三国产| 免费久久久一本精品久久区| 免费日韩av电影| 亚洲高清视频在线| 99精品欧美一区二区三区| 亚洲视频中文| 久久高清福利视频| 欧美成人黑人xx视频免费观看| 欧美成人蜜桃| 欧美视频日韩视频| 国产日韩在线视频| 亚洲福利专区| 亚洲香蕉视频| 久久久午夜视频| 亚洲国产精品成人| 日韩视频一区二区三区在线播放免费观看 | 最新国产成人av网站网址麻豆| 亚洲乱码视频| 亚洲欧美色婷婷| 狼人社综合社区| 夜夜嗨一区二区| 久久九九99| 欧美三级在线视频| 国内精品久久久久久| 99热精品在线观看| 久久九九99| 亚洲精品免费一区二区三区| 亚洲男人影院| 欧美99在线视频观看| 国产精品私拍pans大尺度在线| 在线观看精品视频| 亚洲欧美国产不卡| 欧美大片在线观看一区二区| 亚洲视频网站在线观看| 理论片一区二区在线| 国产精品久久久久影院色老大| 亚洲黄色高清| 久久久国产一区二区| 一本色道久久精品| 你懂的视频欧美| 国产一区二区毛片| 亚洲欧美日韩电影| 亚洲日本成人女熟在线观看|