rover Posted October 13, 2008 Share Posted October 13, 2008 Enumerate tray icon menu items A rough update of one of PaulIAs example scripts included with the old Auto3Lib add on library. right click on tray icons to read menus, example launches status window of Local Area Connection tray icon when tray icon right clicked on Note: not yet setup for menu subitems properly. when I get around to it... expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <WindowsConstants.au3> #include <GuiMenu.au3> #include <WinAPI.au3> #Include <Misc.au3> _Singleton("TrayMenuTest", 0) Opt("MustDeclareVars", 1) HotKeySet("{ESC}", "_Exit") Global $gaPopups[1][3] = [[0, 0]] Global $hMenu, $hParent ConsoleWrite("!ESC key exits" & @CRLF) ConsoleWrite("!Right click tray icon menu" & @CRLF) While 1 Sleep(100) _Lib_PopupScan() If $gaPopups[0][0] > 0 Then Decode() EndIf WEnd Func _Exit() Exit EndFunc ;==>_Exit Func Decode() Local $iI, $iType Local $ahwnd[2] For $iI = 1 To $gaPopups[0][0] $ahwnd[0] = _Lib_PopupGetHwnd($iI) ; menu hwnd $iType = _Lib_PopupGetType($iI) ; menu/toolbar/tooltip $ahwnd[1] = _Lib_PopupGetParent($iI) ; parent hwnd If $hMenu <> $ahwnd[0] Or $hParent <> $ahwnd[1] Then $hMenu = $ahwnd[0] $hParent = $ahwnd[1] If _GUICtrlMenu_IsMenu($hMenu) And IsHWnd($hParent) Then Select Case $iType = 1 ShowMenu($hMenu, $hParent) EndSelect EndIf EndIf Next Return $ahwnd EndFunc ;==>Decode ; =============================================================================== ; Show information about a menu item ; =============================================================================== Func ShowMenu($hMenu, $hParent) Local $iI, $iCount, $sItem, $aRect, $sString, $sAccel $iCount = _GUICtrlMenu_GetItemCount($hMenu) ConsoleWrite("+Parent handle .........: " & $hParent & @CRLF) ConsoleWrite("+Menu handle ...........: " & $hMenu & @CRLF) ConsoleWrite("+Menu item count .......: " & $iCount & @CRLF) ConsoleWrite(@CRLF) For $iI = 0 To $iCount - 1 If $iI < 10 Then $sItem = "-Item " & $iI & " " Else $sItem = "-Item " & $iI & " " EndIf $aRect = _GUICtrlMenu_GetItemRect($hParent, $hMenu, $iI) If _GUICtrlMenu_GetItemType($hMenu, $iI, True) = $MFT_SEPARATOR Then ; determine if index item is menu separator $sString = "Separator" Else $sString = _GUICtrlMenu_GetItemText($hMenu, $iI) EndIf ; find accelerator keys $sAccel = StringInStr($sString, "&") If $sAccel Then $sAccel = StringMid($sString, $sAccel +1, 1) Else $sAccel = "" EndIf ; Local Area Connection - network tray icon, launches status window - change to your preferred tray menu item If $sString == "&Status" And $sAccel <> "" And Send($sAccel) Then Exit ConsoleWrite($sItem & "string ........: " & $sString & @CRLF) ConsoleWrite($sItem & "accelerator ...: " & $sAccel & @CRLF) ConsoleWrite($sItem & "command ID ....: " & _GUICtrlMenu_GetItemID($hMenu, $iI) & @CRLF) ConsoleWrite($sItem & "checked .......: " & _GUICtrlMenu_GetItemChecked($hMenu, $iI) & @CRLF) ConsoleWrite($sItem & "disabled ......: " & _GUICtrlMenu_GetItemDisabled($hMenu, $iI) & @CRLF) ConsoleWrite($sItem & "grayed ........: " & _GUICtrlMenu_GetItemGrayed($hMenu, $iI) & @CRLF) If IsArray($aRect) Then ConsoleWrite($sItem & "rectangle .....: [" & $aRect[0] & _ ", " & $aRect[1] & ", " & $aRect[2] & ", " & $aRect[3] & "]" & @CRLF) EndIf ConsoleWrite(@CRLF) Next EndFunc ;==>ShowMenu Func _Lib_PopupGetParent($iIndex = 1) _Lib_PopupWait() Return $gaPopups[$iIndex][2] EndFunc ;==>_Lib_PopupGetParent Func _Lib_PopupGetType($iIndex = 1) _Lib_PopupWait() Return $gaPopups[$iIndex][1] EndFunc ;==>_Lib_PopupGetType Func _Lib_PopupGetHwnd($iIndex = 1) _Lib_PopupWait() Return $gaPopups[$iIndex][0] EndFunc ;==>_Lib_PopupGetHwnd Func _Lib_PopupScan() Local $iI, $sClass, $hWnd, $hMenu ReDim $gaPopups[1][3] $gaPopups[0][0] = 0 ReDim $winapi_gaWinList[64][2] $winapi_gaWinList[0][0] = 0 $winapi_gaWinList[0][1] = 64 _WinAPI_EnumWindowsPopup() For $iI = 1 To $winapi_gaWinList[0][0] $hWnd = $winapi_gaWinList[$iI][0] $sClass = $winapi_gaWinList[$iI][1] Select Case $sClass = "#32768" $hMenu = _SendMessage($hWnd, $MN_GETHMENU, 0, 0) _Lib_PopupAdd($hMenu, 1, $hWnd) Case $sClass = "ToolbarWindow32" _Lib_PopupAdd($hWnd, 2, _WinAPI_GetParent($hWnd)) Case $sClass = "ToolTips_Class32" _Lib_PopupAdd($hWnd, 3, _WinAPI_GetParent($hWnd)) EndSelect Next EndFunc ;==>_Lib_PopupScan Func _Lib_PopupWait() Local $iLoop = 0 While $iLoop < 50 If $gaPopups[0][0] > 0 Then Return Sleep(100) _Lib_PopupScan() $iLoop += 1 WEnd ConsoleWrite("Timeout waiting for popup window to appear" & @CRLF) EndFunc ;==>_Lib_PopupWait Func _Lib_PopupAdd($hWnd, $iType, $hParent) Local $iCount $gaPopups[0][0] += 1 $iCount = $gaPopups[0][0] ReDim $gaPopups[$iCount + 1][3] $gaPopups[$iCount][0] = $hWnd $gaPopups[$iCount][1] = $iType $gaPopups[$iCount][2] = $hParent EndFunc ;==>_Lib_PopupAdd I see fascists... Link to comment Share on other sites More sharing options...
ptrex Posted October 14, 2008 Share Posted October 14, 2008 @rover Very nice !! Might come in handy sometime regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
rover Posted October 15, 2008 Author Share Posted October 15, 2008 @roverVery nice !! Might come in handy sometime regardsptrexThanks ptrex! I see fascists... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now