Jump to content
Sign in to follow this  
jdelaney

Get Menu options from context menu on sys tray's buttons

Recommended Posts

jdelaney

I was able to find a bit of code to get the MenuBarInfo from the sys tray buttons (when opened through a right click), but I'm unable to pull any information except for the pos of the menu. Would someone verify what I'm doing wrong?

Run this script, open your sys tray, and right click on any button...

#include <GuiMenu.au3>
While 1
;If WinActive("[CLASS:Notepad]") Then ;Makes sure not any active ContextMenu is accepted
If WinExists("[CLASS:#32768]") Then ;Makes sure it is a ContextMenu.
  $SomeName = _GUICtrlMenu_GetMenuBarInfo(WinGetHandle("[CLASS:#32768]" ), 0, 0)
  MsgBox(64,"Information about the current ContextMenu",$SomeName[0]&" - X coordinate of the upper left corner of the rectangle"[email="&@CRLF"]&@CRLF[/email]& _
  $SomeName[1]&" - Y coordinate of the upper left corner of the rectangle"[email="&@CRLF"]&@CRLF[/email]& _
  $SomeName[2]&" - X coordinate of the lower right corner of the rectangle"[email="&@CRLF"]&@CRLF[/email]& _
  $SomeName[3]&" - Y coordinate of the lower right corner of the rectangle"[email="&@CRLF"]&@CRLF[/email]& _
  $SomeName[4]&" - Handle to the menu bar or popup menu"[email="&@CRLF"]&@CRLF[/email]& _
  $SomeName[5]&" - Handle to the submenu"[email="&@CRLF"]&@CRLF[/email]& _
  $SomeName[6]&" - True if the menu bar has focus, otherwise False"[email="&@CRLF"]&@CRLF[/email]& _
  $SomeName[7]&" - True if the menu item has focus, otherwise False"[email="&@CRLF"]&@CRLF[/email]& _
  _GUICtrlMenu_GetItemCount ( $SomeName[4])&" - Count of Items...used in For loop."   )
  For $iItemNumber  = 0 To _GUICtrlMenu_GetItemCount( $SomeName[4] ) - 1 Step 1
   $iItemID   =  _GUICtrlMenu_GetItemID  ( $SomeName[4], $iItemNumber, True )
   $sItemText   =  _GUICtrlMenu_GetItemText  ( $SomeName[4], $iItemID, False )
   msgbox ( 4096, "test", "CurrentItemNumber=[" & $iItemNumber & "] includes ItemID=[" & $iItemID & "] and text=[" & $sItemText & "]." )
  Next
EndIf
WEnd

I guess I should mention what I'm attempting to accomplish. I want to find, and then select, a given item. If I can find the item by it's text value, then I can take it from there, but the script above is unable to pull the text of the item.

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
jdelaney

Ugh, I'm able to get the text of others, but not the one I need. Not sure why I am able to view the text of some popups, and not others.

#include <GuiMenu.au3>
While 1
;If WinActive("[CLASS:Notepad]") Then ;Makes sure not any active ContextMenu is accepted
If WinExists("[CLASS:#32768]") Then ;Makes sure it is a ContextMenu.
  $SomeName = _GUICtrlMenu_GetMenuBarInfo(WinGetHandle("[CLASS:#32768]" ), 0, 0)
  $iCount = 0
  Local $asTest[1][2]
  For $i = $SomeName[1]+9 To $SomeName[3] - 1 Step 25
   MouseMove ( $SomeName[0]+35, $i )
   Sleep (250)
   $stest   = _GUICtrlMenu_MenuItemFromPoint( 0, $SomeName[4], -1, -1 )
   $sItemText  = _GUICtrlMenu_GetItemText   ( $SomeName[4], $stest, True )
   ReDim $asTest[$iCount+1][2]
   $asTest[$iCount][0] = $stest
   $asTest[$iCount][1] = $sItemText
   $iCount = $iCount + 1
  Next
  _ArrayDisplay ( $asTest )
EndIf
WEnd

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
jdelaney

Last one, and I'm done :oops:.

This is all to work with MagicDisk. There is another way to "mount" an iso, through right clicking on the ISO...even in that menu, I'm not able to view the text of the item. I can see it all but the magic disc. At least I can find it by looking for the one with no text :/

Here is the full menu i can see:

[0]|0|&Open

[1]|2|Scan for &viruses

[2]|4|Edit with &Notepad++

[3]|5|

[4]|7|S&hare with

[5]|8|Scan with Malwarebytes' Anti-Malware

[6]|9|Restore previous &versions

[7]|11|Se&nd to

[8]|13|Cu&t

[9]|14|&Copy

[10]|16|Create &shortcut

[11]|17|&Delete

[12]|18|Rena&me

[13]|20|P&roperties

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
Melba23

jdelaney,

I have had mixed success with getting the text from tray menus - many of them seem to be user-drawn and so cannot be examined using the _GUICtrlMenu_GetItemText function. Does the "MagicDisk" item have a pretty graphic by chance? I have often found that to be a good indicator. I posted some code here which showed whether the items are indeed user drawn - but alas not how to then read them. :oops:

However, I have found that these menus often respond to "Accelerator" keypresses - have you tried that? It looks as if the other items on the menu are, so perhaps the "MagicDisk"item is too - "M" and "D" seem like obvious choices for experimentation! :bye:

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  

×