I have a main window in a process that is not owned by the program I'm creating. I'm using a Windows Hook
to inject a DLL into this process for the purpose of adding a child window to this main window.
My end goal was to create a WS_EX_LAYERED
window that allows me to create an internal colored border but allow the center portion to be transparent and allow mouse clicks through. This part works perfectly.
WNDCLASS wndClass = {};
wndClass.style = CS_HREDRAW | CS_VREDRAW;
wndClass.lpfnWndProc = OverlayProc;
wndClass.hInstance = g_TargetInstance;
wndClass.hbrBackground = (HBRUSH)CreateSolidBrush(RGB(0, 255, 255));
wndClass.lpszClassName = "OVERLAY";
RegisterClass(&wndClass);
g_Window = CreateWindowEx(WS_EX_LAYERED | WS_EX_TRANSPARENT, "OVERLAY", nullptr,
WS_CHILDWINDOW, rect.left, rect.top, rect.right+1, rect.bottom+1, data->hwnd, nullptr, g_TargetInstance, nullptr);
SetLayeredWindowAttributes(g_Window, RGB(0, 255, 255), 0, LWA_COLORKEY);
ShowWindow(g_Window, SW_SHOW);
UpdateWindow(g_Window);
The 2nd part to this is a I wanted to conditionally block all mouse input to the parent window. I couldn't do this with the transparent portion of the WS_EX_LAYERED
window so I tried creating a 2nd transparent STATIC
control as a child of the main window but this doesn't block mouse input either.
I'm also sending simulated mouse clicks to the parent window through calls to PostMessage
, passing WM_LBUTTONDOWN
and WM_LBUTTONUP
. How could I block all mouse input to the parent window via a transparent window?
PostMessage
" - That's not simulating input. It's faking it. And it's doing a damn poor job at it, too. – IInspectablesimulate
means. Simulating input is exactly the same thing as "faking" it. Also, I'm not nor did I say that I was "faking" keyboard input but to be clear, I do have a test function for "faking" keyboard input usingPostMessage
and in my case it works perfectly and reliably so saying it's a "damn poor job" is rather subjective. – vane