window doesn't open

This is a discussion on window doesn't open within the Windows Programming forums, part of the Platform Specific Boards category; can someone tell me why my dialog box doesn't open please. It builds fine, it just doesn't open a window.. ...

  1. #1
    Registered User eth0's Avatar
    Join Date
    Dec 2003
    Posts
    164

    window doesn't open

    can someone tell me why my dialog box doesn't open please.
    It builds fine, it just doesn't open a window..


    Code:
    #include <windows.h>
    #include "resource.h" 
    
    BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
    	switch(Message)
    	{
    		case WM_INITDIALOG:
    			
                    return TRUE;
    		case WM_COMMAND:
    			switch(LOWORD(wParam))
    			{
    				case IDOK:
    				        MessageBox(NULL, "You hit OK", "Note", MB_OK);
    				break;
                
    				case IDCANCEL:
    				        MessageBox(NULL, "You hit Cancel", "Note", MB_OK);
    				break;
                             }
    		case WM_CLOSE:
    			EndDialog(hwnd, 0);
    		break;
    		default:
    			return FALSE;
    	}
    	return TRUE;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    	LPSTR lpCmdLine, int nCmdShow)
    {
    	return DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, DlgProc);
    }
    My .rc file is a follows:

    Code:
    #include <windows.h>
    #include <afxres.h>
    #include "resource.h"
    
    IDD_MAIN DIALOG DISCARDABLE  0, 0, 186, 90
    STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
    CAPTION "Dialog"
    FONT 8, "MS Sans Serif"
    BEGIN
        DEFPUSHBUTTON   "&Yes",IDOK,23,42,50,14
        PUSHBUTTON      "&No",IDCANCEL,110,41,50,14
        CONTROL         "Progress1",IDC_PROGRESS1,"msctls_progress32",WS_BORDER,
                        14,65,159,10
        CTEXT           "Do you want to download and install Mozilla ActiveX Control?",
                        IDC_STATIC,16,7,152,27
    END
    
    
    /////////////////////////////////////////////////////////////////////////////
    //
    // DESIGNINFO
    //
    
    #ifdef APSTUDIO_INVOKED
    GUIDELINES DESIGNINFO DISCARDABLE 
    BEGIN
        IDD_MAIN, DIALOG
        BEGIN
            LEFTMARGIN, 7
            RIGHTMARGIN, 179
            TOPMARGIN, 7
            BOTTOMMARGIN, 83
        END
    END
    #endif    // APSTUDIO_INVOKED
    Thanks.
    Open source isn't a matter of life or death......
    .......its much more important than that!!


    SuSE Linux - GCC 3.4.2
    XP Pro - Visual Studio 2005 TS, MinGW 3.4.2

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,699
    Try WS_VISIBLE on the dialog style.

    gg

  3. #3
    Registered User eth0's Avatar
    Join Date
    Dec 2003
    Posts
    164
    Hi Codeplug.

    I've tried that, and DS_CENTER but I'm still getting nothing.

    I've pulled this program right down to the bare minimum as you can see above, but I can't get to the bottom of why it won't load.

    Thanks.
    Open source isn't a matter of life or death......
    .......its much more important than that!!


    SuSE Linux - GCC 3.4.2
    XP Pro - Visual Studio 2005 TS, MinGW 3.4.2

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Your dialog resource includes a common control so you need to link with comctl32.lib, otherwise your dialog won't show. But make sure your dialog has the WS_VISIBLE style, too, as Codeplug has recommended.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    And include a call to InitCommonControls or InitCommonControlsEx somewhere in your program.

  6. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Thanks, Quantum1024 - I forgot to mention that.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  7. #7
    Registered User eth0's Avatar
    Join Date
    Dec 2003
    Posts
    164
    OK, I've got it working, (well I didn't quite get the window I was after, but I got something) but I don't understand it ...... at all.

    I didn't link in the comctl32 library, or call InitCommonControls, all I did was remove the braces around 'switch(LOWORD(wParam))' and it worked.

    Here is my working code ......... can anyone shed some light on this please, I'm baffalled

    Code:
    #include <windows.h>
    #include "resource.h" 
    
    
    BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
    	switch(Message)
    	{
    	         case WM_INITDIALOG:
    			
                     break;       
    	         case WM_COMMAND:
    			switch(LOWORD(wParam))
    			
    				case IDOK:
    				        MessageBox(NULL, "You hit OK", "Note", MB_OK);
    				break;
                
    				case IDCANCEL:
    				        MessageBox(NULL, "You hit Cancel", "Note", MB_OK);
    				break;
           
    		case WM_CLOSE:
    			EndDialog(hwnd, 0);
    		break;
    		default:
    			return FALSE;
    	}
    	return TRUE;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    	LPSTR lpCmdLine, int nCmdShow)
    {
    	return DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, DlgProc);
    }
    Last edited by eth0; 05-04-2005 at 06:37 PM.
    Open source isn't a matter of life or death......
    .......its much more important than that!!


    SuSE Linux - GCC 3.4.2
    XP Pro - Visual Studio 2005 TS, MinGW 3.4.2

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    hmm what happens if you put the braces back in and place a return FALSE at the end of your dialog procedure instead of the return TRUE?

  9. #9
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,699
    In your original code, the WM_COMMAND case is falling through to the WM_CLOSE case.

    gg

  10. #10
    Work in Progress..... Jaken Veina's Avatar
    Join Date
    Mar 2005
    Location
    Missouri. Go Imos Pizza!
    Posts
    256
    Yep. There's no break at the end of the WM_COMMAND case, so the code is reading it something like this.
    Code:
      case WM_COMMAND: case WM_CLOSE:
       {
        switch(LOWORD(wParam))
         {
          case IDOK:
            MessageBox(NULL, "You hit OK", "Note", MB_OK);
          break;
          case IDCANCEL:
            MessageBox(NULL, "You hit Cancel", "Note", MB_OK);
          break;
         } 
        EndDialog(hwnd, 0);
       }
      break;
    If either those two messages are received, it does the same thing, which is to check which button was pressed, and then close the entire dialog.

  11. #11
    Registered User eth0's Avatar
    Join Date
    Dec 2003
    Posts
    164
    Hi.

    OK, I fixed up the code, but I'm still not getting the result I want.


    If I leave the braces in for switch (LOWORD(wParam)), as follows, I get no Window

    Code:
    #include <windows.h>
    #include "resource.h" 
    
    
    BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
       switch (Message)
       {
          case WM_INITDIALOG :
             break;       
          case WM_COMMAND:
             switch (LOWORD(wParam))
                case IDOK:
                   MessageBox(NULL, "You hit OK", "Note", MB_OK);
                   break;
                
                case IDCANCEL:
                   MessageBox(NULL, "You hit Cancel", "Note", MB_OK);
                   break;
             break;
          case WM_CLOSE:
             EndDialog(hwnd, 0);
             break;
          default:
             return FALSE;
       }
    	return TRUE;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    	            LPSTR lpCmdLine, int nCmdShow)
    {
       return DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, DlgProc);
    }
    If I remove the braces, I get the message box saying 'you hit cancel' from IDCANCEL.

    Why am I not getting my main dialog box?

    Thanks
    Open source isn't a matter of life or death......
    .......its much more important than that!!


    SuSE Linux - GCC 3.4.2
    XP Pro - Visual Studio 2005 TS, MinGW 3.4.2

  12. #12
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,699
    Use braces in all your switch statements - always.
    Don't allow WM_COMMAND to fall through to the WM_CLOSE case.
    Use WS_VISIBLE.
    Link with comctl32.lib and call InitCommonControls[Ex], or remove the progress bar from your dialog.

    If it sounds like I'm regurgitating the solution - that's because I am.

    gg

  13. #13
    Work in Progress..... Jaken Veina's Avatar
    Join Date
    Mar 2005
    Location
    Missouri. Go Imos Pizza!
    Posts
    256
    He is exactly right. I copied your code exactly and ran it, and got the same results you're talking about. But as soon as I call InitCommonControls() before the return statement of WinMain, it works perfectly. If you add that and don't add in the brackets around the switch statements, you'll see that every time the program closes, the "You hit cancel" box appears. Thus, the program opens, but when it tries to handle an uninitialized control, it closes, causing the cancel box to appear.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  2. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 02:39 PM
  3. opengl help
    By heat511 in forum Game Programming
    Replies: 4
    Last Post: 04-05-2004, 02:08 AM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 11:12 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM

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