Jump to content

what to do when WinMenuSelectItem won't work


Recommended Posts

I'm new to AutoIt, and am very impressed.

I have the simple task of trying to auto click a dropdown menu in an app.

I can automate it with keyboard movement but this is not very reliable, as the position of the menu choice is not 100% stable.

WinMenuSelectItem would be ideal, but apparently , as the docs state, many apps use non standard menus, so this is not working for my purpose.

What is the accepted solution (beside mouse or keystroke movement) to moving the focus and clicking on a specific menu choice , when WinMenuSelectItem can't be used?

Link to comment
Share on other sites

Are you sure that the Menu isn't a standard menu? Does the menu item that you want to click have keyboard shortcuts? Does it have a control ID? What program is it that you are trying to automate? Can you provide a screenshot with the menu extended as you move your mouse over the various choices? Can you provide a script that partially does what you want?

Sorry, the solution is different based upon what program you are trying to automate and there isn't enough information provided for me to even guess a possible solution. We need more info. The more information you provide, the more likely a solution will be found by one of the community members.

- The Kandie Man ;-)

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

It looks like a standard menu, has hotkeys, but is not responding to WinMenuSelectItem when tried. Using the same code on Notepad does work, so I'm assuming a custom menu is being used.

Is there another way besides sending keystrokes to access a menu?

The program is QuoteTracker , a stock market charting application.

Link to comment
Share on other sites

Have you tried Auto3Lib from example section (it's a sticky)?

Have a look at the Folders.au3-example to get you going. :)

Thanks for the heads up, but frankly , I was trying to avoid wading through yet another massive array of information to do a pretty simple thing.

I guess this has never been done before ;-).

Link to comment
Share on other sites

Almost there.

#include <A3LMenu.au3>

WinActivate("Mergers","")

$hWnd=WinGetHandle("Mergers")

$sText="&Portfolio"

$hMenu=_Menu_GetMenu($hWnd)

_Menu_ClickItem($hWnd, $hMenu, 1)

Ok, now this gets me to the Parent menu, how do I now click on the child menu option that I need?

Link to comment
Share on other sites

Almost there.

#include <A3LMenu.au3>

WinActivate("Mergers","")

$hWnd=WinGetHandle("Mergers")

$hMenu=_Menu_GetMenu($hWnd)

_Menu_ClickItem($hWnd, $hMenu, 1)

Ok, now this gets me to the Parent menu, how do I now click on the child menu option that I need?

Edited by Jdop
Link to comment
Share on other sites

Almost there.

Ok, now this gets me to the Parent menu, how do I now click on the child menu option that I need?

A little demo:

#include <A3LMenu.au3>

Run("Notepad.exe")
_Lib_WinWaitActive ("Untitled - Notepad")
$hWnd = WinGetHandle("Untitled - Notepad")
$hMenu = _Menu_GetMenu ($hWnd)
If IsHWnd($hMenu) Then 
    If StringInStr(_Menu_GetItemText($hMenu, 0), "File") Then
        $hFileMenu = _Menu_GetItemSubMenu($hMenu, 0)
        $ItemCnt = _Menu_GetItemCount($hFileMenu)
        $Msg = "File menu items:" & @CRLF
        For $n = 0 To $ItemCnt - 1
            $Msg &= $n & " = " & _Menu_GetItemText($hFileMenu, $n) & @CRLF
        Next
        MsgBox(64, "Results", $Msg)
        
        If StringInStr(_Menu_GetItemText($hFileMenu, 1), "Open") Then
            _Menu_ClickItem($hWnd, $hMenu, 0)
            Sleep(1000)
            _Menu_ClickItem($hWnd, $hFileMenu, 1)
            Sleep(1000)
        Else
            MsgBox(16, "Error", "Item 1 was not 'Open'.")
        EndIf
    Else
        MsgBox(16, "Error", "Item 0 was not 'File'.")
    EndIf
Else
    MsgBox(16, "Error", "Menu handle not retrieved!")
EndIf

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thanks, very good example. I actually had figured it out but I was mistakenly outputting debugging info to a message box, in between clicks, which 'breaks' the sub menu click.

Thanks again.

Link to comment
Share on other sites

Thanks, very good example. I actually had figured it out but I was mistakenly outputting debugging info to a message box, in between clicks, which 'breaks' the sub menu click.

Thanks again.

You're welcome.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Im still having a problem, trying to do this correctly.

Your code sample works fine with Notepad.

In app Im trying to automate , _Menu_GetItemText does not work correctly, even though _Menu_GetItemCount, and _Menu_ClickItem do function as intended, using the same menu handles.

_Menu_GetItemText reads empty strings. I know this is a Windows API call, so I'm assuming the menu the program (QuoteTRacker) is using is one of the non standard ones. Strange that the other functions work though.

Is there some other way to attack reading in the sub menu text strings, so I can accurately determine what item to click.?

Link to comment
Share on other sites

Im still having a problem, trying to do this correctly.

Your code sample works fine with Notepad.

In app Im trying to automate , _Menu_GetItemText does not work correctly, even though _Menu_GetItemCount, and _Menu_ClickItem do function as intended, using the same menu handles.

_Menu_GetItemText reads empty strings. I know this is a Windows API call, so I'm assuming the menu the program (QuoteTRacker) is using is one of the non standard ones. Strange that the other functions work though.

Is there some other way to attack reading in the sub menu text strings, so I can accurately determine what item to click.?

If the menus are consistently placed, the text doesn't matter. Just use the index numbers. The only reason I used the text in my script was to be sure and get the right menu selection. If I assumed "File" and "Open" would never move or go missing, I wouldn't bother looking for the text and would hard-code the index numbers that point to them.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Im still having a problem, trying to do this correctly.

Your code sample works fine with Notepad.

In app Im trying to automate , _Menu_GetItemText does not work correctly, even though _Menu_GetItemCount, and _Menu_ClickItem do function as intended, using the same menu handles.

_Menu_GetItemText reads empty strings. I know this is a Windows API call, so I'm assuming the menu the program (QuoteTRacker) is using is one of the non standard ones. Strange that the other functions work though.

Is there some other way to attack reading in the sub menu text strings, so I can accurately determine what item to click.?

Maybe post your problem in Auto3Lib topic

Link to comment
Share on other sites

If the menus are consistently placed, the text doesn't matter. Just use the index numbers. The only reason I used the text in my script was to be sure and get the right menu selection. If I assumed "File" and "Open" would never move or go missing, I wouldn't bother looking for the text and would hard-code the index numbers that point to them.

:)

Of course, I tried that, and the items do appear consistently placed. However, the routine seems to fail on CERTAIN windows within the app using that direct method. I wanted to try a more 'intensive' approach, to see if I could make it work.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...