[英]C++ GUI App: Starting a child process in WndProc ( no MFC )
I have been having trouble starting a child process in my GUI application. 我在使用GUI应用程序启动子进程时遇到了麻烦。 Below is my WndProc.
以下是我的WndProc。 I would like the ID_TOOLS_NEWPROCESS case to start a new process which will open the dialog box.
我希望ID_TOOLS_NEWPROCESS案例启动一个新过程,该过程将打开对话框。 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. 我希望我已经清楚地解释了,在此问题上的任何帮助将不胜感激。
EDIT: @Roger Stewart 编辑: @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. 编辑2:这是我现在拥有的代码,但是我仍然无法选择“关于”框打开的主窗口。
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. @David-您能否阐明为什么它仍然没有返回期望的结果。
Thanks @David. 谢谢@大卫。 The solution was indeed to use
CreateDialog()
rather than DialogBox()
解决方案的确是使用
CreateDialog()
而不是DialogBox()
My program is now functioning as I would like it too. 我的程序现在也可以正常运行了。
-Dan. -担。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.