CreateDialog

This is a discussion on CreateDialog within the Windows Programming forums, part of the Platform Specific Boards category; Why is this CreateDialog not working? IDD_DIALOG1 is the name of the dialog box I created with the visual editor ...

  1. #1
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    CreateDialog

    Why is this CreateDialog not working?

    IDD_DIALOG1 is the name of the dialog box I created with the visual editor

    Code:
    
    
    #include <windows.h>
    
    #define IDD_DIALOG1     101
    
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
    BOOL    CALLBACK DialogBoxProc (HWND, UINT, WPARAM, LPARAM) ;
    HWND MainDialogBox=NULL ;
    
    HINSTANCE hInstance ;
    
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
    {
         static TCHAR szAppName[] = TEXT ("HelloWin") ;
         HWND         hwnd ;
         MSG          msg ;
         WNDCLASS     wndclass ;
    
         wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
         wndclass.lpfnWndProc   = WndProc ;
         wndclass.cbClsExtra    = 0 ;
         wndclass.cbWndExtra    = 0 ;
         wndclass.hInstance     = hInstance ;
         wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
         wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
         wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
         wndclass.lpszMenuName  = NULL ;
         wndclass.lpszClassName = szAppName ;
    
         if (!RegisterClass (&wndclass))
         {
              MessageBox (NULL, TEXT ("This program requires Windows NT!"), 
                          szAppName, MB_ICONERROR) ;
              return 0 ;
         }
         
    	
         hwnd = CreateWindow (szAppName,                  // window class name
                              TEXT ("The Hello Program"), // window caption
                              WS_OVERLAPPEDWINDOW,        // window style
                              CW_USEDEFAULT,              // initial x position
                              CW_USEDEFAULT,              // initial y position
                              CW_USEDEFAULT,              // initial x size
                              CW_USEDEFAULT,              // initial y size
                              NULL,                       // parent window handle
                              NULL,                       // window menu handle
                              hInstance,                  // program instance handle
                              NULL) ;                     // creation parameters
         
         ShowWindow (hwnd, SW_SHOWMAXIMIZED) ;
         UpdateWindow (hwnd) ;
    
    
    	 MainDialogBox=CreateDialog (hInstance, MAKEINTRESOURCE(IDD_DIALOG1), 
                                      hwnd, DialogBoxProc) ;
    
    
    	         if(MainDialogBox != NULL)
            {
                ShowWindow(MainDialogBox, SW_SHOW);
            }
            else
            {
                MessageBox(hwnd, "CreateDialog returned NULL", "Warning!",  
                    MB_OK | MB_ICONINFORMATION);
            }
    
    
    
    
    	 
    	    
    
    	while(GetMessage(&msg, NULL, 0, 0) > 0)
    	{
    		if(!IsDialogMessage(MainDialogBox, &msg))
    		{
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    		}
    	}
         return msg.wParam ;
     
    }
    
    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
         HDC         hdc ;
         PAINTSTRUCT ps ;
         RECT        rect ;
    
         int x;
      
    // int Width, Height; 
         
         switch (message)
         {
         case WM_CREATE:
    		 
    
         
    	 ShowWindow(MainDialogBox, SW_SHOW);
    
         case WM_PAINT:
              hdc = BeginPaint (hwnd, &ps) ;
    
                     
              EndPaint (hwnd, &ps) ;
              return 0 ;
              
         case WM_DESTROY:
              PostQuitMessage (0) ;
              return 0 ;
         }
         return DefWindowProc (hwnd, message, wParam, lParam) ;
    }
    
    
    
    
    
    BOOL CALLBACK DialogBoxProc (HWND hDlg, UINT message, 
                               WPARAM wParam, LPARAM lParam)
    
    
    {
         switch (message)
         {
         case WM_INITDIALOG :
              return TRUE ;
              
         case WM_COMMAND :
              switch (LOWORD (wParam))
              {
              //case IDOK :
              //case IDCANCEL :
                  // EndDialog (hDlg, 0) ;
                //   return TRUE ;
              }
              break ;
         }
         return FALSE ;
    }


    Sorry I haven't been coding in win32 for long (it's obvious isn't it?
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Cast your callback function to a DLGPROC like this:

    Code:
    MainDialogBox=CreateDialog (hInstance, MAKEINTRESOURCE(IDD_DIALOG1), hwnd, (DLGPROC)DialogBoxProc) ;
    Should be fine.. or you can use the C++ static-cast if you like
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    why do you have to cast it? BTW it is still not working, I'll just start over.....
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    If you obtain an error number with GetLastError() life is much easier.

    Code:
    #define IDD_DIALOG1     101
    Doies this also occur at the top of the rc file? Typically this goes in a header file which you #include into both the c file and the rc file.

    If IDD_DIALOG1 is not defined to a number in the rc file it is taken as the name so you can try:
    Code:
    CreateDialog (hInstance, "IDD_DIALOG1",  hwnd, DialogBoxProc) ;

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Well I kind of assumed you had a resource file and header with the appropriate information in it. I simply created my own with your driver and it did not work. Casting to the DLGPROC then made it work because as it stood it was not of the correct type. Make sure you create your resource correctly.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  6. #6
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    I am getting this error

    NuevoClienteWindow = CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE (IDD_DIALOG1), hwnd, NuevoCliente);
    ShowWindow(NuevoClienteWindow,SW_SHOW);

    1400 (Invalid Windows Handle)
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  7. #7
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    I think that maybe I am forgetting some settings on the visual editor, because if I create a new one without many changes to it and try load it it works, but if I make any changes whatsoever to it in the visual editor it doesn't work. I am relatively new to this visual editor stuff.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    What do you mean by doesn't work. Do you mean the changes aren't there or it the function call begins to fail? If it is the latter that is very strange. If the changes aren't taking place then you need to make sure you are saving the resource. You can also try a "rebuild all" and see if that helps. Really, making changes should not be that big of a deal.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  9. #9
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Sometimes when I create a new dialog box the default one, the small one works, just whenever it feels like it. But after it is created if I make some changes to it ie. Add a new static text or edit box, then the call to CreateDialog fails and I get error code 1400 Invalid windows handle.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  10. #10
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    I got it fixed :-D
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. combobox reacts strangely to a mouse
    By johny145 in forum Windows Programming
    Replies: 2
    Last Post: 03-07-2005, 05:32 PM
  2. CreateDialog fails (Using resource but not MFC)
    By skiingwiz in forum Windows Programming
    Replies: 5
    Last Post: 03-03-2005, 06:04 PM
  3. CreateDialog() failure
    By LuckY in forum Windows Programming
    Replies: 8
    Last Post: 05-09-2003, 04:47 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21