cwood Posted December 23, 2011 Share Posted December 23, 2011 (edited) I'm a new user, but I was able to pick this up and run with it. Seems powerful and well-written to me! The issue that I'm having when calling menu items is that sometimes they work, and sometimes they absolutely don't, and it seems to be completely random. For example, one menu is "Analysis" with the A underlined. I have tried using both "&Analysis" and "Analysis" with WinMenuSelectItem, one right after the other. Many times neither one will be successful, but many other times it works no problem. I noticed that pressing the Alt key with the main application window in focus causes the underlined letter to appear and disappear, so I assumed that that this was causing the issue and used both names above as a fix. As a potential workaround, I went looking for a function that could a) call menu items by number, or read the name of the menu/item so that I can check and apply the correct string every time. As far as I can tell, neither of these features exists. It's possible that there's some non-printing character or something that appears sometimes but not others, but I don't know how to find out what that might be. The most I can figure out how to do is determine whether WinMenuSelectItem was successful or not. So I'm stumped. The AutoIt Window Info doesn't help, either, as it can't seem to get any information about menus. This is in Win XP, with an older application, so I have no reason to believe that the menus are any specific kind of fancy. Any ideas? Thanks, -Chris Edited December 23, 2011 by cwood Link to comment Share on other sites More sharing options...
kylomas Posted December 23, 2011 Share Posted December 23, 2011 (edited) cwood, Post your code using autoit tags.. kylomas Edited December 23, 2011 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
cwood Posted December 23, 2011 Author Share Posted December 23, 2011 (edited) The code is nothing fancy. This is what I ended up with while trying to debug it: WinActivate ( "rlogic") if WinMenuSelectItem ( "rlogic", "", "&Analysis", "Analyzer") = 1 Then Sleep(500) ElseIf WinMenuSelectItem ( "rlogic", "", "Analysis", "Analyzer") = 1 Then Sleep(500) Else MsgBox(0, "Error", "Analysis Menu Not Found") Exit EndIf I had a WinWaitActive in there as well, but took it out because it didn't seem to make a difference. I also had it report with a MsgBox when WinMenuSelectItem succeeded (instead of sleep(500)), but I took that out. Really scratching my head here. I'd like to add that I was not originally using the WinMenuSelectItem in this way, but found it convenient to use an If...Then statement to evaluate what was going on. Edited December 23, 2011 by cwood Link to comment Share on other sites More sharing options...
sleepydvdr Posted December 24, 2011 Share Posted December 24, 2011 I think the function you are looking for is ControlTreeView, with GetItemCount, GetText and IsChecked being the most useful information returned from it. #include <ByteMe.au3> Link to comment Share on other sites More sharing options...
cwood Posted December 24, 2011 Author Share Posted December 24, 2011 I think the function you are looking for is ControlTreeView, with GetItemCount, GetText and IsChecked being the most useful information returned from it.I don't think there's any way to treat menus that way -- at least no published way that I can see.If that's something that would work, I also don't know how I would ever find the relevant class/instance/handle or other identifier. AutoIt Window Info just doesn't work on the menu. Link to comment Share on other sites More sharing options...
ChrisN Posted December 24, 2011 Share Posted December 24, 2011 Did you try using the GuiMenu.au3 UDF? Link to comment Share on other sites More sharing options...
cwood Posted December 24, 2011 Author Share Posted December 24, 2011 Did you try using the GuiMenu.au3 UDF?I thought that stuff (all of the _GUI... functions) are just for making your own GUI, not for interacting with GUI items that an existing application creates/uses. True?-Chris Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 24, 2011 Moderators Share Posted December 24, 2011 (edited) cwood,The native functions GUI* (those [without a leading underscore) only work on controls created with AutoIt's native functions. But the UDF _GUI* functions (those with a leading underscore) can work on controls in external apps - and usually on native controls as well (although you have to take care). M23Edit: Added the GUI bit for clarity. Thanks Malkey. Edited December 25, 2011 by Melba23 Clarity 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...
Malkey Posted December 25, 2011 Share Posted December 25, 2011 cwood, The native functions (those [without a leading underscore) only work on controls created with AutoIt's native functions. But the UDF functions (those with a leading underscore) can work on controls in external apps - and usually on native controls as well (although you have to take care). M23 @Melba23 I don't think that statement is entirely correct. Firstly, I know the Control group of functions like ControlGetPos(), work with the FireFox browser - a native function working on an external application. Secondly, the example for the WinMenuSelectItem() function in the help file is used on the NotePad menu. Maybe, cwood needs the WinWaitActive() function to have his script wait for the window (with the menu) to be active before trying to select an item in the menu. Malkey Opt("WinTitleMatchMode", -2) ; -2 = Match any case in-sensitive substring in the title. Local $sTitleWin = "[Class:Notepad]" Run("notepad.exe") WinActivate($sTitleWin) Local $hWin = WinWaitActive($sTitleWin) If WinMenuSelectItem($hWin, "", "&File", "Page Set&up...") Then ;If WinMenuSelectItem("[CLASS:SciTEWindow]", "", "&File", "Page Set&up...") Then ; SciTE menu > &File > Page Set&up... wndow MsgBox(0, "Found", "&File>Page Set&up...") Else MsgBox(0, "Error", "&File Menu Not Found") Exit EndIf WinClose($hWin) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 25, 2011 Moderators Share Posted December 25, 2011 Malkey,You are quite correct - I was referring to the GUI*/_GUI* functions only. I have amended the post to make that clear.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...
cwood Posted December 27, 2011 Author Share Posted December 27, 2011 (edited) Secondly, the example for the WinMenuSelectItem() function in the help file is used on the NotePad menu.Maybe, cwood needs the WinWaitActive() function to have his script wait for the window (with the menu) to be active before trying to select an item in the menu.I wasn't concerned about the window itself changing its name, but the menus or menu items. Your code example is useful to see because I didn't know how to accomplish that if I had to, but it doesn't address the (perceived? possible?) problem.Also, I did use WinWaitActive in the past and it had no additional effect (so I took it out). As far as I can tell, the problem is not related to the window not being in focus.Any other ideas? Code snippet for finding a menu by menu # and item # instead of by name?Thanks,-ChrisEDIT: I tried an adaptation of your code snippet with the "Class:Notepad" replaced with my app, etc. Same result. It actually seems to be more of a problem when the app has been opened recently _AND_ I have not manually selected the menu options in question. Once I select them, it seems to work (or at least this looks like a pattern at the moment). Weird, huh. Edited December 27, 2011 by cwood Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted December 28, 2011 Share Posted December 28, 2011 EDIT: I tried an adaptation of your code snippet with the "Class:Notepad" replaced with my app, etc. Same result. It actually seems to be more of a problem when the app has been opened recently _AND_ I have not manually selected the menu options in question. Once I select them, it seems to work (or at least this looks like a pattern at the moment). Weird, huh.That reminds me of (<- link) old thread. Never found an explanation for this weirdness... .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
cwood Posted December 29, 2011 Author Share Posted December 29, 2011 That reminds me of (<- link) old thread. Never found an explanation for this weirdness...It does sound like that. Kind of a dead-end, isn't it? I'm really not sure where to go from here. 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