Ausgabe an Ausgabefenster (Edit-Ctrl) senden

  • Hallo Fachmenschen,

    das ist wahrscheinlich wieder einmal so eine Dummy-Anfängerfrage... Doch ich suchte in der AutoIt-Hilfe, in deren Appendix'es, in den Makro- und UDF-Beschreibungen, sowie zu Guter letzt in diesem und im englischen Forum sowie in der Wiki. Bevor jetzt jemand denkt :) eine Lösung meiner Frage wäre leicht zu finden, weise ich auf meine Sig. hin...

    Szenario:

    Ich habe ein AutoIt-GUI, das ich als "Kontrollfenster" benutze. Drücke ich dort einen Button, öffnet sich eine weitere GUI, die bisher nur ein Edit-Control-Element enthält.

    Das ganze läuft (bis zur Umstellung) im MessageLoopModus.

    Während also mein Script so vor sich her läuft, fragt es bestimmte Zustände ab (Erläuterung in diesem Thread). Wird ein bestimmter Zustand festgestellt, dann wird dieses Ereignis mit FileOpen(), FileWriteLine(), FileClose() in eine Log-Datei geschrieben.

    Wenn ich jetzt den Button drücke, der das Fenster mit dem Edit-Control öffnet, dann wird zuerst mit FileOpen(), FileRead(), FileClose() die Log-Datei eingelesen und im Edit-Control dargestellt. So weit, so gut.

    Von jetzt an soll folgendes gemacht werden:

    a) Jedes weitere Ereignis soll - so wie es in die Datei geschrieben wurde - im Edit-Control dargestellt werden, und
    b) danach in die Datei geschrieben werden.

    An und für sich ist das auch noch nicht einmal mein Problem - zur Darstellung im Edit-Control steht mir ja die Funktion ControlSend() zur Verfügung.

    Meine Frage ist viel mehr: Kennt jemand eine Möglichkeit mit Autoit, eine GUI-Control - die von mir beschriebene Edit-Control - als "Konsole" zu definieren, die als Standard für eine - nur für dieses Control vorgesehene - Ausgabe festgelegt werden kann?

    Ich frage, weil ich denke, dass eine solche Möglichkeit den Programmablauf erheblich beschleunigen könnte, da nicht jedes Mal die Funktion ControlSend() sowie die weiteren Anweisungen hierzu verarbeitet werden müssen.

    Danke - wie immer in diesem freundlichen Forum voller geballtem AutoIt-Wissens - für Eure Antworten.

    • Offizieller Beitrag

    Hi,

    1. es gibt es LOG-Funktion in Autoit _FileWriteLog (einfacher als FIleopen...)

    2. Wenn du selbst die Edit-GUI baust, dann kannst du mit ...SetData den Text setzen.

    Wenn du die Ergebnisse quasi sichtbar protokollieren willst, dann guck dir mal sowas an:

    Spoiler anzeigen
    [autoit]

    #include <GuiConstants.au3>
    #include <GuiEdit.au3>
    #include <GuiStatusBar.au3>
    #include <WinAPI.au3> ; used for Lo/Hi word

    [/autoit] [autoit][/autoit] [autoit]

    Opt('MustDeclareVars', 1)

    [/autoit] [autoit][/autoit] [autoit]

    $Debug_Ed = False ; Check ClassName being passed to Edit functions, set to True and use a handle to another control to see it work

    [/autoit] [autoit][/autoit] [autoit]

    Global $hEdit

    [/autoit] [autoit][/autoit] [autoit]

    _Example_Internal()

    [/autoit] [autoit][/autoit] [autoit]

    Func _Example_Internal()
    Local $hGUI, $StatusBar, $sFile = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\include\changelog.txt"
    Local $aPartRightSide[4] = [120, 248, 378, -1], $button

    [/autoit] [autoit][/autoit] [autoit]

    ; Create GUI
    $hGUI = GUICreate("(Internal) Edit Get Modify", 400, 300)
    $hEdit = GUICtrlCreateInput("", 2, 2, 394, 25)
    $button = GUICtrlCreateButton("Ok", 10, 40, 90, 25)
    GUICtrlSetState($button, $GUI_DEFBUTTON)
    $StatusBar = _GUICtrlStatusBar_Create ($hGUI, $aPartRightSide)
    _GUICtrlStatusBar_SetIcon ($StatusBar, 3, 97, "shell32.dll")
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

    [/autoit] [autoit][/autoit] [autoit]

    ; Add Text
    _GUICtrlEdit_AppendText ($hEdit, "This is a test")

    [/autoit] [autoit][/autoit] [autoit]

    ; Get Modified Flag
    _GUICtrlStatusBar_SetText ($StatusBar, "Modified: " & _GUICtrlEdit_GetModify ($hEdit), 2)

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlSetState($button, $GUI_FOCUS)

    [/autoit] [autoit][/autoit] [autoit]

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
    EndFunc ;==>_Example_Internal

    [/autoit] [autoit][/autoit] [autoit]

    Func _Input_Changed($hControl)
    _DebugPrint("Input Changed: " & _GUICtrlEdit_GetText ($hControl))
    EndFunc ;==>_Input_Changed

    [/autoit] [autoit][/autoit] [autoit]

    Func _Input_Focus($hControl)
    _DebugPrint("Input Got Focus")
    _GUICtrlEdit_SetSel ($hControl, 0, -1)
    EndFunc ;==>_Input_Focus

    [/autoit] [autoit][/autoit] [autoit]

    Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit
    If Not IsHWnd($hEdit) Then $hWndEdit = GUICtrlGetHandle($hEdit)
    $hWndFrom = $ilParam
    $iIDFrom = _WinAPI_LoWord ($iwParam)
    $iCode = _WinAPI_HiWord ($iwParam)
    Switch $hWndFrom
    Case $hEdit, $hWndEdit
    Switch $iCode
    Case $EN_ALIGN_LTR_EC ; Sent when the user has changed the edit control direction to left-to-right
    _DebugPrint("$EN_ALIGN_LTR_EC" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
    "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
    "-->Code:" & @TAB & $iCode)
    ; no return value
    Case $EN_ALIGN_RTL_EC ; Sent when the user has changed the edit control direction to right-to-left
    _DebugPrint("$EN_ALIGN_RTL_EC" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
    "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
    "-->Code:" & @TAB & $iCode)
    ; no return value
    Case $EN_CHANGE ; Sent when the user has taken an action that may have altered text in an edit control
    _DebugPrint("$EN_CHANGE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
    "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
    "-->Code:" & @TAB & $iCode)
    _Input_Changed($iIDFrom)
    ; no return value
    Case $EN_ERRSPACE ; Sent when an edit control cannot allocate enough memory to meet a specific request
    _DebugPrint("$EN_ERRSPACE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
    "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
    "-->Code:" & @TAB & $iCode)
    ; no return value
    Case $EN_HSCROLL ; Sent when the user clicks an edit control's horizontal scroll bar
    _DebugPrint("$EN_HSCROLL" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
    "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
    "-->Code:" & @TAB & $iCode)
    ; no return value
    Case $EN_KILLFOCUS ; Sent when an edit control loses the keyboard focus
    _DebugPrint("$EN_KILLFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
    "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
    "-->Code:" & @TAB & $iCode)
    ; no return value
    Case $EN_MAXTEXT ; Sent when the current text insertion has exceeded the specified number of characters for the edit control
    _DebugPrint("$EN_MAXTEXT" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
    "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
    "-->Code:" & @TAB & $iCode)
    ; This message is also sent when an edit control does not have the $ES_AUTOHSCROLL style and the number of characters to be
    ; inserted would exceed the width of the edit control.
    ; This message is also sent when an edit control does not have the $ES_AUTOVSCROLL style and the total number of lines resulting
    ; from a text insertion would exceed the height of the edit control

    [/autoit] [autoit][/autoit] [autoit]

    ; no return value
    Case $EN_SETFOCUS ; Sent when an edit control receives the keyboard focus
    _DebugPrint("$EN_SETFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
    "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
    "-->Code:" & @TAB & $iCode)
    _Input_Focus($iIDFrom)
    ; no return value
    Case $EN_UPDATE ; Sent when an edit control is about to redraw itself
    _DebugPrint("$EN_UPDATE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
    "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
    "-->Code:" & @TAB & $iCode)
    ; no return value
    Case $EN_VSCROLL ; Sent when the user clicks an edit control's vertical scroll bar or when the user scrolls the mouse wheel over the edit control
    _DebugPrint("$EN_VSCROLL" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
    "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
    "-->Code:" & @TAB & $iCode)
    ; no return value
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_COMMAND

    [/autoit] [autoit][/autoit] [autoit]

    Func _DebugPrint($s_text, $line = @ScriptLineNumber)
    ConsoleWrite( _
    "!===========================================================" & @LF & _
    "+======================================================" & @LF & _
    "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
    "+======================================================" & @LF)
    EndFunc ;==>_DebugPrint

    [/autoit]

    So long,

    Mega