Search code examples
cwinapimingw32

How do I disable the 'Close Window' option in the taskbar?


How to write a C Code in order to disable the 'Close Window' option in the taskbar?

Compiler: GCC-mingw32

Which API Function should I use?

Thanks.


Solution

  • Make the window's message dispatcher process the message WM_SYSCOMMAND and filter it out if the message's wParam is SC_CLOSE.

    Let WndProc be the windows message handler then the code to do might look like this:

    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
      ...
    
      switch (message)
      {
        case WM_SYSCOMMAND:
         if (wParam == SC_CLOSE);
           break;
    
         return DefWindowProc(hWnd, message, wParam, lParam);  
    
        case ...
    
      }
    
      return 0;
    }
    

    This does not remove the "close"-menu item from the application's jump-list (its taskbar's local menu), but disables its functionality.