简体   繁体   中英

C++ GUI App: Starting a child process in WndProc ( no MFC )

I have been having trouble starting a child process in my GUI application. Below is my WndProc. I would like the ID_TOOLS_NEWPROCESS case to start a new process which will open the dialog box. Will this will allow the main window to remain responsive when the new window opens?

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;

switch (message)
{
case WM_COMMAND:
    wmId    = LOWORD(wParam);
    wmEvent = HIWORD(wParam);
    // Parse the menu selections:
    switch (wmId)
    {
    case IDM_ABOUT:
        DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
        break;
    case IDM_EXIT:
        DestroyWindow(hWnd);
        break;
    case ID_TOOLS_NEWPROCESS:
        DialogBox(hInst, MAKEINTRESOURCE(IDD_NEWBOX), hWnd, NEW);
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    break;
case WM_PAINT:
    hdc = BeginPaint(hWnd, &ps);
    // Draw text in the main window
    TextOut(hdc, 10, 10, L"Main Window",11);
    EndPaint(hWnd, &ps);
    break;
case WM_DESTROY:
    PostQuitMessage(0);
    break;
default:
    return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

I hope I have explained that clearly, Any help on this issue would be greatly appreciated.

  • Dan.

EDIT: @Roger Stewart

The about is using the following as its message pump:

INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam,         LPARAM lParam)
{

UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
    return (INT_PTR)TRUE;

case WM_COMMAND:
    if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDOK)
    {
        EndDialog(hDlg, LOWORD(wParam));
        return (INT_PTR)TRUE;
    }
    break;
}
return (INT_PTR)FALSE;
}

The trouble here is that When the about box is open, the main window behind is unresponsive until the about box is closed. I would like to be able to open and control multiple dialog boxs with the main windows still being responsive.

EDIT 2: This is the code I have now but I am still unable to select the main window with the about box open.

message handler for the about box:

INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{

UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
    return (INT_PTR)TRUE;

case WM_ACTIVATE:
    if (0 == wParam)             // becoming inactive
        hDlgCurrent = NULL;
    else                         // becoming active
        hDlgCurrent = hDlg;
    return FALSE;

case WM_COMMAND:
    if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDOK)
    {
        EndDialog(hDlg, LOWORD(wParam));
        return (INT_PTR)TRUE;
    }
    break;
}
return (INT_PTR)FALSE;
}

Main message loop:

     while (GetMessage(&msg, NULL, 0, 0))
     {
     if (NULL == hDlgCurrent || !IsDialogMessage(hDlgCurrent, &msg))
        {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
        }
     }

@David - could you possibly shed some light on why this is still not returning the desired result.

Thanks @David. The solution was indeed to use CreateDialog() rather than DialogBox()

My program is now functioning as I would like it too.

-Dan.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM