使用窗口手柄将窗口置于最上方 [英] Make a window topmost using a window handle

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

问题描述

使用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.

推荐答案

您需要使用使用SetWindowPos进行P /调用以实现此目的:

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天全站免登陆