Jump to content
Sign in to follow this  
MisterBates

How to choose item from taskbar popup

Recommended Posts

MisterBates

Hi,

With PaulIA's sample volume control code (and excellent Auto3Lib), I can get a popup menu to appear for the Windows Live Messenger taskbar icon (and for others), but I don't know how, from there, to get info on the menu items, or how to "click" a menu item that doesn't have an assigned accelerator key.

Here's my code:

#include <A3LMenu.au3>
#include <A3LToolbar.au3>

Opt("WinTitleMatchMode", 4)
Opt("TrayIconHide", 1)

; Const $sWinTitle = "Jabber Messenger"
Const $sWinTitle = "Windows Live Messenger"

$hWnd   = ControlGetHandle("classname=Shell_TrayWnd", "", "Notification Area")
$iCount = _Toolbar_ButtonCount($hWnd)

for $iI = 1 to $iCount
    $iCommand = _Toolbar_IndexToCommand($hWnd, $iI)
    $sText  = _Toolbar_GetButtonText ($hWnd, $iCommand)
    if StringInStr($sText, $sWinTitle) then
        $iMousePos = MouseGetPos()
        WinActivate($hWnd); Show the taskbar (if it's on auto-hide)
        _Lib_PopupScan(); Auto3Lib internal routine to find popup menus - find already existing popups
        ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $gaPopups = ' & $gaPopups[0][0] & @crlf & '>Error code: ' & @error & @crlf);### Debug Console
        _Toolbar_ClickButton($hWnd, $iCommand, "primary", True, 1, 0, True)
        sleep(200); popup window takes a litte time
        _Lib_PopupScan(); Auto3Lib internal routine to find popup menus - find any new popups
        ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $gaPopups = ' & $gaPopups[0][0] & @crlf & '>Error code: ' & @error & @crlf);### Debug Console

       ; HOW TO GET MENU ITEM TEXT - to determine which one to click?
        
        MouseMove($iMousePos[0], $iMousePos[1], 0)
    endif
next

At the point marked "HOW TO GET MENU ITEM TEXT", the Auto3Lib global variable $gaPopups has two new entries - on my PC, at positions 4 and 5 in the array. I think these correspond to the popup menu and the "status" submenu, but I have no clue where to go from here ... I can't get hold of window text, controls etc. for these two new windows.

What I'd like to be able to do is process the popup menus to find a specific menu item based on menu item text (the number of menu items and the text for each can change), then click a menu item to choose it or to open a submenu that would be processed/clicked in the same way as the main popup menu.

Any ideas?

MisterBates

Share this post


Link to post
Share on other sites
PaulIA

Hi,

With PaulIA's sample volume control code (and excellent Auto3Lib), I can get a popup menu to appear for the Windows Live Messenger taskbar icon (and for others), but I don't know how, from there, to get info on the menu items, or how to "click" a menu item that doesn't have an assigned accelerator key.

Here's my code:

#include <A3LMenu.au3>
#include <A3LToolbar.au3>

Opt("WinTitleMatchMode", 4)
Opt("TrayIconHide", 1)

; Const $sWinTitle = "Jabber Messenger"
Const $sWinTitle = "Windows Live Messenger"

$hWnd   = ControlGetHandle("classname=Shell_TrayWnd", "", "Notification Area")
$iCount = _Toolbar_ButtonCount($hWnd)

for $iI = 1 to $iCount
    $iCommand = _Toolbar_IndexToCommand($hWnd, $iI)
    $sText  = _Toolbar_GetButtonText ($hWnd, $iCommand)
    if StringInStr($sText, $sWinTitle) then
        $iMousePos = MouseGetPos()
        WinActivate($hWnd); Show the taskbar (if it's on auto-hide)
        _Lib_PopupScan(); Auto3Lib internal routine to find popup menus - find already existing popups
        ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $gaPopups = ' & $gaPopups[0][0] & @crlf & '>Error code: ' & @error & @crlf);### Debug Console
        _Toolbar_ClickButton($hWnd, $iCommand, "primary", True, 1, 0, True)
        sleep(200); popup window takes a litte time
        _Lib_PopupScan(); Auto3Lib internal routine to find popup menus - find any new popups
        ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $gaPopups = ' & $gaPopups[0][0] & @crlf & '>Error code: ' & @error & @crlf);### Debug Console

      ; HOW TO GET MENU ITEM TEXT - to determine which one to click?
        
        MouseMove($iMousePos[0], $iMousePos[1], 0)
    endif
next

At the point marked "HOW TO GET MENU ITEM TEXT", the Auto3Lib global variable $gaPopups has two new entries - on my PC, at positions 4 and 5 in the array. I think these correspond to the popup menu and the "status" submenu, but I have no clue where to go from here ... I can't get hold of window text, controls etc. for these two new windows.

What I'd like to be able to do is process the popup menus to find a specific menu item based on menu item text (the number of menu items and the text for each can change), then click a menu item to choose it or to open a submenu that would be processed/clicked in the same way as the main popup menu.

Any ideas?

MisterBates

There are a couple of ways you can do this:

1. If you just want to click on a menu item in the popup menu, use _Menu_ClickPopupAccel and pass the menu accelerator character or _Menu_ClickPopup and pass the zero based item in the popup menu.

2. If you actually want to read the popup menu item text, you first get the popup menu handle with _Lib_PopupGetHwnd(). Then, use the returned handle in any of the A3LMenu functions.

Check out the Auto3Lib help file for examples on usage of the above functions. If you're still having trouble, PM me and I'll see what I can do to help you out.


Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites
MisterBates

Hi,

Got it all working, and wanted to share the result. I can't yet post to "Example scripts" (not enough posts), so I'm posting it here (attached).

Couple of notes on the code:

  • I found that I had numerous popup menus, but only one with menu items - thus the looping in the code
  • Menus on my PC must be on some sort of delay (not tracked it down yet), so I needed a couple 600ms pauses
  • If a menu item has an accelerator, there will be a "&" in the menu text - I've not coded to ignore this
  • Some menu items are "owner draw" with no menu text - in this case, only option is to use menu item number
  • The $iTrace parameter was a late but useful addition - it enabled me to step-by-step track down problems
Here's how to call the Func to set your "Windows Live Messenger" status to busy ...

$bResult = ClickTaskbarMenuItem("Windows Live Messenger", "status", "busy")

All comments appreciated!

MisterBates

ScB_TrayIcons.au3

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×