HOWTO: Province Your Own Window Class Name for an MFC Dialog Box

xiaoxiao2021-03-06  98

From: http://support.microsoft.com/default.aspx? Scid = http://support.microsoft.com: 80 / support / KB / Articles / Q251 / 0 / 59.ASP & NoWebContent = 1

This article was previously published under Q251059 Note Microsoft Visual C .NET (2002) supports both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. The information in this article applies only to unmanaged Visual C Code. Summarythis Article Shows You How To Provide Your OWN WINDOW Class Name for a Dialog Box That Is 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 INFORMATIONTo provide your own Window Class Name, follow these steps:. Open your project work space that contains the dialog box, and then click ResourceView. 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.Alternatively, open the .rc file as a text file Go to the desired DIALOG resource and add the cLASS optio. N.

IDD_LIMITDLGINSTANCE_DIALOG DIALOGEX 0, 0, 195, 44STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENUEXSTYLE WS_EX_APPWINDOWCAPTION "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,15nd add the folowing code in 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 (AFXGETITINSTANCEHANDE (), "# 32770", & wc);

// Change the name of the class. Wc.lpszclassname = "myprivateclassname";

// register this class so much 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.

转载请注明原文地址:https://www.9cbs.com/read-123852.html

New Post(0)