Jump to content

ControlSetText(), ControlSend() nor Send() not working to change Edit box txt


Recommended Posts

Posted

I am trying to automate the entry of stock tickers from another program to my trading software.  In the snippet below I hard coded my fictitious stock to a variable but I am unable to change the text (From "AAPL" to "CSCO") in one of the windows (in this example using the "Apple Window" - Upper left) I am able to retrieve the handle of the windows, and the control etc, but I am unable to change the Text in the edit box ("Edit1").  The same code (w/ some modifications, titles etc) works find with Notepad.

I have tried many different avenues to achieve my goal.  As you can see in my results, the ControlSetText returned 0 but both Control and ControlSend returned 1 (meaning success) yes the txt never changed.

I would appreciate it any help I can get on this issue, been going at it for a while now.

Thank u for giving this matter ur prompt attention

Ito

 

 

 

WarriorSim.thumb.PNG.6d4bc68caacab8632c88990902932287.PNG

 

540249927_WarriorSim2.thumb.PNG.28a9c62198a71589b1b9ce3528b2d983.PNG

 

 

;#include "myFunctions.au3"
#include <GuiComboBox.au3>
#include <GuiEdit.au3>


Opt("WinTitleMatchMode", 2)  ;To use partial match for window title search
Const _
        $iDuration = 5 ;seconds

Global _
        $sWinControlType = "Edit1"          ;Control [Class:Edit];[Instance:1]
$sStockTicker = "CSCO"
$sWinTitle = "Apple Inc. [AAPL] - Level II"
$sControlTxt = ""
$var = ""
$var2 = ""

$hWin = WinWait($sWinTitle, "", $iDuration)
$hControl = _GetControlHandle($hWin, $sWinControlType, $iDuration)
$varControlSet = _ChangeControl($sWinTitle, $hControl, "", "")
ControlFocus($hControl, "", $sWinControlType)
$var = ControlSend($sWinTitle, "", $sWinControlType, $sStockTicker, 1)
$var2 = Send($sStockTicker & "{ENTER}", 1)
_ChangeControl($sWinTitle, $hControl, "", $sStockTicker)

ConsoleWrite(@CRLF & @CRLF & _
        "Win Handle  : " & $hWin & @CRLF & _
        "Ctrl Handle :" & $hControl & @CRLF & _
        "New Text : " & $sStockTicker & @CRLF & @CRLF & @CRLF & _
        "Control Set Txt : " & $varControlSet & @CRLF & _
        "Control Send : " & $var & @CRLF & _
        "Send : " & $var2 & @CRLF & @CRLF)



Func _ChangeControl($hWin, $hControl, $sControlTxt, $sNewSymbol)
    WinActivate($hWin)
    ControlFocus($hWin, $sControlTxt, $hControl)
    If Not ControlSetText($hWin, $sControlTxt, $hControl, $sNewSymbol, 1) Then
        MsgBox(1, 3, "not able to ControlSetText", 1)
        Return 0
    EndIf

    Return 1
EndFunc   ;==>_ChangeControl

Func _GetControlHandle($hWindow, $sControlType, $iDuration)
    $hControl = _ControlWait($hWindow, $sControlType, $iDuration)
    If Not IsHWnd($hControl) Then
        MsgBox(1, 2, "not able to get control handle")
        Exit 2
    EndIf
    Return $hControl
EndFunc   ;==>_GetControlHandle

Func _ControlWait($hWindow, $Control, $iSecTimeout)
    $hControl = ControlGetHandle($hWindow, "", $Control)
    If Not IsHWnd($hControl) Then
        $iTimer = TimerInit()
        Do
            Sleep(10)
            $hControl = ControlGetHandle($hWindow, "", $Control)
        Until IsHWnd($hControl) Or TimerDiff($iTimer) > $iSecTimeout * 1000
    EndIf
    Return $hControl
EndFunc   ;==>_ControlWait

Results when I run the script

+>16:26:03 Starting AutoIt3Wrapper v.19.102.1901.0 SciTE v.4.1.2.0   Keyboard:00000409  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0409)  CodePage:  utf8.auto.check:
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\rturn\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\rturn\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:c:\Users\rturn\Documents\Autohotkey\Projects\Automate\Automation\TradeAuto_03.au3
+>16:26:04 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "c:\Users\rturn\Documents\Autohotkey\Projects\Automate\Automation\TradeAuto_03.au3"  /errorstdout
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop


Win Handle  : 0x000B0E12
Ctrl Handle :0x000B0CE6
New Text : CSCO


Control Set Txt : 0
Control Send : 1
Send : 1

+>16:26:07 AutoIt3.exe ended.rc:0
+>16:26:07 AutoIt3Wrapper Finished.
Process exited with code 0


 

Posted

hi, bnut  your trading platform not have possibility to crate inside of them code ???  example  nijatrader  and Metatrader4 or  5  have also ambient for develop all type of personaliziation and  you can by develop , pass data and many more ... ,

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...