How to allow click through on Transparent WinForm OpenGL overlay

0

I'm trying to create an OpenGL Overlay window (using C# and OpenTK). I've managed to get the transparency working using DWM BlurBehind with an invalid region> I then set the owner of the form to another process so it only overlays over the top of that. This is working great, but I can not figure out a way to allow clickthrough of the Window.

I've tired overriding WndProc to some success, as I'm now able to type into the window below (I'm using Notepad as the owner in this case just for testing), but I can't click it, and the cusor doesn't change based on which part of Notepad it's over. Intrestingly enough if I press the alt key, a menu item in Notepad highlights which I can click and select stuff from the menu.

This is my attempt at overriding WndProc

        protected override void WndProc(ref Message m)
        {
            const UInt32 WM_MOUSEACTIVATE = 0x0021;
            const UInt32 WM_LBUTTONDOWN = 0x0201;
            const UInt32 WM_KEYDOWN = 0x0100;
            const UInt32 WM_KEYUP = 0x0101;
            const UInt32 WM_ACTIVATE = 0x06;
            const UInt32 WM_ACTIVATEAPP = 0x1C;
            const UInt32 WM_NCHITTEST = 0x84;
            const UInt32 WM_SETFOCUS = 0x07;
            const UInt32 WM_NCLBUTTONDOWN = 0xA1;
            const UInt32 WM_NCLBUTTONUP = 0xA2;

            if (m.Msg == WM_LBUTTONDOWN || m.Msg == WM_MOUSEACTIVATE || m.Msg == WM_KEYDOWN || m.Msg == WM_KEYUP || m.Msg == WM_ACTIVATE
                || m.Msg == WM_ACTIVATEAPP || m.Msg == WM_NCHITTEST || m.Msg == WM_SETFOCUS || m.Msg == WM_NCLBUTTONDOWN || m.Msg == WM_NCLBUTTONUP)
            {
                Console.WriteLine("activate" + m.Msg.ToString());
                NativeMethods.PostMessage(notepadHandle, (uint)m.Msg, m.WParam, m.LParam);
                SetForegroundWindow(notepadHandle);
                return;
            }
            else
            {
                base.WndProc(ref m);
            }
        }

These are the parameters I use for the form.

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

                const int WS_EX_NOACTIVATE = 0x08000000;
                const int WS_EX_TOOLWINDOW = 0x00000080;
                const int WS_POPUP = unchecked((int)0x80000000);
                const int WS_BORDER = 0x00800000;

                baseParams.Style |= WS_POPUP | WS_BORDER;
                baseParams.ExStyle |= (int)(WS_EX_NOACTIVATE | WS_EX_TOOLWINDOW);

                return baseParams;
            }
        }
c#
winforms
winapi
opengl
dwm
asked on Stack Overflow Aug 27, 2019 by jdm555 • edited Aug 27, 2019 by jdm555

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0