使用窗口句柄在最上面创建一个窗口 [英] Make a window topmost using a window handle

查看:19
本文介绍了使用窗口句柄在最上面创建一个窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Process 类启动应用程序后,我想让该窗口位于最顶部.目前,我的应用程序是最顶层的窗口,所以当我启动另一个应用程序时它不会显示.我想到的一件事是我可以在启动进程之前为我的应用程序设置 topmost = false,这个问题是我想在向用户显示之前给进程足够的时间来加载它,所以我想当我将另一个应用程序切换到最顶层时,可以更好地控制.

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 with SetWindowPos 来完成这个:

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);

这篇关于使用窗口句柄在最上面创建一个窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆