C#使窗口最上面使用窗口句柄 [英] C# make a window topmost using a window handle
问题描述
使用Process类启动应用程序后,我想使该窗口最上面。目前,我的应用程序是最顶层的窗口,因此,当我启动其他应用程序不显示。来考虑的一件事是我可以设置为我的应用程序最顶层=虚假启动过程之前,这个问题是我想给这个过程足够的时间它显示给用户之前加载,所以我想当我在其他应用程序切换到最上面的更多的控制。
After launching an application using the Process class I'd like to make that window topmost. Currently, my app is the topmost window so when i launch the other app it doesn't display. One thing that came to mind is that I could set topmost = false for my application before launching the process, the problem with this is I want to give the process ample time to load up before displaying it to the user, so I'd like more control over when I switch the other application to the topmost.
推荐答案
您需要使用的P / Invoke与SetWindowPos 以accopmlish这样的:
You need to use P/Invoke with SetWindowPos to accopmlish this:
[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
const UInt32 SWP_NOSIZE = 0x0001;
const UInt32 SWP_NOMOVE = 0x0002;
const UInt32 SWP_SHOWWINDOW = 0x0040;
// Call this way:
SetWindowPos(theWindowHandle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
这篇关于C#使窗口最上面使用窗口句柄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!