我正在处理 Win32 应用程序。所有绘图都在 WM_PAINT 中完成。它工作正常。我在其中添加了一项功能。当我单击按钮时,将执行命令提示符。这我可以使用 WinExec 完成。现在,当我移动 Cmd.exe 时,背景绘图未完成。 我用 CreateProcess 更新了代码,同样的事情也发生了。谁能帮我看看这段代码有什么问题。是因为当我专注于此窗口时,焦点丢失并且绘图未完成。
代码
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
TCHAR wchCmdPath[MAX_PATH];
memset(wchCmdPath,_T('\0'),MAX_PATH);
GetSystemDirectory(wchCmdPath,MAX_PATH);
wcscat(wchCmdPath,_T("\\cmd.exe"));
// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line)
wchCmdPath, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
return;
}
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
InvalidateRect(hwnd,NULL,TRUE);
UpdateWindow(hwnd);
提前致谢
最佳答案
这可能是因为 WinExec
在生成的可执行文件调用 GetMessage
时返回或直到指定超时(参见:http://msdn.microsoft.com/en-us/library/ms687393(v=vs.85).aspx)。
这意味着在这种情况发生之前,您的程序会卡在这一行,因此不会处理消息(包括 WM_PAINT
)。 CreateProcess
没有这个问题,但您是否一直在等待它?
关于c++ - Win32 应用程序中的绘图问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4448838/