使 GDI 绘图不可点击 [英] Make GDI drawing not clickable

查看:35
本文介绍了使 GDI 绘图不可点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 GDI 绘图的透明 WinForms 应用程序(我将其用作叠加层).问题是,每当我单击 GDI 绘图时,焦点都会转到应用程序窗口.我该如何转?

I have a transparent WinForms app with GDI drawings (I use it as an overlay). The problem is that whenever I click on the GDI drawing the focus goes to the app window. How do I turn that of?

推荐答案

只要你正确地实现了覆盖(一个拥有的窗口显示为 Shown(owner) 重载,示例) 然后它只需要一点点复制/粘贴代码.Windows 会询问您单击了窗口的哪个部分,您可以回答它是透明的".所以它会继续寻找任何感兴趣的人,下一个是它的父窗口.

As long as you implemented the overlay correctly (an owned window displayed with the Shown(owner) overload, example) then it just takes a little scrap of copy/paste code. Windows asks you what part of the window was clicked, you can respond with "it is transparent". So it will keep looking for anybody that is interested, its parent window is next.

像这样:

    protected override void WndProc(ref Message m) {
        const int WM_NCHITTEST = 0x84;
        const int HTTRANSPARENT = -1;
        if (m.Msg == WM_NCHITTEST) m.Result = new IntPtr(HTTRANSPARENT);
        else base.WndProc(ref m);
    }

这篇关于使 GDI 绘图不可点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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