Search code examples
c++windowswinapitaskbar

check current application clicked in taskbar? (C++, Windows API)


I've spent many hours on google and haven't found any relevent results on this particular subject.

I have an application I am wanting to be minimized when the user clicks on it in the taskbar (if it's not already minimized). The problem seems to be related to the fact the window is borderless. When I set it to have a border, it minimizes just fine when clicking it in the taskbar, without any code intervention. But I need the window borderless because I'm making a "custom border" using the client area.

tl;dr how do I check if the current application is being clicked in the taskbar?

Many thanks! Samuel


Solution

  • There is no need to tinker with the taskbar.

    Just make sure you have the WS_MINIMIZEBOX|WS_MAXIMIZEBOX styles set for your window. Otherwise your window won't handle WM_SYSCOMMAND with a wParam of SC_MINIMIZE and SC_RESTORE.

    Some resource editors like the one in Visual Studio make it impossible to set WS_MINIMIZEBOX|WS_MAXIMIZEBOX when you remove the standard window border. You may programmatically add the styles back like this:

    DWORD style = GetWindowLong( hwnd, GWL_STYLE ); 
    SetWindowLong( hwnd, GWL_STYLE, style | WS_MINIMIZEBOX | WS_MAXIMIZEBOX );