-2

我正在开发一个窗口最初是透明的应用程序,然后在按键上(比如说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); 

现在,有什么解决方案可以得到Not ClickThrough吗?我谷歌它,但从来没有找到任何一个。

4

1 回答 1

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
于 2018-07-24T06:03:56.493 回答