Jump to content

GUICtrlMenuClick


jugador
 Share

Recommended Posts

#include "GUICtrlMenuClick.au3"

Example()

Func Example()
    Local $hWnd = WinGetHandle("[CLASS:SciTEWindow]")
    Local $hMenu = _GUICtrlMenu_GetMenu($hWnd)

    Local $ooo_GetID = __GUICtrlMenu_GetID($hMenu, 'As HTML...')
    If $ooo_GetID <> -1 Then _
    __GUICtrlMenu_ClickByID($hWnd, $ooo_GetID)

    If WinExists($hMenu) Then WinClose($hMenu)
EndFunc

example 2:-     https://www.autoitscript.com/forum/topic/206886-problem-with-notepad/?do=findComment&comment=1491372

Modified udf as per @Nine suggestion

GUICtrlMenuClick.au3

Edited by jugador
Link to comment
Share on other sites

Nice find.  Only one small issue.  When clicking the menu, it does not close the context menu.

Example()

Func Example()
  Local $hWnd = WinGetHandle("[CLASS:SciTEWindow]")
  Local $hCtrl = ControlGetHandle($hWnd, "", "Scintilla1")
  _WinAPI_PostMessage($hWnd, $WM_CONTEXTMENU, $hCtrl, 0x00E000E0)
  Local $hContext = WinWait("[CLASS:#32768]")
  Local $hMenu = _SendMessage($hContext, $MN_GETHMENU)
  Local $iItem = _GUICtrlMenu_FindItem($hMenu, "Select All")
  Local $ItemID = _GUICtrlMenu_GetItemID($hMenu, $iItem)
  ConsoleWrite($ItemID & @CRLF)
  _SendMessage($hWnd, $WM_COMMAND, $ItemID, 0)
  WinClose($hContext)
EndFunc

Tested on standard menu, it works perfectly. No issue.

So you should consider just adding context window handle as a parameter of your function.

Link to comment
Share on other sites

Thanks @Nine for testing.

I am not a coder so opinion of the forum members is important.

while searching forum on UI Automation, i found  Automating Notepad - Classic  post of @LarsJ    

So basically I did not find anything 😅 .

& for context menu closing

If WinExists($hContext) Then WinClose($hContext)

 

Edited by jugador
Link to comment
Share on other sites

Link to comment
Share on other sites

  • Moderators

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

@jugador For it not being important you sure are acting as if someone kicked your dog instead of accidentally moving a thread to the wrong forum. Moved again, let's hope this makes it all better for you.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Now you can click Menu or Sub menu by ID
for instance you can click "SciTE Export As HTML..." option just by ID.
Just use __GUICtrlMenu_GetID to get the ID of the menu & that’s it.
1st post updated with example & GUICtrlMenuClick.udf

Link to comment
Share on other sites

Nice idea to recurse the menu tree to find a leaf. 

FWIW :

1- It is kind of strange to see those prefixes to your variable names, consider using Best Coding Practices.

2- I think you should use _SendMessage instead of _WinAPI_PostMessage as it "returns without waiting for the thread to process the message".  SendMessage waits until the thread has processes the request.  It is more in line with the objective of the click menu IMO.

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