Thread: How to set up main window/dialogs so...

  1. #1
    He's trying.
    Join Date
    Apr 2005
    Location
    Missouri, US
    Posts
    70

    Question How to set up main window/dialogs so...

    Hey,
    I'm trying to set up my win32 app (C++ straight win32 API, by the way) in a way that when someone selects a menu item/makes a certain choice in a pop-up dialog, the main-window changes, for instance buttons are added and text, etc...
    So far my attempts to do this have failed. Things I've tried:

    -Using a WS_CHILD dialog that opens up inside my main window that holds all the new controls I want to add.
    Failed - not sure why, the PUSHBUTTON I used wasn't clickable and my program kept focus on main window while being unable to click the "X" button there, so I have to close out with Task Manager.

    -Using CreateWindow() or CreateWindowEx() to create every control fresh. Seems really ugly, hacky, and difficult. This isn't the only way, I hope?

    I've also thought about turning my main window into a dialog box itself. Don't know if this would help or if it would be modular, though.


    Are any of these on-track, or should one work and I'm just not implementing it right? I have a feeling if I could get the WS_CHILD dialogs to work, it'd be super-easy to change main-window states because I could just end one dialog and start another...If this is the case, I can post code.

    Thanks very much! This is my first venture into Win32 so I'm trying to understand how it all works...after that I think I'll move to a wrapper API like QT or FOX.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Either for you methods should work fine. I can't tell you why the child dialog didn't work for you without seeing some code though. Another option you may want to look at is the use of property sheets. Property sheets is an easy way to sort of stack multiple dialogs on the same page, and only show one at a time.

  3. #3
    He's trying.
    Join Date
    Apr 2005
    Location
    Missouri, US
    Posts
    70
    Aye, thanks. Here's some hopefully relevant bits of code:
    Code:
    // An example dialog.  Not one I'd particularly like to put in the main window, but works
    // as an example.
    
    DIALOG_NEW_MP_JOIN DIALOG DISCARDABLE 100, 150, 150, 60
    STYLE WS_CHILD | WS_VISIBLE   // I added WS_VISIBLE, didn't help though...
    CAPTION "Join a Game"
    FONT 8, "MS Sans Serif"
    {
    	LTEXT "Please enter target IP address:", ID_TEXT_1, 5, 5, 100, 20
    	EDITTEXT ID_EDIT_IP, 15, 25, 40, 14
    	DEFPUSHBUTTON "&Let's go!", IDOK, 80, 40, 50, 14
    }
    Calling the dialog from my main window proc:
    Code:
    		case ID_NEW_MP_JOIN:
    		{
    			int returnVal = DialogBox((HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
    						MAKEINTRESOURCE(DIALOG_NEW_MP_JOIN), hwnd, processNewMPJoinDialog);
    			if (returnVal == IDCANCEL)
    				/*messagebox*/;
    			break;
    		}
    The (HINSTANCE) way of calling the dialog causes no dialog to become visible, but program functions normally. GetModuleHandle(NULL) in place of the (HINSTANCE) parameter causes the dialog to appear, but it won't function and I have to End-Taskify my program.


    If anything obvious jumps out at you, please let me know.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    The problem is you are creating a Modal dialog instead of a Modeless dialog. This is why your application appears to freeze after you call DialogBox().

    Instead of calling DialogBox(), you need to call CreateDialog(). You also have to change your message loop as well in order to dispatch the dialog messages. It would look something like:

    Code:
    while ( (bRet = GetMessage(&msg, NULL, 0, 0)) != 0 ) 
    { 
        if (bRet == -1 )
        {
            // handle the error and possibly exit
        }
        else if (!IsWindow(hwndModelessDlg) || !IsDialogMessage(hwndModelessDlg, &msg)) 
        { 
            TranslateMessage(&msg); 
            DispatchMessage(&msg); 
        } 
    }
    This calls IsDialogMessage() which will process the message if it is for the modeless dialog and return false. If the message is not for the modeless dialog, then IsDialogMessage() returns false, and the message is processed by TranslateMessage() and DispatchMessage().

  5. #5
    He's trying.
    Join Date
    Apr 2005
    Location
    Missouri, US
    Posts
    70
    Thanks! I should've known better since I've been using theForger's guide and he has information about modeless dialogs. Anyway, I've got it sorted out and now all I have to do is hack up a management system to make sure all these dialogs don't layer on top of each other!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 02:39 PM
  2. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  3. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM
  4. void main
    By Shadow in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 05-29-2002, 07:08 PM
  5. void or int for main?:)
    By bigtamscot in forum C Programming
    Replies: 13
    Last Post: 09-27-2001, 03:11 AM