manipulating taskbar applications w/o mouse?

Help
2008-04-17
2013-05-28
  • quitbuggingme
    quitbuggingme
    2008-04-17

    I am using the following code to activate windows via the taskbar:

    def activateTaskbarWindow(index): # this starts counting at 1
        index=int(index) # ensure integer not string
        numTrayApps=taskbar.RunningApplications.ButtonCount()
        # there are exactly twice as many windows for some reason
        bc=[taskbar.RunningApplications.GetButtonRect(i) for i inrange(numTrayApps)]
        r = bc[2*(index-1)+1] # get rectangle of desired window
        # activate foreground window with a click
        taskbar.RunningApplications.ClickInput(coords=(r.left+2,r.top+2))
        hwnd=win32gui.GetForegroundWindow()
        return hwnd

    As you can see, I'm using the mouse to click on the taskbar with the
    ClickInput above.

    Is there an alternative method that does not use the mouse?

    Thanks in advance.

     
    • Mark Mc Mahon
      Mark Mc Mahon
      2008-04-17

      Hi,

      The taskbar module is really experimental - and I think this is one of the first questions about it :)

      tb.RunningApplication.Button(i).Click() - doesn't use ClickInput()

      RunningApplications is a toolbar control - and I don't understand toolbar controls very well either.

      If you print the "Texts()" for tb.RunningApplications - you can see that there are two texts for each button. Clicking one of them highlights the button but doesn't necessarily make the application pop to the front (though it could be because I am using cmd line rather than a script.

      There may be some Notification message I need to send to the Toolbar (or it's parent) to make it more like a real click.

      Thanks
        Mark

       
      • quitbuggingme
        quitbuggingme
        2008-04-18

        thanks for your reply.

        Is there a more direct way to get the handle for an application on the taskbar?

        I'm trying to sort, restore, and close these applications.

        Thanks.

         
        • Mark Mc Mahon
          Mark Mc Mahon
          2008-04-18

          Hi,

          It might be much easier to just get the top level windows and then ignore the two special ones with classes "Progman" and "Shell_TrayWnd".

          e.g.

          from pywinauto.findwindows import find_windows
          from pywinauto.handleprops import classname

          # get the handles and filter out the pseudo top level windows
          all_top_level =  [hwnd in find_windows() if classname(hwnd) not in ("Progman","Shell_TrayWnd")]

          # Convert these handles to HwndWrappers (if you want to do this - up to you :) )
          from pywinauto.controls.HwndWrapper import HwndWrapper
          wrapped_handles = [HwndWrapper(hwnd) for hwnd in all_top_level]

          wrapped_handles[0].Restore()
          wrapped_handles[0].SetFocus()
          wrapped_handles[0].Maximize()
          wrapped_handles[0].Minimize()
          # etc

          Thanks
            Mark