-2

I am working on an application in which a window is transparent initially,then on a key press (say shift+tab) window should be Not ClickThrough. Code which I use to get ClickThrough is as follow:

_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); 

Now, any solution to get Not ClickThrough? I google it but never find any one.

Student
  • 805
  • 1
  • 8
  • 11
Ahmad Raza
  • 1,923
  • 2
  • 14
  • 19
  • Waht are you calling "Not ClickThrough"? – jaudo Jul 23 '18 at 14:11
  • Is it C, or C++? – Thomas Jager Jul 23 '18 at 14:12
  • 1
    C or C++ does not matter here – jaudo Jul 23 '18 at 14:13
  • 1
    Hmm, that is not a transparent window. There is already a decent alternative for a window that is transparent, click-through and can't be focused by clicking: don't create it. Use RegisterHotKey() to recognize the keystroke. – Hans Passant Jul 23 '18 at 14:21
  • Is it possible to get focus to the window or not .. ? – Ahmad Raza Jul 23 '18 at 16:40
  • Focus is controlled per thread. But that doesn't buy you much. You're probably interested in foreground activation instead. [Foreground activation permission is like love: You can’t steal it, it has to be given to you](https://blogs.msdn.microsoft.com/oldnewthing/20090220-00/?p=19083). If you registered a hotkey, then [Pressing a registered hotkey gives you the foreground activation love](https://blogs.msdn.microsoft.com/oldnewthing/20090226-00/?p=19013), but we don't know any of that. – IInspectable Jul 23 '18 at 20:18
  • it was possible . – Ahmad Raza Jul 24 '18 at 06:00

1 Answers1

0

Yes I have done this using registering HotKeys: WndProc is as follows:

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);
    }


}

Register HotKeys as follows:

RegisterHotKey(_hwnd, 1, MOD_SHIFT, 0x43); //shift + c
RegisterHotKey(_hwnd, 2, MOD_SHIFT, 0x44); //shift + d
RegisterHotKey(_hwnd, 3, MOD_SHIFT, 0x45); //shift + e
Ahmad Raza
  • 1,923
  • 2
  • 14
  • 19