How to get hWnd of window opened by ShellExecuteEx.. hProcess?(如何获得ShellExecuteEx..hProcess打开的窗口的hWnd?)
问题描述
这个简单"的问题似乎充满了附带问题.
例如.新进程是否打开多个窗口;它有启动画面吗?
有没有简单的方法?(我正在启动 Notepad++ 的新实例)
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?
}
...
推荐答案
首先使用 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 use EnumWindows
and GetWindowThreadProcessId
to determine which windows in the system belong to the created process.
例如:
struct ProcessWindowsInfo
{
DWORD ProcessID;
std::vector<HWND> Windows;
ProcessWindowsInfo( DWORD const AProcessID )
: ProcessID( AProcessID )
{
}
};
BOOL __stdcall EnumProcessWindowsProc( HWND hwnd, LPARAM lParam )
{
ProcessWindowsInfo *Info = reinterpret_cast<ProcessWindowsInfo*>( lParam );
DWORD WindowProcessID;
GetWindowThreadProcessId( hwnd, &WindowProcessID );
if( WindowProcessID == Info->ProcessID )
Info->Windows.push_back( hwnd );
return true;
}
....
if( ShellExecuteEx(&sei) )
{
WaitForInputIdle( sei.hProcess, INFINITE );
ProcessWindowsInfo Info( GetProcessId( sei.hProcess ) );
EnumWindows( (WNDENUMPROC)EnumProcessWindowsProc,
reinterpret_cast<LPARAM>( &Info ) );
// Use Info.Windows.....
}
这篇关于如何获得ShellExecuteEx..hProcess打开的窗口的hWnd?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何获得ShellExecuteEx..hProcess打开的窗口的hWnd?


基础教程推荐
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 从 std::cin 读取密码 2021-01-01