如何在C#/ Vista中将鼠标事件传递给我的应用程序? [英] How to pass mouse events to applications behind mine in C#/Vista?

查看:187
本文介绍了如何在C#/ Vista中将鼠标事件传递给我的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在C#中编写一个非常专门的应用程序,它在整个桌面上浮动为一个最透明的窗口。我想能够创建并将鼠标事件传递给我的应用程序,并让它们看起来正常运行,以响应这些事件。如果窗口管理员可以做出回应,那么也可能是最好的。



我不是Windows的大师,不确定如何最好地完成这个。
$ b

从此页面:
http://bytes.com /forum/thread270002.html



看来,mouse_event会很好,除了因为我的应用程序浮出水面之外,我猜我的生成的事件永远不会发生在下面的其他应用程序。



似乎替代方案是SendMessage,但这需要大量的手动操纵Windows和鼠标事件生成的不是真实的。



有什么想法来处理这个问题?

解决方案

在查看系统钩子和其他低级解决方案后,我发现一个更简单的方法。



首先,设置表单的TransparencyKey和BackColor成为sam即这对我来说没有任何视觉差异,因为我的表单已经是视觉透明的,但这将有助于让鼠标事件通过。



其次,以下代码将会

 保护重写CreateParams CreateParams 
{
get
{
CreateParams createParams = base.CreateParams;
createParams.ExStyle | = 0x00000020; // WS_EX_TRANSPARENT

return createParams;
}
}

最后,将TopMost设置为true。



您的表单现在将漂浮在所有视觉上,但会放弃所有其他应用的重点。


I am writing a very specialized app in C# that floats as a mostly transparent window over the entire desktop. I want to be able to create and pass mouse events to applications behind mine, and have them appear to operate "normally", responding to those events. It would also be preferable if the window manager could respond.

I am not a Windows guru, and am unsure of how to best accomplish this.

From this page: http://bytes.com/forum/thread270002.html

it would appear that mouse_event would be good, except that since my app is floating over everything else, I'm guessing my generated events would never make it to the other apps underneath.

It seems the alternative is SendMessage, but that requires a fair amount of manual manipulation of windows, and the mouse events generated aren't "authentic."

Any thoughts on the best way to approach this?

解决方案

After looking at System hooks and other low level solutions I found a much simpler method.

First, set the TransparencyKey and BackColor of the form to be the same. This didn't make any visual difference to me as my form was visually transparent already, but this will help in letting mouse events through.

Second, the following code will let mouse events "fall" through your form.

protected override CreateParams CreateParams
{
    get
    {
        CreateParams createParams = base.CreateParams;
        createParams.ExStyle |= 0x00000020; // WS_EX_TRANSPARENT

        return createParams;
    }
}

Lastly, set TopMost to be true.

Your form will now float on top of everything visually, but will give up focus to all other apps.

这篇关于如何在C#/ Vista中将鼠标事件传递给我的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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