斜树的空间

集中精力,放弃一切的去做一件事情,只要尽力了,即使失败了,你也不会后悔!

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  47 随笔 :: 0 文章 :: 12 评论 :: 0 Trackbacks

   全局变量的定义:
在MFC的框架中有个全局变量:
CTestApp theApp;
theApp是在进入WinMain函数之前就构造好值的。
所以可以进入WinMain函数之前是先执行theApp的构造函数。
孙鑫老师说MFC是通过应用程序类的对象来标识应用程序的实例的(这句话不明白,应该都是hInstance标识的吧,也许要等到我看侯捷老师书的时候才知道了),且每个MFC程序有且仅有一个从CWinApp派生的类。也仅有一个CWinApp派生类的对象,即仅有一个theApp对象。theApp对象就标识了应用程序本身。
即theApp是统领其它类的。
并且CWinApp类是派生于CWinThread类的,
There are two general types of threads that CWinThread supports: worker threads and user-interface threads. Worker threads have no message pump: for example, a thread that performs background calculations in a spreadsheet application. User-interface threads have a message pump and process messages received from the system. CWinApp and classes derived from it are examples of user-interface threads. Other user-interface threads can also be derived directly from CWinThread.

MSDN中还提供了一些额外的操作全局信息的函数:

  • AfxGetApp   Obtains a pointer to the CWinApp object.

  • AfxGetInstanceHandle   Obtains a handle to the current application instance.

  • AfxGetResourceHandle   Obtains a handle to the application's resources.

  • AfxGetAppName   Obtains a pointer to a string containing the application's name. Alternately, if you have a pointer to the CWinApp object, use m_pszExeName to get the application's name.

    看看MFC中的 main()函数:
    extern "C" int WINAPI
    _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
     _In_ LPTSTR lpCmdLine, int nCmdShow)
    #pragma warning(suppress: 4985)
    {
     // call shared/exported WinMain
     return AfxWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
    }

  • posted on 2010-05-01 20:59 张贵川 阅读(412) 评论(1)  编辑 收藏 引用

    评论

    # re: MFC框架的初读(0) 2010-05-02 13:57 pywm
    Vc远控编程爱好者群111720426   回复  更多评论
      


    只有注册用户登录后才能发表评论。
    网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理