Sign in to follow this  
Followers 0
cwood

Menu names change at random?

13 posts in this topic

#1 ·  Posted (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 B) 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 by cwood

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

cwood,

Post your code using autoit tags..

kylomas

Edited 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

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by cwood

Share this post


Link to post
Share on other sites

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>

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Did you try using the GuiMenu.au3 UDF?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#8 ·  Posted (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). :)

M23

Edit: Added the GUI bit for clarity. Thanks Malkey. ;)

Edited 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._______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

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)

Share this post


Link to post
Share on other sites

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._______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

#11 ·  Posted (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,

-Chris

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.

Edited by cwood

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
Share on other sites

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.

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