透明窗口(或绘制到屏幕)没有鼠标捕获 [英] Transparent Window (or Draw to screen) No Mouse Capture

查看:566
本文介绍了透明窗口(或绘制到屏幕)没有鼠标捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个应用程序,我编码,我想做出出现一个警告消息,显示大量半透明的警告信息,而不会影响用户的工作。基本上我会褪色的消息,但从未将它的不透明度为1,我希望用户能够点击通过的消息,就好像它不存在。

In an app I'm coding I would like to make an alert message to appear that displays a large semi-transparent warning message without affecting the users work. Basically I will fade in the message but never set it's opacity to 1 and I want the user to be able to click 'through' the message as if it isn't there.

我已经通过在顶部窗口总是使用并设置窗口样式为无,并设置背景和透明度关键白开始。在这个窗口中有一个与它包含了警报消息(以后我可能会覆盖漆事件和油漆使用GDI消息)大字体的标签。我用一个定时器拨打了它的不透明度再次回落拨回之前消失在邮件中。它的工作原理确定的,重点是不是从任何应用程序窃取,但透明的形式捕获鼠标事件,而不是在它下面(实际上其中大部分是透明的不捕获鼠标事件的形式,只有标签文本做形式)。

I have started by using an always on top window and setting the window style to none and setting the background and transparency key to white. On this window there is a label with a large font which contains the alert message (later I'll probably override the paint event and paint the message using GDI). I use a timer to fade in the message by dialling up it's opacity before dialling it back down again. It works OK in that the focus isn't stolen from any apps but the transparent form captures the mouse events, not the form below it (actually most of the form which is transparent doesn't capture the mouse events, only the label text does).

另外我不知道它的最佳方法,也许我应该直接画到屏幕上莫名其妙。

Also I'm not sure it's the optimal approach, maybe I should be painting straight to the screen somehow.

我应该如何改善的事情。

How should I improve things.

推荐答案

重写CreateParams属性上的Form类并确保WS_EX_NOACTIVATE扩展样式设置。我的是这样的:

Override the CreateParams property on your Form class and make sure the WS_EX_NOACTIVATE extended style is set. Mine looks like this:

protected override CreateParams CreateParams
{
  get
  {
    CreateParams baseParams = base.CreateParams;

    baseParams.ExStyle |= ( int )(
      Win32.ExtendedWindowStyles.WS_EX_LAYERED |
      Win32.ExtendedWindowStyles.WS_EX_TRANSPARENT |
      Win32.ExtendedWindowStyles.WS_EX_NOACTIVATE |
      Win32.ExtendedWindowStyles.WS_EX_TOOLWINDOW );

    return baseParams;
  }
}

值上面使用ExtendedWindowStyles是:

Values for ExtendedWindowStyles used above are:

WS_EX_LAYERED = 0x00080000,
WS_EX_NOACTIVATE = 0x08000000,
WS_EX_TOOLWINDOW = 0x00000080,
WS_EX_TRANSPARENT = 0x00000020,

这篇关于透明窗口(或绘制到屏幕)没有鼠标捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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