Sign in to follow this  
Followers 0
PARK

How to click menu item in Autoit v3

4 posts in this topic

Hi

I am new here and I am really enjoy AutoIt, it is nice and wonderful.

I have some difficulty to click on menu item. I saw numbers of example in your forum but none of them works for me, it seems that the major problem is that I have no <AL3Menu.au3>, I could not find it in forum.

Is anyone can help me with this, give me "AL3Menu.au3" or tell me how can I click on Item.

Thanks in advanced

Share this post


Link to post
Share on other sites



The old AL3 library of UDFs was updated and standardized for inclusion with the AutoIt distribution a long time ago. While you can still find the old UDFs, nobody maintains them anymore and you should use the current UDFs instead.

If you don't need the complexity of the UDF, use WinMenuSelectItem() (see help file).

Otherwise, there are over 50 _GuiCtrlMenu_* functions in GuiMenu.au3 (see help file).

:mellow:


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

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

The old AL3 library of UDFs was updated and standardized for inclusion with the AutoIt distribution a long time ago. While you can still find the old UDFs, nobody maintains them anymore and you should use the current UDFs instead.

If you don't need the complexity of the UDF, use WinMenuSelectItem() (see help file).

Otherwise, there are over 50 _GuiCtrlMenu_* functions in GuiMenu.au3 (see help file).

:P

Hi PsaltyDS and thanks for replay,

I scan all _GuiCtrlMenu_* functions but i did not findout how i can click the menu.

I need to do the follow and it would be fantastic if you can help me,

I need to get the menu of current windows and walk throw all menu element, click each of them and make the screen capture from the active windows.

I can do all in above task but Click on menu Item :party: . by using WinMenuSelectItem(), I can just select the known menuitem. :mellow: while i have no idea about the menues in opened windows.

Any Idea?

Thanks in advacned

Edited by PARK

Share this post


Link to post
Share on other sites

One way is to get the CmdID of the menu item and send a WM_COMMAND message for it:

#include <GuiMenu.au3>
#include <GuiConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#Include <SendMessage.au3>

Opt('MustDeclareVars', 1)

Global Enum $idNew = 1000, $idOpen, $idSave, $idExit, $idCut, $idCopy, $idPaste, $idAbout
Global $hGUI, $hFile, $hEdit, $hHelp, $hMain, $idMemo, $idTestButton

; Create GUI
$hGUI = GUICreate("Menu", 400, 400)

; Create File menu
$hFile = _GUICtrlMenu_CreateMenu()
_GUICtrlMenu_InsertMenuItem($hFile, 0, "&New", $idNew)
_GUICtrlMenu_InsertMenuItem($hFile, 1, "&Open", $idOpen)
_GUICtrlMenu_InsertMenuItem($hFile, 2, "&Save", $idSave)
_GUICtrlMenu_InsertMenuItem($hFile, 3, "", 0)
_GUICtrlMenu_InsertMenuItem($hFile, 4, "E&xit", $idExit)

; Create Edit menu
$hEdit = _GUICtrlMenu_CreateMenu()
_GUICtrlMenu_InsertMenuItem($hEdit, 0, "&Cut", $idCut)
_GUICtrlMenu_InsertMenuItem($hEdit, 1, "C&opy", $idCopy)
_GUICtrlMenu_InsertMenuItem($hEdit, 2, "&Paste", $idPaste)

; Create Help menu
$hHelp = _GUICtrlMenu_CreateMenu()
_GUICtrlMenu_InsertMenuItem($hHelp, 0, "&About", $idAbout)

; Create Main menu
$hMain = _GUICtrlMenu_CreateMenu()
_GUICtrlMenu_InsertMenuItem($hMain, 0, "&File", 0, $hFile)
_GUICtrlMenu_InsertMenuItem($hMain, 1, "&Edit", 0, $hEdit)
_GUICtrlMenu_InsertMenuItem($hMain, 2, "&Help", 0, $hHelp)

; Set window menu
_GUICtrlMenu_SetMenu($hGUI, $hMain)

; Create memo control
$idMemo = GUICtrlCreateEdit("", 2, 2, 396, 276, 0)
GUICtrlSetFont($idMemo, 9, 400, 0, "Courier New")

; Create test button
$idTestButton = GUICtrlCreateButton("TEST", 150, 330, 100, 30)


; Loop until user exits
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUISetState()
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idTestButton
            _SendMessage($hGUI, 0x111, 0x3ED, 0) ; 0x111 = WM_COMMAND, 0x3ED = 'File|Copy' command ID
    EndSwitch
WEnd

; Handle menu commands
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    ;ConsoleWrite("WM_COMMAND:  $hWnd = " & $hWnd & "; $iMsg = " & $iMsg & "; $iwParam = " & $iwParam & "; $ilParam = " & $ilParam & @LF)

    Local $iCmdID = _WinAPI_LoWord($iwParam)
    Switch $iCmdID
        Case $idNew
            MemoWrite("New:  " & $iCmdID)
        Case $idOpen
            MemoWrite("Open:  " & $iCmdID)
        Case $idSave
            MemoWrite("Save:  " & $iCmdID)
        Case $idExit
            Exit
        Case $idCut
            MemoWrite("Cut:  " & $iCmdID)
        Case $idCopy
            MemoWrite("Copy:  " & $iCmdID)
        Case $idPaste
            MemoWrite("Paste:  " & $iCmdID)
        Case $idAbout
            MemoWrite("about:  " & $iCmdID)
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

; Write message to memo
Func MemoWrite($sMessage)
    GUICtrlSetData($idMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

The problem with this is that, depending on the style of the menu, it might send WM_MENUCOMMAND instead of WM_COMMAND when an item is clicked.

:mellow:


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

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