Search code examples
pythonwindowswinapipywin32

windows: disable maximize window on double-click title bar, and minimize on clicking task bar


I want to make a window in an application that is not mine (i.e. I don't have the source code) not closable or resizable (sounds annoying, but it's at the request of the users...) Anyway, I've managed to almost accomplish that fully with this code:

def set_window_style(hwnd, resizable=None, sysmenu=None):
    style = win32api.GetWindowLong(hwnd, win32con.GWL_STYLE)
    if resizable is not None:
        if resizable:
            style &= win32con.WS_SIZEBOX
        else:
            style &= ~win32con.WS_SIZEBOX
    if sysmenu is not None:
        if sysmenu:
            style &= win32con.WS_SYSMENU
        else:
            style &= ~win32con.WS_SYSMENU
    win32api.SetWindowLong(hwnd, win32con.GWL_STYLE, style)

giving False to both params means they can't drag to resize it or hit maximize or the 'x' button, as they're not there. However, if one double-clicks on the title bar, the window is still maximized. Is there a way to disable this behavior?

Furthermore, if I click on the window in the task bar, it minimizes and is restored. Can I disable this, too?


Solution

  • Also remove the WS_MINIMIZEBOX and WS_MAXIMIZEBOX styles.