jugador Posted April 16, 2021 Share Posted April 16, 2021 (edited) #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 October 25, 2021 by jugador Tick 1 Link to comment Share on other sites More sharing options...
Nine Posted April 17, 2021 Share Posted April 17, 2021 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. jugador 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
jugador Posted April 17, 2021 Author Share Posted April 17, 2021 (edited) 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 April 17, 2021 by jugador Link to comment Share on other sites More sharing options...
Nine Posted April 17, 2021 Share Posted April 17, 2021 Well. You made the association that _GUICtrlMenu_GetItemID is equal to the CmdID required in the message. So no need to hardcode the ID now. Congrats for that. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted April 17, 2021 Moderators Share Posted April 17, 2021 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 More sharing options...
jugador Posted April 17, 2021 Author Share Posted April 17, 2021 @JLogan3o13 If you read the first post I wasn't asking for help. So instead of moving here you could move the post to AutoIt Example Scripts section. Anyway it’s not that important so forget it. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted April 18, 2021 Moderators Share Posted April 18, 2021 @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 More sharing options...
jugador Posted April 18, 2021 Author Share Posted April 18, 2021 (edited) @JLogan3o13 meticulous observation 👏 👏 👏 well done 👍. Edited April 18, 2021 by jugador Link to comment Share on other sites More sharing options...
jugador Posted April 18, 2021 Author Share Posted April 18, 2021 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 More sharing options...
Nine Posted April 18, 2021 Share Posted April 18, 2021 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. jugador 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now