Sign in to follow this  
Followers 0
tinu

Get Menu Handle of a Pop-Up Menu

5 posts in this topic

#1 ·  Posted (edited)

Hi All

Using the Auto3Lib (great stuff!!) to execute a right-mouse click in the systray and click on a series of menu items.

I can't post in the Auto3Lib topic since it is a sticky item therefore my post in the General Help.

One menu item of that pop-up menu has a menu-sub-branch.

The menu items in that sub-branch are loaded dynamically so I never really know for sure which menu is available and in which position it is going to be.

Therefore I wanted to count through the menu-items in the menu-sub-branch read the menu title and decided if it is the menu I was looking for.

Any hints on how to do this?

Thanks a lot.

Tinu

Edited by tinu

Share this post


Link to post
Share on other sites



Hi All

Using the Auto3Lib (great stuff!!) to execute a right-mouse click in the systray and click on a series of menu items.

I can't post in the Auto3Lib topic since it is a sticky item therefore my post in the General Help.

One menu item of that pop-up menu has a menu-sub-branch.

The menu items in that sub-branch are loaded dynamically so I never really know for sure which menu is available and in which position it is going to be.

Therefore I wanted to count through the menu-items in the menu-sub-branch read the menu title and decided if it is the menu I was looking for.

Any hints on how to do this?

Thanks a lot.

Tinu

Once the pop up is displayed, use _Lib_PopupGetHwnd to get the handle of the pop menu. You can then pass this handle to any of the functions in A3LMenu.au3 (like reading the text, opening sub menus, etc.). If you look at the code for _Menu_ClickPopUp, you'll see this is what it does.

Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites

Thanks for you quick reply. I got the _Lib_PopupGetHwnd() Function working.

You might be able to help me further since I try to open up a sub-menu. (See attached Bitmap).

I've added the code I've created to click on two menu items before I need to click on one certain 'MyConnection ...' menu item.

My problem is: How to I get the Sub-Menu listing?

Thanks for your help!!

Tinu

CODE

; Loop through the SysTray to retrieve the "NetScreen-Remote" handle

;-------------------------------------------------------------------

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

$iCount = _Toolbar_ButtonCount($hWnd)

For $iI = 1 to $iCount

$iCommand = _Toolbar_IndexToCommand($hWnd, $iI)

if _Toolbar_GetButtonText ($hWnd, $iCommand) = "NetScreen-Remote" Then

;Open the Pop-Up Menu of the icon and retrieve the menu handle

_Toolbar_ClickButton($hWnd, $iCommand, "right")

$hMenu = _Lib_PopupGetHwnd()

;Click on the menu 'Disconnect All'

if ClickMyMenu($hMenu, "Disconnect &All") Then

;Open the PopUp Menu again if the menu has been found

_Toolbar_ClickButton($hWnd, $iCommand, "right")

$hMenu = _Lib_PopupGetHwnd()

EndIf

;Click on the menu 'Reload Security Policy'

if ClickMyMenu($hMenu, "R&eload Security Policy") Then

;Open the PopUp Menu again if the menu has been found

_Toolbar_ClickButton($hWnd, $iCommand, "right")

$hMenu = _Lib_PopupGetHwnd()

EndIf

;Click on the menu 'Connect'

if ClickMyMenu($hMenu, "&Connect") Then

_Toolbar_ClickButton($hWnd, $iCommand, "right")

$hMenu = _Lib_PopupGetHwnd()

EndIf

EndIf

Next

Func ClickMyMenu($hMenu, $MenuTextToClick)

dim $iCount

dim $Clicked = False

$iCount = _Menu_GetItemCount($hMenu)

For $i = 0 to $iCount Step 1

$MenuText = _Menu_GetItemText($hMenu, $i)

if $MenuText = $MenuTextToClick Then

_Menu_ClickPopup($i)

$Clicked = true

ExitLoop

EndIf

Next

return $Clicked

EndFunc

post-22515-1177482201_thumb.jpg

Share this post


Link to post
Share on other sites

Thanks for you quick reply. I got the _Lib_PopupGetHwnd() Function working.

You might be able to help me further since I try to open up a sub-menu. (See attached Bitmap).

I've added the code I've created to click on two menu items before I need to click on one certain 'MyConnection ...' menu item.

My problem is: How to I get the Sub-Menu listing?

Thanks for your help!!

Tinu

CODE

; Loop through the SysTray to retrieve the "NetScreen-Remote" handle

;-------------------------------------------------------------------

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

$iCount = _Toolbar_ButtonCount($hWnd)

For $iI = 1 to $iCount

$iCommand = _Toolbar_IndexToCommand($hWnd, $iI)

if _Toolbar_GetButtonText ($hWnd, $iCommand) = "NetScreen-Remote" Then

;Open the Pop-Up Menu of the icon and retrieve the menu handle

_Toolbar_ClickButton($hWnd, $iCommand, "right")

$hMenu = _Lib_PopupGetHwnd()

;Click on the menu 'Disconnect All'

if ClickMyMenu($hMenu, "Disconnect &All") Then

;Open the PopUp Menu again if the menu has been found

_Toolbar_ClickButton($hWnd, $iCommand, "right")

$hMenu = _Lib_PopupGetHwnd()

EndIf

;Click on the menu 'Reload Security Policy'

if ClickMyMenu($hMenu, "R&eload Security Policy") Then

;Open the PopUp Menu again if the menu has been found

_Toolbar_ClickButton($hWnd, $iCommand, "right")

$hMenu = _Lib_PopupGetHwnd()

EndIf

;Click on the menu 'Connect'

if ClickMyMenu($hMenu, "&Connect") Then

_Toolbar_ClickButton($hWnd, $iCommand, "right")

$hMenu = _Lib_PopupGetHwnd()

EndIf

EndIf

Next

Func ClickMyMenu($hMenu, $MenuTextToClick)

dim $iCount

dim $Clicked = False

$iCount = _Menu_GetItemCount($hMenu)

For $i = 0 to $iCount Step 1

$MenuText = _Menu_GetItemText($hMenu, $i)

if $MenuText = $MenuTextToClick Then

_Menu_ClickPopup($i)

$Clicked = true

ExitLoop

EndIf

Next

return $Clicked

EndFunc

Menus and sub menus are created dynamically. You can't get a listing until they are created (visible). Just click the submenu item and then, when the sub menu appears, get the new pop up handle the way you did before. Also, you might want to consider using _Menu_ClickPopupAccel as it allows you to click using the accelerator key of the menu item instead of having to loop through the text.

Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites

Can anything like this be accomplished with any of the functions ported from Auto3Lib? The OP's issue is pretty much what I am experiencing now, but after poring through the help file and the Include sources, I've come up empty handed.

I have an application that sits in the system tray, that when right-clicked opens a popup menu with a handful of options. I was hoping there was a way to read the text of each item, then activate whichever one matches certain criteria. I am able to use the 'Control' functions to grab its handle, and show/hide/move it based on its class name (WindowsForms10.window.20808.app.0.33c0d9d), but I haven't had much luck doing anything else with it.

Thank you for any advice.

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  
Followers 0