没有觉得XP相比Win2k,Win98,在界面编程元素上有什么扩展,无非是多了一种窗口风格。
但是我的vc2005建立的MFC的文档-视图工程里面,CWinApp::InitInstance里面,一开始就是这样一段代码:         // InitCommonControlsEx() is required on Windows XP if an application
         // manifest specifies use of ComCtl32.dll version 6 or later to enable
         // visual styles.  Otherwise, any window creation will fail.
         INITCOMMONCONTROLSEX InitCtrls;
         InitCtrls.dwSize = sizeof(InitCtrls);
         // Set this to include all the common control classes you want to use
         // in your application.
         InitCtrls.dwICC = ICC_WIN95_CLASSES;
         InitCommonControlsEx(&InitCtrls);这段代码到底是做什么的? 有或者没有这段代码对于我的工程/GUI到底有什么影响?

解决方案 »

  1.   

    这段代码是设置界面风格为Windows95
      

  2.   

    可是我在winxp上面注释掉了这几句话也没有关系啊,虽然他说了:// Otherwise, any window creation will fail.没发现有什么fail的地方。大虾解释一下!
      

  3.   

    if an application manifest specifies use of ComCtl32.dll version 6 or later to enable visual styles.
    —— 你没有满足条件,当然不会失败了。
    ICC_WIN95_CLASSES
    Load animate control, header, hot key, list-view, progress bar, status bar, tab, ToolTip, toolbar, trackbar, tree-view, and up-down control classes. 
    Structure Information
    —— 就是初始化Win95开始提供的常用公共控件了
    ComCtl32.dll会随操作系统更新的,会扩展一些功能。比如list-view(MFC中CListCtrl),有些扩展样式就要高版本才支持。
      

  4.   

    这里确实没有必要显式的调用InitCommonControlsEx或者InitCommonControls,因为只要用到了CDialog,MFC框架代码会自动调用InitCommonControls
    具体在CWnd::CreateDlgIndirect的
    VERIFY(AfxDeferRegisterClass(AFX_WNDCOMMCTLS_REG));
    但是comtrl32 version6 在开启主题风格的情况下必须先InitCommonControls(Ex)才能正常使用,否则对话框创建失败。建个sdk工程可以验证下