CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2010
    Posts
    1

    Help with Creating a Custom Class for a modeless dialog popup

    Hello all,

    I desire to create a modeless dialog with a custom class. The dialog
    is created as a form. The code below shows what I'm doing. Yet
    CreateDialog always returns NULL. I guess I don't know what I'm doing
    wrong...

    Code:
    IDRESULTS DIALOGEX 0, 0, 412, 232
    STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_MINIMIZEBOX |
    WS_POPUP | WS_CAPTION | WS_SYSMENU
    EXSTYLE WS_EX_CONTROLPARENT
    CAPTION "Results"
    CLASS "MyClass"
    FONT 8, "MS Shell Dlg", 400, 0, 0x1
    BEGIN
    
    END
    Code:
    HWND RegisterResultsDlg(HINSTANCE hInst, HWND hwnd)
    {
       HWND hwndDlg;
       WNDCLASS wc;
    
       GetClassInfo(hInst,"#32770",&wc);
       wc.lpfnWndProc = DlgResultsProc;
       wc.lpszClassName = "MyClass";
       if(!RegisterClass(&wc))
       {
          MessageBox(NULL, "Failed to Register Custom Dialog Class!", "Error!",
             MB_ICONEXCLAMATION | MB_OK);
          return NULL;
    
       }
    
       hwndDlg = (HWND)CreateDialog(hInst, "MyClass",
          hwnd, DlgResultsProc);
    
       if(hwndDlg == NULL)
       {
          MessageBox(NULL, "Failed to Create Results Dialog Box!", "Error!",
             MB_ICONEXCLAMATION | MB_OK);
          return NULL;
       }
    
       ShowWindow(hwndDlg,SW_SHOW);
       return hwndDlg;
    }
    Last edited by ovidiucucu; February 3rd, 2010 at 03:41 AM. Reason: CODE tags added

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Help with Creating a Custom Class for a modeless dialog popup

    The second parmeter of CreateDialog is not the window class name but the dialog template name.
    In your particular case it has to be MAKEINTRESOURCE(IDRESULTS).
    It is not possible to create a dialog with custom class name by calling CreateDialog. Instead, you have to use CreateWindowEx function.
    CreateDialog calls CreateWindowEx and performs some additional tasks like sending WM_INITDIALOG messge and so on.
    So... it's a little bit to sweat.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured