dushkin Posted July 8, 2013 Share Posted July 8, 2013 (edited) Hi, Following my question >here, how do I select a menu item according to its text? I tried the following (please see also comments embedded): If WinExists("[CLASS:#32768") Then $hWnd = WinGetHandle("[CLASS:#32768") ;ContextMenu $hMenu = _SendMessage($hWnd, $MN_GETHMENU, 0, 0) If _GUICtrlMenu_IsMenu($hMenu) Then ConsoleWrite("$menuItemText = " & $menuItemText & @CRLF) ;That is the text I am searching in the menu.. $menuItemsCount = _GUICtrlMenu_GetItemCount($hMenu) ConsoleWrite("$menuItemsCount = " & $menuItemsCount & @CRLF) For $i = 0 To $menuItemsCount - 1 ;By the way I tried with FindItem and failed.. $itemText = _GUICtrlMenu_GetItemText($hMenu, $i) ConsoleWrite("$itemText = " & $itemText & @CRLF) If $itemText = $menuItemText Then Sleep(1000) ConsoleWrite("{ENTER}") Send("{ENTER}") ;Well, this wouldn't work of course because I didn't select an item. I think I could use here something like "selectItem (text) " before the "ENTER" Return True EndIf Next ConsoleWrite("Didn't find " & $menuItemText & " in menu" & @CRLF) Return False EndIf EndIf Thanks! Edited July 8, 2013 by Melba23 Added tags Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 8, 2013 Moderators Share Posted July 8, 2013 dushkin,The only way I can get it to fire is like this:#include <WindowsConstants.au3> #include "SendMessage.au3" #Include <GuiMenu.au3> Global $sRequired_Text = "Select All" While 1 If WinExists("[CLASS:#32768]") Then $hWnd = WinGetHandle("[CLASS:#32768]") $hMenu = _SendMessage($hWnd, $MN_GETHMENU, 0, 0) If _GUICtrlMenu_IsMenu($hMenu) Then $iCount = _GUICtrlMenu_GetItemCount($hMenu) For $iIndex = 0 To $iCount - 1 Local $sText = _GUICtrlMenu_GetItemText($hMenu, $iIndex) If $sText = $sRequired_Text Then $aPos = _GUICtrlMenu_GetItemRect($hWnd, $hMenu, $iIndex) $iOldOpt = Opt("MouseCoordMode", 0) MouseClick("primary", $aPos[0], $aPos[1], 1, 20) ; Adjust the speed to suit Opt("MouseCoordMode", $iOldOpt) EndIf Next EndIf EndIf Sleep(10) WEndBut there must be something more elegant. I will keep looking - or maybe someone else will put us both right! M23P.S. When you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
dushkin Posted July 9, 2013 Author Share Posted July 9, 2013 Thanks Mel. Well, your code really helped me, but I had to modify the Mosue click position. With your code, it try to click one item above the desired and left of it, meaning it didn't really clicked the Item. So I modified the line to MouseClick("primary", $aPos[0] + 100, $aPos[1] + 20, 1, 20) and then it was ok, but the question is if this is the correct way? (and it is not!) How to perorm this task without manualy modifying the position values? Thanks! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 9, 2013 Moderators Share Posted July 9, 2013 dushkin,I have no idea why it does not click in the correct place for you - as you can see I changed the MouseCoordMode mode to the current window, which should be the popup holding the context menu. It certainly worked for me when I tried it within SciTE. What you have done is the logical way to correct the position, but I am afraid I cannot explain why it is not moving to the right place automatically. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Iczer Posted July 9, 2013 Share Posted July 9, 2013 i think it should be: MouseClick("primary", $aPos[0] + ($aPos[2] - $aPos[0]) / 10, $aPos[1] + ($aPos[3] - $aPos[1]) / 2, 1, 20) 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