Modifying the system menu

Tim Golden mail at
Wed Sep 17 10:17:30 CEST 2008

raj.indian.08 at wrote:
> For (2) I wrote the following code for basic testing:
>     hwnd = win32gui.GetForegroundWindow()
>     hw = win32gui.GetSystemMenu(hwnd, False)
>     if hw != None:
>         win32gui.AppendMenu(hw,win32con.MF_SEPARATOR,0,'-');
> and it shows the following error: pywintypes.error: (1401,
> 'AppendMenu', 'Invalid menu handle.')

Works for me. The following adds a separator and the
string "Hello" to my (Console) window's system menu

import win32con
import win32gui

hwnd = win32gui.GetForegroundWindow ()
hmenu = win32gui.GetSystemMenu (hwnd, False)
win32gui.AppendMenu (hmenu, win32con.MF_SEPARATOR, 0, '')
win32gui.AppendMenu (hmenu, win32con.MF_STRING, 100, 'Hello')



More information about the Python-list mailing list