WS_EX_TRANSPARENT - 它实际上是做什么的? [英] WS_EX_TRANSPARENT - What does it actually do?

查看:63
本文介绍了WS_EX_TRANSPARENT - 它实际上是做什么的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我创建了一个由用户控制不透明度的表单.如果表单是完全透明的,鼠标事件通过"(没有我的干预),否则我的表单会处理它们.

In my project, I create a form with the opacity controlled by the user. If the form was fully transparent the mouse events 'fell through' (without my intervention), otherwise my form handled them.

阅读这个问题后 并覆盖 CreateParams 属性以在我的表单上设置 WS_EX_TRANSPARENT 标志,现在当不透明度为任何值 <255 时,它允许鼠标事件发生.

After reading this question and overriding the CreateParams property to set the WS_EX_TRANSPARENT flag on my form, it now allows mouse events to fall through when the opacity is any value <255.

这正是我想要的,但让我担心的是我不明白它为什么有效.

This is exactly what I want, but it concerns me that I don't understand why it works.

据我所知,WS_EX_TRANSPARENT 旨在通过在其 Paint 方法中从其下方的表单窃取位"来使表单看起来透明,因此:

From what I've read, WS_EX_TRANSPARENT is meant to make the form appear transparent by 'stealing bits' from the form below it in its Paint method, therefore:

  1. 我的窗体的 Paint 方法和其中的所有控件不应该被调用,对吗?由于 WS_EX_TRANSPARENT 应该导致 Windows 覆盖它们,那么为什么它会影响输入处理而不影响我的表单的绘制?

  1. The Paint method of my form and all the controls in it should never be called, right? As WS_EX_TRANSPARENT should cause Windows to override them, so why does it affect input handling but not the drawing of my form?

不透明度应该对鼠标事件的处理没有影响,就像油漆被覆盖一样,本地"不透明度应该无关紧要,不是吗?

The opacity should have no impact on the handling of mouse events, as if Paint is being overridden the 'local' opacity should not matter, no?

谁能解释一下,这个标志真正有什么作用?它是如何工作的?

Could someone explain, what this flag really does? How does it work?

推荐答案

WS_EX_TRANSPARENT 使您的事件(如鼠标点击)穿过您的窗口等.不透明度是一个单独的概念,它指示窗口管理器在绘制表单时应用字母混合.这两件事并不相关,但是当您将它们结合起来时,您将获得您所需要的效果.

WS_EX_TRANSPARENT makes your events (like mouse clicks) fall through your window, amongst other things. Opacity is a separate concept, it instructs window manager to apply alphablending when drawing your form. Those two things are not related, but when you combine them you get the effect you need in your case.

所以:

  1. 表单的 Paint 方法正常调用,不透明度与此无关.

  1. Paint method of your form is called normally as it should, opacity has nothing to do with it.

不透明度与鼠标事件无关,如第一段所述.

Opacity does not have anything to do with mouse events, as described in the first paragraph.

这篇关于WS_EX_TRANSPARENT - 它实际上是做什么的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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