如何获取 ShellExecuteEx..hProcess 打开的窗口的 hWnd?
这个“简单”的问题似乎充满了附带问题。
例如。新进程是否打开多个窗口;有闪屏吗?
有简单的方法吗? (我正在启动 Notepad++ 的新实例)
...
std::tstring tstrNotepad_exe = tstrProgramFiles + _T("\\Notepad++\\notepad++.exe");
SHELLEXECUTEINFO SEI={0};
sei.cbSize = sizeof(SHELLEXECUTEINFO);
sei.fMask = SEE_MASK_NOCLOSEPROCESS;
sei.hwnd = hWndMe; // This app's window handle
sei.lpVerb = _T("open");
sei.lpFile = tstrNotepad_exe.c_str();
sei.lpParameters = _T(" -multiInst -noPlugins -nosession -notabbar ";
sei.lpDirectory = NULL;
sei.nShow = SW_SHOW;
sei.hInstApp = NULL;
if( ShellExecuteEx(&sei) )
{ // I have sei.hProcess, but how best to utilize it from here?
}
...
This "simple" issue seems to be fraught with side issues.
eg. Does the new process open multiple windows; Does it have a splash screen?
Is there a simple way? (I'm starting a new instance of Notepad++)
...
std::tstring tstrNotepad_exe = tstrProgramFiles + _T("\\Notepad++\\notepad++.exe");
SHELLEXECUTEINFO SEI={0};
sei.cbSize = sizeof(SHELLEXECUTEINFO);
sei.fMask = SEE_MASK_NOCLOSEPROCESS;
sei.hwnd = hWndMe; // This app's window handle
sei.lpVerb = _T("open");
sei.lpFile = tstrNotepad_exe.c_str();
sei.lpParameters = _T(" -multiInst -noPlugins -nosession -notabbar ";
sei.lpDirectory = NULL;
sei.nShow = SW_SHOW;
sei.hInstApp = NULL;
if( ShellExecuteEx(&sei) )
{ // I have sei.hProcess, but how best to utilize it from here?
}
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先使用
WaitForInputIdle
暂停程序,直到应用程序启动并等待用户输入(此时主窗口应该已经创建),然后使用EnumWindows
和GetWindowThreadProcessId
来确定系统中哪些窗口属于所创建的进程。例如:
First use
WaitForInputIdle
to pause your program until the application has started and is waiting for user input (the main window should have been created by then), then useEnumWindows
andGetWindowThreadProcessId
to determine which windows in the system belong to the created process.For example: