在MFC中用CreateDialogParam来创建一个非模块对话框,但不知如果取得hInstance,

解决方案 »

  1.   

    AfxGetInstanceHandle  This function allows you to retrieve the instance handle of the current application. 
    HINSTANCE AFXAPI AfxGetInstanceHandle( );
     Return Value
    An HINSTANCE to the current instance of the application. If called from within a DLL linked with the USRDLL version of MFC, an HINSTANCE to the DLL is returned.Res
    AfxGetInstanceHandle always returns the HINSTANCE of your executable file (.EXE) unless it is called from within a DLL linked with the USRDLL version of MFC. In this case, it returns an HINSTANCE to the DLL.Example
      Copy Code 
    // Print the application instance handle to the debugger output window.
    TRACE("Application instance handle is 0x%0X\n", AfxGetInstanceHandle());
     
      

  2.   

    还有一个问题想请教一下,CreateDialogParam的第4个参数 我现在是自己建的About函数CreateDialogParam(AfxGetInstanceHandle(),LPCTSTR(IDD_DIALOG1),this->m_hWnd,(DLGPROC)About,NULL);怎么写才能用回MFC本身的
      

  3.   

    用全局的 AfxGetInstanceHandle  MFC 框架实现的全局函数,
    只用使用了 MFC 就可以在任意位置调用该函数获得指定的句柄
      

  4.   

    使用全局函数AfxGetInstanceHandle();