Microsoft KB Archive/251059: Difference between revisions

From BetaArchive Wiki
m (Text replacement - "&" to "&")
m (Text replacement - """ to """)
 
Line 93: Line 93:
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
EXSTYLE WS_EX_APPWINDOW
CAPTION "LimitDlgInstance"
CAPTION "LimitDlgInstance"
CLASS "MyPrivateClassName" // Add your class name here!
CLASS "MyPrivateClassName" // Add your class name here!
FONT 8, "MS Sans Serif"
FONT 8, "MS Sans Serif"
BEGIN
BEGIN
     DEFPUSHBUTTON  "OK",IDOK,138,7,50,14
     DEFPUSHBUTTON  "OK",IDOK,138,7,50,14
     PUSHBUTTON      "Cancel",IDCANCEL,138,23,50,14
     PUSHBUTTON      "Cancel",IDCANCEL,138,23,50,14
     PUSHBUTTON      "&Test!",IDC_BUTTON1,48,14,49,15
     PUSHBUTTON      "&Test!",IDC_BUTTON1,48,14,49,15
END
END
                         </pre></li>
                         </pre></li>
Line 113: Line 113:
     // Get the info for this class.
     // Get the info for this class.
         // #32770 is the default class name for dialogs boxes.
         // #32770 is the default class name for dialogs boxes.
     ::GetClassInfo(AfxGetInstanceHandle(), &quot;#32770&quot;, &wc);
     ::GetClassInfo(AfxGetInstanceHandle(), "#32770", &wc);


     // Change the name of the class.
     // Change the name of the class.
     wc.lpszClassName = &quot;MyPrivateClassName&quot;;
     wc.lpszClassName = "MyPrivateClassName";


     // Register this class so that MFC can use it.
     // Register this class so that MFC can use it.

Latest revision as of 12:52, 21 July 2020

Knowledge Base


How to provide your own Window class name for an MFC dialog box

Article ID: 251059

Article Last Modified on 11/21/2006



APPLIES TO

  • Microsoft Foundation Class Library 4.2, when used with:
    • Microsoft Visual C++ 5.0 Enterprise Edition
    • Microsoft Visual C++ 6.0 Enterprise Edition
    • Microsoft Visual C++ 5.0 Professional Edition
    • Microsoft Visual C++ 6.0 Professional Edition
    • Microsoft Visual C++ 6.0 Standard Edition
    • Microsoft Visual C++ .NET 2003 Standard Edition
    • Microsoft Visual C++ .NET 2002 Standard Edition
    • Microsoft Visual C++ 2005 Express Edition



This article was previously published under Q251059

Note Microsoft Visual C++ .NET 2002 and Microsoft Visual C++ .NET 2003 support 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. Microsoft Visual C++ 2005 supports both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model.

SUMMARY

This 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 INFORMATION

To provide your own Window Class Name, follow these steps:

  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.
  6. Build and run your application. Use the Spy++ tool to verify that the dialog now uses the new class name.


REFERENCES

238100 Limiting 32-bit MFC SDI applications to a single instance in WinCE



Additional query words: one instance single limit restrict define personal

Keywords: kbarchitecture kbdlg kbfaq kbhowto kbresource kbwndwclass KB251059