我正在使用一个最初是透明的窗口的应用程序,然后在按键(例如shift+tab
)上的窗口应该是 Not ClickThrough
。我用来获取ClickThrough
的代码如下:
_hwnd = CreateWindowEx(WS_EX_LAYERED | WS_EX_TRANSPARENT,
TEXT("Example"),
title, WS_BORDER,
GetSystemMetrics(SM_CXSCREEN) / 2 - _width / 2,
GetSystemMetrics(SM_CYSCREEN) / 2 - _height / 2,
_width, _height,
NULL, NULL,
NULL, NULL);
int opacity = 70;
SetLayeredWindowAttributes(_hwnd, 0, (255 * opacity) / 100, LWA_ALPHA);
现在,有什么解决办法可以不 ClickThrough
吗?我用谷歌搜索,但没有找到。
答案 0 :(得分:0)
是的,我通过注册 HotKeys 完成了此操作: WndProc 如下:
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
switch (message)
{
//break;
case WM_HOTKEY:
{
switch (wparam)
{
case 1:// Close Window
PostQuitMessage(0);
break;
case 2://Disable ClickThrough
SetWindowLong(hwnd, -20, WS_EX_LAYERED); //-16 for window style
break;
case 3://enable ClickThrough
SetWindowLong(hwnd, -20, WS_EX_LAYERED | WS_EX_TRANSPARENT);
break;
}
}
break;
case WM_CLOSE:
{
DestroyWindow(hwnd);
return 0;
}
break;
default:
return DefWindowProc(hwnd, message, wparam, lparam);
}
}
注册热键,如下所示:
RegisterHotKey(_hwnd, 1, MOD_SHIFT, 0x43); //shift + c
RegisterHotKey(_hwnd, 2, MOD_SHIFT, 0x44); //shift + d
RegisterHotKey(_hwnd, 3, MOD_SHIFT, 0x45); //shift + e