Modifying the system menu

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • raj.indian.08@gmail.com

    Modifying the system menu

    Hi all,
    I am trying to modify the system menu of all the applications in
    my machine.
    For example say - I am creating multiple desktops for windows -
    and I want to give every application the capability to be moved across
    different desktops. So I wanted to modify the basic system menu list
    to include the new options.

    The methods I could think of are -
    1. Modify the basic windows set of system menu values (best option)
    or
    2. Poll every few milliseconds and modify the system menu values of
    the active window

    For (1) I couldnt think of a way to do it. Is it even possible using
    python?

    For (2) I wrote the following code for basic testing:
    hwnd = win32gui.GetFor egroundWindow()
    hw = win32gui.GetSys temMenu(hwnd, False)
    if hw != None:
    win32gui.Append Menu(hw,win32co n.MF_SEPARATOR, 0,'-');

    and it shows the following error: pywintypes.erro r: (1401,
    'AppendMenu', 'Invalid menu handle.')

    If anyone could help me out in both the options (1) and/or (2), I
    would be very thankful.

    Thank you very much in advance,
    A python newbie
  • Tim Golden

    #2
    Re: Modifying the system menu

    raj.indian.08@g mail.com wrote:
    For (2) I wrote the following code for basic testing:
    hwnd = win32gui.GetFor egroundWindow()
    hw = win32gui.GetSys temMenu(hwnd, False)
    if hw != None:
    win32gui.Append Menu(hw,win32co n.MF_SEPARATOR, 0,'-');
    >
    and it shows the following error: pywintypes.erro r: (1401,
    'AppendMenu', 'Invalid menu handle.')

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

    <code>
    import win32con
    import win32gui

    hwnd = win32gui.GetFor egroundWindow ()
    hmenu = win32gui.GetSys temMenu (hwnd, False)
    win32gui.Append Menu (hmenu, win32con.MF_SEP ARATOR, 0, '')
    win32gui.Append Menu (hmenu, win32con.MF_STR ING, 100, 'Hello')

    </code>

    TJG

    Comment

    • raj.indian.08@gmail.com

      #3
      Re: Modifying the system menu

      I tested it again and found that the behaviour is a little different
      from what I mentioned previously in the mailchain.
      The item is working perfectly the first time around. Now if I close
      the application and run it again (which was what I did earlier), if
      that application system menu is already modified, it is causing this
      issue.

      Why would this happen? If it is that the file handle is not obtained,
      it wouldnt have gone through the following check at all?
      hw = win32gui.GetSys temMenu(hwnd, False)
      if hw != None:
      win32gui.Append Menu(hw,win32co n.MF_SEPARATOR, 0,'-');
      Not only did it go through, it failed with an invalid menu handle
      error.

      Comment

      • raj.indian.08@gmail.com

        #4
        Re: Modifying the system menu

        On Sep 18, 6:39 am, raj.indian...@g mail.com wrote:
        I tested it again and found that the behaviour is a little different
        from what I mentioned previously in the mailchain.
        The item is working perfectly the first time around. Now if I close
        the application and run it again (which was what I did earlier), if
        that application system menu is already modified, it is causing this
        issue.
        >
        Why would this happen? If it is that the file handle is not obtained,
        it wouldnt have gone through the following check at all?
        >
            hw = win32gui.GetSys temMenu(hwnd, False)
            if hw != None:
                win32gui.Append Menu(hw,win32co n.MF_SEPARATOR, 0,'-');
        >
        Not only did it go through, it failed with an invalid menu handle
        error.
        More worryingly, this happens randomly. Am I doing some mistake here?

        Comment

        • Lawrence D'Oliveiro

          #5
          Re: Modifying the system menu

          In message
          <bfa45e21-fb5e-454d-a4c2-e7cc00919f38@p3 1g2000prf.googl egroups.com>,
          raj.indian.08@g mail.com wrote:
          For example say - I am creating multiple desktops for windows -
          and I want to give every application the capability to be moved across
          different desktops.
          But doesn't the desktop environment/window manager that provides the
          multiple desktops also provide the relevant entries in the system menu?

          Comment

          Working...