修改mfc对话框程序窗口类名

This information is very old but I think it's very useful.Now show to everybody.

1. 

Open your project work space that contains the dialog box, and then click ResourceView.

 

2.

Open the dialog box in Resource Editor. Right-click the dialog box, and then select Properties. Notice an entry for Class Name at the bottom right. This edit box appears disabled if you are using a resource file with Microsoft Foundation Class Library support. To enable this option, switch to the top-level node on the resource view, and then right-click and select Properties. Clear the Enable MFC Features check box. Or for Visual C++ .NET, clear the MFC Mode property to FALSE. Now display the properties for your dialog box. The Class Name edit box should be enabled. Type the class name; for instance MyPrivateClassName.

 

3.

 

Alternatively, open the .rc file as a text file. Go to the desired DIALOG resource and add the CLASS option.

IDD_LIMITDLGINSTANCE_DIALOG DIALOGEX 0, 0, 195, 44
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "LimitDlgInstance"
CLASS "MyPrivateClassName" // Add your class name here!
FONT 8, "MS Sans Serif"
BEGIN
    DEFPUSHBUTTON   "OK",IDOK,138,7,50,14
    PUSHBUTTON      "Cancel",IDCANCEL,138,23,50,14
    PUSHBUTTON      "&Test!",IDC_BUTTON1,48,14,49,15
END
      4.                                                                                     

 

Add the following code in the InitInstance() function of the CWinApp-derived class.

BOOL CLimitDlgInstanceApp::InitInstance()
{
               / 
               / 
               WNDCLASS wc;
 
               // Get the info for this class.
         // #32770 is the default class name for dialogs boxes.
               ::GetClassInfo(AfxGetInstanceHandle(), "#32770", &wc);
 
               // Change the name of the class.
               wc.lpszClassName = "MyPrivateClassName";
 
               // Register this class so that MFC can use it.
               AfxRegisterClass(&wc);           
               / 
               / 
 
// ...
}
                                                                                            

5.

In the step above, in the call to ::GetClassInfo(), make sure to use the correct HINSTANCE call if your dialog resource is located in a separate DLL.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值