我如何看看我的表是目前在其他的顶部? [英] How do I see if my form is currently on top of the other ones?

查看:127
本文介绍了我如何看看我的表是目前在其他的顶部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上了,我怎么知道我的计划是上述所有其他的人分层?

Basically, how do I tell if my program is layered above all the other ones?

推荐答案

一个相当简单的方法是为P / Invoke的 GetForegroundWindow()和比较HWND返回。应用程序的form.Handle财产

A fairly simple way is to P/Invoke GetForegroundWindow() and compare the HWND returned to the application's form.Handle property.

using System;
using System.Runtime.InteropServices;

namespace MyNamespace
{
    class GFW
    {
        [DllImport("user32.dll")]
        private static extern IntPtr GetForegroundWindow();

        public bool IsActive(IntPtr handle)
        {
            IntPtr activeHandle = GetForegroundWindow();
            return (activeHandle == handle);
        }
    }
}



然后,从您的表格:

Then, from your form:

if (MyNamespace.GFW.IsActive(this.Handle))
{
  // Do whatever.
}

这篇关于我如何看看我的表是目前在其他的顶部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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