HOWTO: Provide Your Own Window Class Name for an MFC Dialog Box
来源:互联网 发布:手机淘宝上传图片尺寸 编辑:程序博客网 时间:2024/06/07 21:35
HOWTO: Provide Your Own Window Class Name for an MFC Dialog Box
Q251059
--------------------------------------------------------------------------------
The information in this article applies to:
The Microsoft Foundation Classes (MFC), included with:
Microsoft Visual C++, 32-bit Enterprise Edition, version 5.0
Microsoft Visual C++, 32-bit Professional Edition, version 5.0
Microsoft Visual C++, 32-bit Enterprise Edition, version 6.0
Microsoft Visual C++, 32-bit Professional Edition, version 6.0
Microsoft Visual C++, 32-bit Learning Edition, version 6.0
--------------------------------------------------------------------------------
SUMMARY
This article shows you how to provide your own Window Class Name for a dialog box created in an MFC-based application.
You may encounter this need when you try to limit your dialog-based MFC application to a single instance.
MORE INFORMATION
Follow the steps outlined below to provide your own Window Class Name.
Open your project work space containing the dialog box and click ResourceView.
Open the dialog box in Resource Editor. Right-click the dialog box and 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, then right-click and select Properties. Clear the Enable MFC Features check box. Now display the properties for your dialog box. The Class Name edit box should be enabled. Type the class name; for instance MyPrivateClassName
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
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);
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
// ...
}
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.
Build and run your application. Use the Spy++ tool to verify that the dialog now uses the new class name.
- HOWTO: Provide Your Own Window Class Name for an MFC Dialog Box
- HOWTO: Provide Your Own Window Class Name for an MFC Dialog Box
- HOWTO: How to Provide Your Own DllMain in an MFC Regular DLL
- HOWTO: How to Provide Your Own DllMain in an MFC Regular DLL
- The String class is provided in the Java library. Provide your own implementation for the following
- 修改MFC Dialog 的 class name
- Howto: Make Your Own Cert With OpenSSL
- Customize your own MFC message
- Embed an HTML control in your own window using plain C
- Embed an HTML control in your own window using plain C
- Embed an HTML control in your own window using plain C
- Embed an HTML control in your own window using plain C
- Implementing your own base class for user controls in Silverlight 2
- Provide an Alternative View to Data Using Splitter Window
- Taking Responsibility for Your Own Learning
- Android.mk for your own module
- Android.mk for your own module
- Android.mk for your own module
- (转)从WINAPI和CALLBACK这两个宏说开去- -
- Servlet中的Listener的应用
- (转)C/C++中的日期和时间 time_t与struct tm转换
- php 面向对象
- struts-default.xml 文件说明
- HOWTO: Provide Your Own Window Class Name for an MFC Dialog Box
- Symbian异常三步曲之二:清除栈(CleanupStack)
- C++编写api一例
- 概要设计报告
- .net 笔试常见题(一) 值类型与引用类型的区别
- C++算法题
- 项目经理必读法律法规
- SymbianOS异常三步曲之三:两段构造
- 解决QQ2009正式版登录时出现“服务器拒绝”问题