如何在所有窗口上方显示半透明窗口?

时间:2015-09-07 05:24:42

标签: c# python c++ windows opengl

如何在所有窗口上方显示半透明窗口?并在此窗口中加载一些信息:图像/文本/按钮?我需要在windows / linux(或至少是windows)的所有desctop表上方显示一些半透明区域,并且在该区域的中心,我需要显示一些带有文本的图像。但是,尽管如此,它不能成为当前工作应用程序的焦点。它会自动隐藏。 请看图像:普通的desctop和我想制作的半透明窗口。 谢谢。 enter image description here enter image description here

1 个答案:

答案 0 :(得分:1)

在C#中,这是满足您需求的代码:

注意:它不会专注于启动,并且在点击它时不会重点关注。

public static class ExtendedWindowStyles
{

    public static readonly Int32

    WS_EX_ACCEPTFILES = 0x00000010,

    WS_EX_APPWINDOW = 0x00040000,

    WS_EX_CLIENTEDGE = 0x00000200,

    WS_EX_COMPOSITED = 0x02000000,

    WS_EX_CONTEXTHELP = 0x00000400,

    WS_EX_CONTROLPARENT = 0x00010000,

    WS_EX_DLGMODALFRAME = 0x00000001,

    WS_EX_LAYERED = 0x00080000,

    WS_EX_LAYOUTRTL = 0x00400000,

    WS_EX_LEFT = 0x00000000,

    WS_EX_LEFTSCROLLBAR = 0x00004000,

    WS_EX_LTRREADING = 0x00000000,

    WS_EX_MDICHILD = 0x00000040,

    WS_EX_NOACTIVATE = 0x08000000,

    WS_EX_NOINHERITLAYOUT = 0x00100000,

    WS_EX_NOPARENTNOTIFY = 0x00000004,

    WS_EX_OVERLAPPEDWINDOW = WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE,

    WS_EX_PALETTEWINDOW = WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST,

    WS_EX_RIGHT = 0x00001000,

    WS_EX_RIGHTSCROLLBAR = 0x00000000,

    WS_EX_RTLREADING = 0x00002000,

    WS_EX_STATICEDGE = 0x00020000,

    WS_EX_TOOLWINDOW = 0x00000080,

    WS_EX_TOPMOST = 0x00000008,

    WS_EX_TRANSPARENT = 0x00000020,

    WS_EX_WINDOWEDGE = 0x00000100;

}

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        this.TopMost = true;
    }

    protected override bool ShowWithoutActivation
    {
        get
        {
            return true;
        }
    }
    protected override CreateParams CreateParams
    {
        get
        {
            var currentParameters = base.CreateParams;

            currentParameters.ExStyle |= (int)(ExtendedWindowStyles.WS_EX_NOACTIVATE | ExtendedWindowStyles.WS_EX_TOOLWINDOW);

            return currentParameters;
        }
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
        this.ClientSize = Screen.PrimaryScreen.Bounds.Size;
        this.Left = 0;
        this.Top = 0;
        this.Opacity = 0.5;
    }
}

将您想要/需要的其他控件(图像,标签等)放在您的表单上。

您只需使用form.ShowDialog();从应用程序代码中弹出此表单。如果您想从任何地方弹出此表单,请将其设置为可执行文件,并在需要时运行它。

相关问题