jugador Posted March 15, 2022 Share Posted March 15, 2022 Trying to learn how to use _SendMessage /_WinAPI_PostMessage with different Windows Messages list like 000c => WM_SETTEXT 000d => WM_GETTEXT 000e => WM_GETTEXTLENGTH 0300 => WM_CUT 0301 => WM_COPY 0302 => WM_PASTE 0303 => WM_CLEAR Trying to get length of string but it not work.... #include <SendMessage.au3> #include <WinAPISysWin.au3> __TestRun() Func __TestRun() Run("notepad.exe") WinWait("[CLASS:Notepad]", "", 10) Local $o_hWnd = WinGetHandle("[CLASS:Notepad]") If @error Then ConsoleWrite("An error occurred when trying to retrieve the window handle of Notepad." & @CRLF) Exit EndIf Local $o_SheetHandle = ControlGetHandle($o_hWnd, '', 'Edit1') ConsoleWrite("Notepad (hWnd) => " & $o_hWnd & @Tab & "Edit1 (hWnd) => " &$o_SheetHandle & @CRLF) Send("ABCD") ;~ now how i retrieve text length using _SendMessage Local $WM_GETTEXTLENGTH = 0x000e _SendMessage($o_SheetHandle, $WM_GETTEXTLENGTH, 0, 0) Local $oo_Msg = @error ConsoleWrite("_SendMessage: " & $oo_Msg & @CRLF) MsgBox(0, "", "Click to continue.....") WinClose($o_hWnd) EndFunc it's bit confusing as WM_PASTE work with _SendMessage but not with _WinAPI_PostMessage ClipPut("ABCD") _SendMessage($o_SheetHandle, $WM_PASTE, 0, 0) ;~ working _WinAPI_PostMessage($o_SheetHandle, $WM_PASTE, 0, 0) ;~ not working ClipPut("") or this code using _WinAPI_PostMessage work but _SendMessage not work why? Local $VK_RETURN = 0x0D Local $WM_KEYDOWN = 0x0100 Local $WM_KEYUP = 0101 _SendMessage($o_SheetHandle, $WM_KEYDOWN, $VK_RETURN, 0) ;~ not working _SendMessage($o_SheetHandle, $WM_KEYUP, $VK_RETURN, 0) ;~ not working _WinAPI_PostMessage($o_SheetHandle, $WM_KEYDOWN, $VK_RETURN, 0) ;~ working _WinAPI_PostMessage($o_SheetHandle, $WM_KEYUP, $VK_RETURN, 0) ;~ working So it will helpful if someone knowledgeable could write example/note on AutoIt Example Scripts section about _SendMessage / _WinAPI_PostMessage Link to comment Share on other sites More sharing options...
ad777 Posted March 15, 2022 Share Posted March 15, 2022 1 hour ago, jugador said: Trying to get length of string but it not work.... $Length = _SendMessage($o_SheetHandle, $WM_GETTEXTLENGTH, 0, 0) Local $oo_Msg = @error ConsoleWrite("_SendMessage: " & $oo_Msg & @CRLF) ConsoleWrite("Length:" & $Length &@CRLF) iam ِAutoit programmer. best thing in life is to use your Brain to Achieve everything you want. Link to comment Share on other sites More sharing options...
jugador Posted March 15, 2022 Author Share Posted March 15, 2022 (edited) @ad777 thanks 1) Now _WinAPI_PostMessage with $WM_PASTE work just have to add sleep(100) _WinAPI_PostMessage($o_SheetHandle, $WM_PASTE, 0, 0) Sleep(100) 2) and for _SendMessage and $VK_RETURN to work have to use $WM_CHAR instead of $WM_KEYDOWN _SendMessage($o_SheetHandle, $WM_CHAR, $VK_RETURN, 0) 3) WM_SETTEXT Local $WM_SETTEXT = 0x000c Local $o_Text = "ABCDEF" Local $t_struct = DllStructCreate("wchar[" & StringLen($o_Text) + 1 & "]") DllStructSetData($t_struct, 1, $o_Text) _SendMessage($o_SheetHandle, $WM_SETTEXT, 0, DllStructGetPtr($t_struct)) $t_struct = 0 4) WM_GETTEXT Local $WM_GETTEXT = 0x000d Local $o_Text = "ABCDEF" Send($o_Text) Local $o_MaxCharacters = StringLen($o_Text) + 1 Local $t_struct = DllStructCreate("wchar[" & $o_MaxCharacters & "]") _SendMessage($o_SheetHandle, $WM_GETTEXT, $o_MaxCharacters, DllStructGetPtr($t_struct)) ConsoleWrite(DllStructGetData($t_struct, 1) & @CRLF) $t_struct = 0 5) Ctrl + P ;~ keybd_event by @Bilgus Local $WM_KEYDOWN = 0x0100 Local $WM_KEYUP = 0x0101 Local $VK_P = 0x50 DllCall('user32.dll', 'int', 'keybd_event', 'byte', 0xA2, 'dword', 0x1D, 'dword', 0x0, 'int', 0) _WinAPI_PostMessage($o_SheetHandle, $WM_KEYDOWN, $VK_P, 0) _WinAPI_PostMessage($o_SheetHandle, $WM_KEYUP, $VK_P, 0) DllCall('user32.dll', 'int', 'keybd_event', 'byte', 0xA2, 'dword', 0x1D, 'dword', 0x0002, 'int', 0) For WM_COMMAND( 0x0111 ) this may help....https://www.autoitscript.com/forum/topic/205640-guictrlmenuclick/ Edited March 16, 2022 by jugador Link to comment Share on other sites More sharing options...
junkew Posted March 15, 2022 Share Posted March 15, 2022 https://www.codeproject.com/Articles/1228123/The-Art-of-WIN-Programming-the-Elusive-Control-Spy jugador 1 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
jugador Posted March 24, 2022 Author Share Posted March 24, 2022 (edited) @LarsJ and @junkew to retrieves the command identifier associated with the button we use _GUICtrlToolbar_IndexToCommand it worked well with notepad++ but failed if try on different software so is it possible to retrieves the command identifier associated with the button of toolbar using MSAA or UI Automation code or have to use Winspector / spy++ Edited March 24, 2022 by jugador Link to comment Share on other sites More sharing options...
junkew Posted March 25, 2022 Share Posted March 25, 2022 On first sight I would not know if that commandid is somewhere easy to retrieve with uia. never had the need as i normally click or invoke a button that is found either by name or index jugador 1 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets 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