如何将窗口置于通过CreateProcess创建的进程之上
How to bring window on top of the process created through CreateProcess
我正在使用CreateProcess API从我的应用程序启动一个进程,我想把新进程的窗口放在顶部。有办法吗?我们在CreateProcess中有任何标志或类似的东西吗?
您可以尝试使用CreateProcess传入的STARTUPINFO结构并设置SW_SHOW。不过,我不确定这是否有助于将注意力转移到高层。如果这不起作用,请尝试以下操作:
首先,不要使用FindWindow(),它是不必要的不可靠的,因为它只通过窗口名和类名工作。相反,应该从CreateProcess()调用中读取lpProcessInformation并获取dwProcessId。然后调用EnumWindows(),让你的回调看起来像这样:
BOOL CALLBACK EnumWindowsProc( HWND hwnd, LPARAM lParam ) {
DWORD dwPID;
GetWindowThreadProcessId( hwnd, &dwPID );
if( dwPID == lParam ) {
SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
// Or just SetFocus( hwnd );
return FALSE;
}
return TRUE;
}
当调用EnumWindows()时,您将需要传入之前捕获的PID作为lParam,如下所示:
EnumWindows( EnumWindowsProc, ( LPARAM )( PI -> dwProcessId ) );
您需要启动的应用程序的窗口句柄。如果你没有,你可以使用FindWindowA API调用。
然后使用SetFocus API调用,并将窗口句柄作为参数。
相关链接:
http://www.andreavb.com/tip020001.html
http://msdn.microsoft.com/en-us/library/aa697422%28v=vs.71%29.aspx
相关文章:
- C++ 无法识别创建进程'telnet'
- gcc 找不到 -lgcc, g++.exe: 错误: 创建进程: 没有这样的文件或目录
- 创建进程 API 失败,在窗口 122 上出现错误代码 10
- 为什么创建进程 API 调用会导致内存访问冲突?
- 创建进程失败,意外错误
- C++ - 创建进程失败代码 2
- 创建进程使用路径时出现错误事件:类型 "char *" 的 E0167 参数与类型 "LPWSTR" 的参数不兼容
- 无法使用创建进程重定向标准输出
- C++ Mingw32 创建进程() 失败,错误代码 2:系统找不到指定的文件
- 来自 c++ 服务的 CreateProcessAsUser 创建进程,但没有控制台
- 我试图创建进程的二叉树结构,其中每个进程不超过 2 个子进程
- 如何在 DPI 感知设置为DPI_AWARENESS_CONTEXT_UNAWARE的情况下创建进程
- 创建进程命令行参数
- 创建进程和重定向输出
- 从创建进程创建的进程获取输出
- 使用创建进程函数创建"dir"命令失败,错误代码为 2
- 创建进程不继承父环境
- 创建进程失败,错误代码'740' Windows7 64 位
- Windows 在创建进程时如何传递 ANSI 命令行
- 创建进程作为用户 - 错误 1305