Hello,
thanks for the tip!
I change my script to this
#include <GUIConstants.au3>
#Include <GuiListView.au3>
$red = 0xff0000
$green = 0x00FF40
$Form1 = GUICreate("Form1", 630, 262, 193, 115)
$b_write = GUICtrlCreateButton("Write", 100, 224, 100, 30, $BS_FLAT)
$b_save = GUICtrlCreateButton("Save", 300, 224, 100, 30, $BS_FLAT)
$L_Console = GUICtrlCreateListView("| |", 0, 32, 626, 182, BitOR($LVS_NOCOLUMNHEADER, $LVS_SINGLESEL, $WS_VSCROLL, $WS_HSCROLL), $LVS_EX_FLATSB)
GUISetState(@SW_SHOW)
_consolewrite($L_Console, "jdfölkjsf", $green)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
case $b_write
_consolewrite($L_Console, "This is a example text that is longer as 260 characters. -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 260123456789")
Case $b_save
$logfile = FileSaveDialog("Log speichern", @ScriptDir, "Log-Datei (*.log)")
if Not @error Then _consolesave($L_Console, $logfile)
EndSwitch
WEnd
Func _consolewrite($console, $text, $color = 0xffffff)
if $text <> "" Then
If StringLen($text) > 260 then
$write = GUICtrlCreateListViewItem($text & "|" & StringMid($text, 260), $console)
Else
$write = GUICtrlCreateListViewItem($text, $console)
GUICtrlSetBkColor(-1, $color)
$count = _GUICtrlListViewGetItemCount($console)
_GUICtrlListViewScroll($console,0,200)
EndIf
EndIf
_GUICtrlListViewSetColumnWidth($L_Console, 0, $LVSCW_AUTOSIZE)
_GUICtrlListViewSetColumnWidth($L_Console, 1, $LVSCW_AUTOSIZE)
EndFunc
Func _consolesave($console, $save_file)
if StringRight($save_file, 4) <> ".log" Then
$save_file = $save_file & ".log"
EndIf
if FileExists($save_file) Then
$ueberschreib = MsgBox(36, "Datei existiert", "Soll die Datei " & $save_file & " überschrieben werden?")
if $ueberschreib = 6 Then
$file = FileOpen($save_file, 2)
$count = _GUICtrlListViewGetItemCount($console)
for $i = 0 to $count -1
$line = _GUICtrlListViewGetItemText($console, $i, 0)
FileWriteLine($file, $line)
Next
_consolewrite($L_Console, "Log wurde nach " & $save_file & " gespeichert.", $green)
FileClose($file)
Else
_consolewrite($L_Console, "Speichern des Logs wurde abgebrochen.")
EndIf
Else
$file = FileOpen($save_file, 2)
$count = _GUICtrlListViewGetItemCount($console)
for $i = 0 to $count -1
$line = _GUICtrlListViewGetItemText($console, $i, 0)
FileWriteLine($file, $line)
Next
_consolewrite($L_Console, "Log wurde nach " & $save_file & " gespeichert.", $green)
FileClose($file)
EndIf
EndFunc
If a line is longer as 260 characters then the text is split to 2 strings and written in a new column.
This is nearly perfect. There are some spaces after the first column if the text is longer as 260 characters.