Sign in to follow this  
Followers 0
Ibrahim

menu control problem

14 posts in this topic

how to deal with programs's menu items and choose one ,say i want to run a program hidden in the background like mspaint and choose some menu item from it regarding that these menu items have no shortcut keyboard keys thnx.

Share this post


Link to post
Share on other sites



sorry man not working and i read in the help that some menus are realy toolbars pretending to be menus and i guess my program is one of them and autoit window info tool doesnot give it any control id and don't recognize it even as a control hope u can help

Share this post


Link to post
Share on other sites

Are you sure your program doesn't have shortcut keys? In most programs, you can press Alt and the first letter of whatever menu it is, and the menu will be opened. Just use Send("!_") and in place of the _, put the first letter of the menu.

Share this post


Link to post
Share on other sites

yup i'm sure it doesn't

I'm affraid all you can do is Alt-TAB to that window and MouseClick the menu entries.

It is not an elegant solution and not one to be recommended but ... it is up to you. It depends on how bad do you want that or not.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

I think your out of luck with hidden windows.. hmm...

But, for an active window there is another way other than using WinMenuSelectItem

Try AutoLib3, Try the example below with MSpaint, it's menu has no controlID info, but it does have accelerator keys

Auto3Lib, A library of functions for AutoIt

Download Auto3Lib Installer

Navigating Menu issues

Wait for menu-item

Get Menu Handle of a Pop-Up Menu

Here's a modified code example from this post by PsaltyDS

what to do when WinMenuSelectItem won't work

;sometimes using the zero-based menu Index method works, In other parts of the menu it doesn't


#include <A3LLibrary.au3>
#include <A3LMenu.au3>

AutoItSetOption("WinTitleMatchMode", 4);4 = Advanced mode - allows HWNDS "Handles" in place of title text (Paint "Title" varies with open filename with this app)
                                            ;1 = Match the title from the start (default)
                                            ;2 = Match any substring in the title
                                            ;3 = Exact title match
                                            ;4 = Advanced mode

Run(@SystemDir & '\mspaint.exe', @WorkingDir)
WinWaitActive("[CLASS:MSPaintApp]", "",5)

Switch WinExists("[CLASS:MSPaintApp]", ""); WinExists will return 1 even if the window is hidden
    Case 1
         $winhandle = WinGetHandle("[CLASS:MSPaintApp]", "") ; use class, title name varies with open filename with this app
        ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $winhandle1 = ' & $winhandle & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
         If @error = 1 Or IsHWnd($winhandle) = 0 Then ContinueCase ; check if HWND returned in $winhandle
    Case 0
         AutoItSetOption("WinTitleMatchMode", 2)
         If WinExists("Paint", "") Then
            $winhandle = WinGetHandle("Paint", "") ; use title with partial string match WinTitleMatchMode 2
            ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $winhandle2 = ' & $winhandle & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
            If @error = 1 Or IsHWnd($winhandle) = 0 Then Exit ; check if HWND returned in $winhandle, exit if fail
         Else
            Exit
         EndIf
EndSwitch
 
AutoItSetOption("WinTitleMatchMode", 4) ; Return to WinTitleMatchMode 4, use HWNDS and Control iD's

$hMenu = _Menu_GetMenu($winhandle); Use AutoLib3 to get Paint Menu HWND
If IsHWnd($winhandle) = 0 Then Exit
    
$hFileMenu0 = _Menu_GetItemSubMenu($hMenu, 0); File Menu ControlID
$hFileMenu1 = _Menu_GetItemSubMenu($hMenu, 1); Edit Menu ControlID
$hFileMenu2 = _Menu_GetItemSubMenu($hMenu, 2); View Menu ControlID
$hFileMenu3 = _Menu_GetItemSubMenu($hMenu, 3); Image Menu ControlID
$hFileMenu4 = _Menu_GetItemSubMenu($hMenu, 4); Colors Menu ControlID
$hFileMenu5 = _Menu_GetItemSubMenu($hMenu, 5); Help Menu ControlID

;#comments-start ; Display Menu Item Index Numbers, NOTE: Separators Have Index numbers

        $ItemCnt = _Menu_GetItemCount($hFileMenu0) ; Menu Item Text/Index For File Menu ControlID
        $Msg = "File menu items:" & @CRLF
        For $n = 0 To $ItemCnt - 1
            $Msg &= $n & " = " & _Menu_GetItemText($hFileMenu0, $n) & @CRLF
        Next
        MsgBox(64, "Results", $Msg)

        $ItemCnt = _Menu_GetItemCount($hFileMenu1) ; Menu Item Text/Index For Edit Menu ControlID
        $Msg = "Edit menu items:" & @CRLF
        For $n = 0 To $ItemCnt - 1
            $Msg &= $n & " = " & _Menu_GetItemText($hFileMenu1, $n) & @CRLF
        Next
        MsgBox(64, "Results", $Msg)
        
        $ItemCnt = _Menu_GetItemCount($hFileMenu2) ; Menu Item Text/Index For View Menu ControlID
        $Msg = "View menu items:" & @CRLF
        For $n = 0 To $ItemCnt - 1
            $Msg &= $n & " = " & _Menu_GetItemText($hFileMenu2, $n) & @CRLF
        Next
        MsgBox(64, "Results", $Msg)
        
        $ItemCnt = _Menu_GetItemCount($hFileMenu3) ; Menu Item Text/Index For Image Menu ControlID
        $Msg = "Image menu items:" & @CRLF
        For $n = 0 To $ItemCnt - 1
            $Msg &= $n & " = " & _Menu_GetItemText($hFileMenu3, $n) & @CRLF
        Next
        MsgBox(64, "Results", $Msg)
        
        $ItemCnt = _Menu_GetItemCount($hFileMenu4) ; Menu Item Text/Index For Colors Menu ControlID
        $Msg = "Colors menu items:" & @CRLF
        For $n = 0 To $ItemCnt - 1
            $Msg &= $n & " = " & _Menu_GetItemText($hFileMenu4, $n) & @CRLF
        Next
        MsgBox(64, "Results", $Msg)

        $ItemCnt = _Menu_GetItemCount($hFileMenu5) ; Menu Item Text/Index For Help Menu ControlID
        $Msg = "Help menu items:" & @CRLF
        For $n = 0 To $ItemCnt - 1
            $Msg &= $n & " = " & _Menu_GetItemText($hFileMenu5, $n) & @CRLF
        Next
        MsgBox(64, "Results", $Msg)
        
;#comments-end


; 2 Menu Item Examples - Uncomment either one
; ControlID based commands won't work here.
; Menu has no ControlID when viewed with AutoIt Window Info Utility

#comments-start ; File Menu, Open Image Dialog 
            ControlFocus($winhandle, "", $hMenu)
            _Menu_ClickItem($winhandle, $hMenu, 0) ; Click on File Menu
            Sleep(1000)
            ControlFocus($winhandle, "", $hFileMenu0)
            _Menu_ClickAccel($winhandle, $hFileMenu0, "0") ; Click "Open" on File Menu, works with MSpaint, uses Accelerator key
            _Menu_ClickItem($winhandle, $hFileMenu0, 1) ; Click "Open" on File Menu, works with MSpaint
            Sleep(1000)
#comments-end

#comments-start ; Colors Menu, Edit Colors.. Item
            ControlFocus($winhandle, "", $hMenu)
            _Menu_ClickItem($winhandle, $hMenu, 4) ; Click on Colors Menu
            ControlFocus($winhandle, "", $hFileMenu4)
            ;Select "Edit Colors..."
            ;_Menu_ClickAccel($winhandle, $hFileMenu4, "E") ; Doesn't work here, but does in other parts of menu, uses Accelerator key
             ;_Menu_ClickItem($winhandle, $hFileMenu4, 0)   ; Doesn't work here, but does in other parts of menu
            Send("{E}")                                     ; Works with MSpaint, uses Accelerator key
#comments-end

I see fascists...

Share this post


Link to post
Share on other sites

returns an error in the libraray

@@ Debug(23) : $winhandle2 = 0x000A0586

>Error code: 0

d:\PROGRA~1\AutoIt3\Include\A3LMenu.au3 (1077) : ==> AutoIt has encountered a fatal crash as a result of:

Unable to execute DLLCall.:

DllCall("User32.dll", "int", "GetMenuString", "hwnd", $hMenu, "int", $iItem, "ptr", DllStructGetPtr($tBuffer), "int", 4096, "int", $iByPos)

Share this post


Link to post
Share on other sites

returns an error in the libraray

@@ Debug(23) : $winhandle2 = 0x000A0586

>Error code: 0

d:\PROGRA~1\AutoIt3\Include\A3LMenu.au3 (1077) : ==> AutoIt has encountered a fatal crash as a result of:

Unable to execute DLLCall.:

DllCall("User32.dll", "int", "GetMenuString", "hwnd", $hMenu, "int", $iItem, "ptr", DllStructGetPtr($tBuffer), "int", 4096, "int", $iByPos)

looks like conflict with older version of AutoLib3 maybe?

I'm using AutoIt3 v3.2.4.9 and AutoLib3 v4.10 - last version from author

v4.10 A3LMenu.au3 has this code for _Menu_GetItemText

; #FUNCTION# ====================================================================================================================
; Description ...: Retrieves the text of the specified menu item
; Parameters ....: $hMenu       - Handle of the menu
;                  $iItem       - Identifier or position of the menu item
;                  $fByPos      - Menu identifier flag:
;                  | True - $iItem is a zero based item position
;                  |False - $iItem is a menu item identifier
; Return values .: Success      - Menu item text
; Author ........: Paul Campbell (PaulIA)
; Remarks .......:
; Related .......: _Menu_SetItemText
; ===============================================================================================================================

Func _Menu_GetItemText($hMenu, $iItem, $fByPos=True)
  Local $iByPos, $aResult

  if $fByPos then $iByPos = $MF_BYPOSITION
  $aResult = DllCall("User32.dll", "int", "GetMenuString", "hwnd", $hMenu, "int", $iItem, "str", 0, "int", 4096, "int", $iByPos)

  Return $aResult[3]
EndFuncoÝ÷ Ù8b±Êy·¥£¬v§¢W^®÷«²*'¡ð7,ǧ¹«·~º&yªåÈƲÛM;ØZ²Ø^YR¶»´g­>Úí«l,|¨º·+jÈfzËæ§v+'¢Ø§¶§{«½êìè|­ ¸Ü(ºWgßÛkzèv維«!o+0×!x-+"ÉnuëayÊ{
+Çè®gÙhiÛ&²¢Ûazvëx,º¦²èÇl¡ø§uì^±ú+y§!éîצ#f¢ëh~lzaÂ+a¶¬ëÞíç(u觶¢Énuë-¯+azw°z°.¶âoybn¶«É«mébF¢÷¦k&Þ²¢wÇjw(g§¶í+ºÚ"µÍ[ÈÓY[WÑÙ]][U^
    ÌÍÚY[K   ÌÍÚR][K  ÌÍÙTÜÏUYJBØØ[    ÌÍÝY ÌÍÚPTÜÂY   ÌÍÙTÜÈ[    ÌÍÚPTÜÈH   ÌÍÓQÐTÔÒUSÓ  ÌÍÝYHÝXÝÜX]][ÝØÚ^ÍMI][ÝÊBØ[
    ][ÝÕÙÌ  ][ÝË  ][ÝÚ[ ][ÝË  ][ÝÑÙ]Y[[É][ÝË ][ÝÚÛ    ][ÝË  ÌÍÚY[K   ][ÝÚ[ ][ÝË  ÌÍÚR][][ÝÜ][ÝËÝXÝÙ]    ÌÍÝYK    ][ÝÚ[ ][ÝË
M   ][ÝÚ[ ][ÝË  ÌÍÚPTÜÊB]ÝXÝÙ]]J    ÌÍÝY ][ÝÕ^ ][ÝÊB[[

I see fascists...

Share this post


Link to post
Share on other sites

thank you man for your help . . . . .thanks alot

no problem..

I can't edit my posts until they exceed 10 I think, so I'll add my correction here.

posted the above code at 4am and it shows, I cut "n" pasted/coded in some errors.

should be "File Menu Handle" Not ControlID

$hFileMenu0 = _Menu_GetItemSubMenu($hMenu, 0); File Menu ControlID
$ItemCnt = _Menu_GetItemCount($hFileMenu0)    ; Menu Item Text/Index For File Menu ControlID

there are no ControlID's in the menu, so this command returns 0, does nothing

ControlFocus($winhandle, "", $hMenu)

I see fascists...

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