Jump to content
  • Advertisement
Sign in to follow this  
chawk

[C++/Win32] Modal dialog box without DialogBox()

This topic is 4265 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My program currently starts in WinMain, creates a non-modal dialog box with CreateDialog and a dialog resource file, and then it pumps the message loop until program exit. Inside the dialog proc, I process the various WM_COMMAND messages for the controls on my main dialog window. Straightforward so far. One of my controls is a button that I want to launch a second dialog window, have that window modal, but I want control of the message loop of this new dialog because I'm doing intensive calculations through the life of the dialog window until I either meet my stopping condition or the user presses cancel. Therefore, I need to be able to process the messages and then loop through my calculation code. I'm failing right now in creating a window which operates normally and disables the previous main dialog and and returns proper control once it closes. code:

// in WinMain
dlg = CreateDialog(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, dialogProc);

while ((result = GetMessage(&msg, NULL, 0, 0)) != FALSE)
{
    if (!IsDialogMessage(dlg, &msg))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}

// done



// in the dialog proc
	switch (msg)
	{
        case WM_INITDIALOG:
            // init stuff
            return TRUE;

        case WM_COMMAND:
            switch (LOWORD(wParam))
            {
            case CMD_BUTTON:
                // here's where I want to disable input to the main dlg window,
                // launch my new dialog box, have it complete, then return
                // control to the main dlg
                EnableWindow(dlg, FALSE);  // is this necessary?
                launchNewDialog();
                EnableWindow(dlg, TRUE);
                return TRUE;
            }
        }


// now for launchNewDialog

// parent hWnd is the dlg
newDlg = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(DLG_CALCULATE), dlg, calculationProc);

while (!done)
{
    // check if there are messages to process
    if (PeekMessage(&msg, newDlg, 0, 0, PM_NOREMOVE) != 0)
    {
        while (PeekMessage(&msg, newDlg, 0, 0, PM_REMOVE) != 0)
        {
            if (msg.message == WM_QUIT)
                done = TRUE;
            else
            {
                if (!IsDialogMessage(newDlg, &msg))
                {
                    TranslateMessage(&msg);
                    DispatchMessage(&msg);
                }
            }
        }
    }

    // here's where I do my calculations
    calculationFunction();
}

//and finally, the newDlg's proc
switch (msg)
{
case WM_COMMAND:
    switch (LOWORD(wParam))
    {
    case CMD_CANCEL_CALCULATION:
        DestroyWindow(hDlg);
        return TRUE;
    }

    case WM_DESTROY:
        PostQuitMessage(0);
        return TRUE;
}


...am I going about this correctly? Currently, once I close the new dialog box (which for now is just hitting cancel), it does close as expected, but the previous main dialog is frozen and unresponsive. I have to close it with ctrl-alt-del. I'm confused :( Any help is greatly appreciated!

Share this post


Link to post
Share on other sites
Advertisement
er crap, I just realized I posted this in Game Programming and not in General Programming like I intended. if an admin wants to move it, please do :P

Share this post


Link to post
Share on other sites
That's an option, of course, but I'm really rusty with threaded programming :P Do you have any ideas on how to coordinate/synchronize data reading/writing between my calculation thread and my main thread (which will display results) ?

Something using globals and mutexes and some such?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!