Farbige Zeilen in GUICtrlCreateEdit

  • ja, ich suche die Möglichkeit, wie unten in Scite in der Console, einzelne Zeilen farbig zu gestalten... halt in einem GUICtrlCreateEdit

    hat da wer ne Idee?

    Einmal editiert, zuletzt von Karill Endusa (11. Juni 2010 um 21:14)

  • ich hab schon gesucht aber keine gute Anleitung für RichEdit Controls unter AutoIT gefunden

    und wieso schaffst du es hier das zu schreiben aber im anderen Forum nit X(

  • Was ist denn dein Problem mit Richedit Controls?
    Hier mal ein einfaches Beispiel zur Verwendung:

    Spoiler anzeigen
    [autoit]

    #include <Array.au3>
    #include <EditConstants.au3>
    #AutoIt3Wrapper_Au3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
    #include <GuiRichEdit.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

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

    Main()

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

    Func Main()
    Local $hGui, $hRichEdit, $iMsg, $cButton
    $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, 4) & ")", 320, 350, -1, -1)
    $hRichEdit = _GUICtrlRichEdit_Create($hGui, "::::::::::::::DEMO::::::::::::::", 10, 10, 300, 220, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL,$ES_NOHIDESEL))
    $cButton = GUICtrlCreateButton("Add", 20, 320, 100, 20)
    GUISetState()

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

    While True
    $iMsg = GUIGetMsg()
    Select
    Case $iMsg = $GUI_EVENT_CLOSE
    GUIDelete()
    Exit
    Case $iMsg = $cButton
    _GUICtrlRichEdit_SetSel($hRichEdit,-1,-1) ; Cursor ans Ende setzen
    _RichEdit_AddColoredText($hRichEdit,@CR & "This is some Text",_NewColor())
    EndSelect
    WEnd
    EndFunc ;==>Main

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

    Func _NewColor()
    Local $aHex = StringSplit("0123456789ABCDEF", "", 2), $sRet = "0x"
    For $i = 1 To 6
    $sRet &= $aHex[Random(0, 15, 1)]
    Next
    Return $sRet
    EndFunc ;==>_NewColor

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

    Func _RichEdit_AddColoredText($hRichEdit, $sText, $nColor)
    ;SEuBo
    Local $aSel, $aNSel
    $aSel = _GUICtrlRichEdit_GetSel($hRichEdit) ; aktuelle Cursorpos.
    _GUICtrlRichEdit_AppendText($hRichEdit, $sText) ; Text ahängen
    $aNSel = _GUICtrlRichEdit_GetSel($hRichEdit) ; Cursorpos nach dem Text einfügen
    _GUICtrlRichEdit_SetSel($hRichEdit, $aSel[0], $aNSel[0], True) ; Geschriebenen Text wählen
    _GUICtrlRichEdit_SetCharColor($hRichEdit, $nColor) ; Einfärben
    _GUICtrlRichEdit_SetSel($hRichEdit, -1, -1) ; Und cursor ans ende setzen
    EndFunc ;==>_RichEdit_AddColoredText

    [/autoit]
  • ok danke soweit, ich kann leider nicht sagen dass es funktioniert, aber es klingt logisch

    mein Problem ist nun folgendes:
    wenn er da was reinschreiben soll, unter verwendung deiner Funktion, bekomm ich ne Fehlermeldung

    Code
    _GUICtrlRichEdit_SetSel($hre_RichEdit, $a_Sel[0], $a_NSel[0], True)
    _GUICtrlRichEdit_SetSel($hre_RichEdit, $a_Sel[0], $a_NSel^ ERROR

    Die von dir geschriebene Version hab ich nur angepasst, sie wird durch eine andere Funktion aufgerufen:

    [autoit]

    Func _console_write($s_console_type, $s_console_text)
    GUICtrlSetData($hl_console, "Now: "&$s_console_text)
    Local $hex_color = 0x000000
    If $s_console_type = "INFO" Then $hex_color = 0x000000
    If $s_console_type = "DELETE" Then $hex_color = 0xff0000
    If $s_console_type = "UPDATE" Then $hex_color = 0x0000ff
    If $s_console_type = "INSERT" Then $hex_color = 0x00ff00
    _RichEdit_AddColoredText($hre_console, $s_console_text, $hex_color)
    _GUICtrlRichEdit_ScrollLines($hre_console, +1)
    EndFunc

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

    Func _RichEdit_AddColoredText($hre_RichEdit, $s_Text, $hex_Color)
    Local $a_Sel, $a_NSel
    $a_Sel = _GUICtrlRichEdit_GetSel($hre_RichEdit)
    _GUICtrlRichEdit_AppendText($hre_RichEdit, $s_Text)
    $aNSel = _GUICtrlRichEdit_GetSel($hre_RichEdit)
    _GUICtrlRichEdit_SetSel($hre_RichEdit, $a_Sel[0], $a_NSel[0], True)
    _GUICtrlRichEdit_SetCharColor($hre_RichEdit, $hex_Color)
    _GUICtrlRichEdit_SetSel($hre_RichEdit, -1, -1)
    EndFunc

    [/autoit]
    • Offizieller Beitrag

    Ohne ein Script; was ausführbar ist, kann man dir nicht helfen.

  • ah ja, gerne^^ is ne erweiterte/neuere Version meines TS3-Rechte-Transfer-Programms^^

    Spoiler anzeigen
    [autoit]

    #RequireAdmin

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

    ;[includes]
    #include <GuiEdit.au3>
    #include <GuiRichEdit.au3>
    #include <SQLite.au3>
    #include <SQLite.dll.au3>

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

    Opt("GUIOnEventMode", 1)

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

    Global $b_sqlite_opened = False

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

    $h_MainGui = GUICreate("TS3 Rights Transferer, Version 0.02", 500, 300)
    GUISetOnEvent(-3, "_exit", $h_MainGui)
    GUICtrlCreateLabel("ts3server.sqlitedb path:", 5, 5)
    $hi_ts3sqlite_input = GUICtrlCreateInput("", 5, 25, 300, 20)
    GUICtrlSetState(-1, 128)
    GUICtrlCreateButton("...", 310, 25, 60, 20)
    GUICtrlSetOnEvent(-1, "__sqlite_file_lookup")
    GUICtrlCreateButton("Load", 375, 25, Default, 20)
    GUICtrlSetOnEvent(-1, "_load_all_groups")
    GUICtrlCreateLabel("Template Groups:", 5, 60)
    $hc_template_groups = GUICtrlCreateCombo("no ts3sqlite file", 5, 75, 100)
    GUICtrlSetState(-1, 128)
    GUICtrlCreateLabel("------------", 110, 78)
    GUICtrlCreateLabel("----------->", 255, 78)
    $hb_transfer_button = GUICtrlCreateButton("transfer", 140, 75, 120, 20)
    GUICtrlSetState(-1, 128)
    GUICtrlSetOnEvent(-1, "_transfer_rights")
    GUICtrlCreateLabel("Server Groups:", 300, 60)
    $hc_server_groups = GUICtrlCreateCombo("no ts3sqlite file", 300, 75, 100)
    GUICtrlSetState(-1, 128)
    $hl_console = GUICtrlCreateLabel("Now:", 5, 135, 495)
    $hre_console = _GUICtrlRichEdit_Create($h_MainGui, "", 0, 150, 500, 150, BitOR(4, 0x00200000, 64,256, 2048))
    GUISetState()

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

    If FileExists("ts3server.sqlitedb") Then
    GUICtrlSetData($hi_ts3sqlite_input, @ScriptDir & "\ts3server.sqlitedb")
    EndIf

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

    Func _console_write($s_console_type, $s_console_text)
    GUICtrlSetData($hl_console, "Now: "&$s_console_text)
    Local $hex_color = 0x000000
    If $s_console_type = "INFO" Then $hex_color = 0x000000
    If $s_console_type = "DELETE" Then $hex_color = 0xff0000
    If $s_console_type = "UPDATE" Then $hex_color = 0x0000ff
    If $s_console_type = "INSERT" Then $hex_color = 0x00ff00
    _RichEdit_AddColoredText($hre_console, $s_console_text, $hex_color)
    _GUICtrlRichEdit_ScrollLines($hre_console, +1)
    EndFunc

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

    Func _console_flush()
    $i_reLineCount = _GUICtrlRichEdit_GetLineCount($hre_console)
    _GUICtrlRichEdit_ScrollLines($hre_console, -$i_reLineCount)
    _GUICtrlRichEdit_SetText($hre_console, "")
    EndFunc

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

    Func _RichEdit_AddColoredText($hre_RichEdit, $s_Text, $hex_Color)
    Local $a_Sel, $a_NSel
    $a_Sel = _GUICtrlRichEdit_GetSel($hre_RichEdit)
    _GUICtrlRichEdit_AppendText($hre_RichEdit, $s_Text)
    $aNSel = _GUICtrlRichEdit_GetSel($hre_RichEdit)
    _GUICtrlRichEdit_SetSel($hre_RichEdit, $a_Sel[0], $a_NSel[0], True)
    _GUICtrlRichEdit_SetCharColor($hre_RichEdit, $hex_Color)
    _GUICtrlRichEdit_SetSel($hre_RichEdit, -1, -1)
    EndFunc

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

    Func _transfer_rights()
    _console_flush()
    $s_chosen_temmplate_grp = GUICtrlRead($hc_template_groups)
    $s_chosen_server_grp = GUICtrlRead($hc_server_groups)

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

    $as_chosen_server_grp = StringSplit($s_chosen_server_grp, ":")
    $s_chosen_server_grp_svrid = $as_chosen_server_grp[1]
    $s_chosen_server_grp_name = $as_chosen_server_grp[2]

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

    __sqlite_open()
    Local $aResult, $iRows, $iColumns, $iRval
    $iRval = _SQLite_GetTable(-1, "SELECT group_id FROM groups_server WHERE server_id = 0 AND type = 0 AND name = '"&$s_chosen_temmplate_grp&"';", $aResult, $iRows, $iColumns)
    If $iRval = $SQLITE_OK Then
    If $aResult[0] <> 2 Then Exit
    $s_template_group_id = $aResult[2]
    Else
    MsgBox(16, "SQLite Error: "&$iRval, _SQLite_ErrMsg())
    EndIf
    $iRval = _SQLite_GetTable(-1, "SELECT group_id FROM groups_server WHERE server_id = "&$s_chosen_server_grp_svrid&" AND type = 1 AND name = '"&$s_chosen_server_grp_name&"';", $aResult, $iRows, $iColumns)
    If $iRval = $SQLITE_OK Then
    If $aResult[0] <> 2 Then Exit
    $s_server_group_id = $aResult[2]
    Else
    MsgBox(16, "SQLite Error: "&$iRval, _SQLite_ErrMsg())
    EndIf

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

    _console_write("INFO", "Transfer der Rechte: group_id="&$s_template_group_id&" zu group_id="&$s_server_group_id & @CRLF)

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

    $iRval = _SQLite_GetTable(-1, "SELECT perm_id, perm_value, perm_negated, perm_skip FROM perm_server_group WHERE server_id = 0 AND id1="&$s_template_group_id&";", $aResult, $iRows, $iColumns)
    If $iRval = $SQLITE_OK Then
    Local $hQuery, $aRow
    For $i = 5 To $aResult[0] Step 4
    $s_perm_id = $aResult[$i]
    $s_perm_value = $aResult[$i+1]
    $s_perm_negated = $aResult[$i+2]
    $s_perm_skip = $aResult[$i+3]
    _SQLite_Query(-1, "SELECT ROWID FROM perm_server_group WHERE perm_id='"&$s_perm_id&"' AND server_id="&$s_chosen_server_grp_svrid&" AND id1="&$s_server_group_id&";", $hQuery)
    _SQLite_FetchData($hQuery, $aRow, False, True)
    _SQLite_QueryFinalize($hQuery)
    If $aRow[0] <> "" Then
    _SQLite_Exec(-1, "UPDATE perm_server_group SET perm_value="&$s_perm_value&", perm_negated="&$s_perm_negated&", perm_skip="&$s_perm_skip&" WHERE ROWID="&$aRow[0]&";")
    _console_write("UPDATE", "Updated PERM:"&$aRow[0]&":"&$s_perm_id&" GRP:"&$s_chosen_server_grp_svrid&":"&$s_server_group_id)
    Else
    _SQLite_Exec(-1, "INSERT INTO perm_server_group (server_id, id1, id2, perm_id, perm_value, perm_negated, perm_skip) VALUES ("&$s_chosen_server_grp_svrid&", "&$s_server_group_id&", 0, '"&$s_perm_id&"', "&$s_perm_value&", "&$s_perm_negated&", "&$s_perm_skip&");")
    _console_write("INSERT", "Inserted PERM:"&$s_perm_id&" GRP:"&$s_chosen_server_grp_svrid&":"&$s_server_group_id)
    EndIf
    Next
    Else
    MsgBox(16, "SQLite Error: "&$iRval, _SQLite_ErrMsg())
    EndIf

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

    $iRval = _SQLite_GetTable(-1, "SELECT ROWID, perm_id FROM perm_server_group WHERE server_id = "&$s_chosen_server_grp_svrid&" AND id1="&$s_server_group_id&";", $aResult, $iRows, $iColumns)
    If $iRval = $SQLITE_OK Then
    Local $hQuery, $aRow
    For $i = 3 To $aResult[0] Step 2
    $s_rowid = $aResult[$i]
    $s_perm_id = $aResult[$i+1]
    _SQLite_Query(-1, "SELECT ROWID FROM perm_server_group WHERE perm_id='"&$s_perm_id&"' AND server_id=0 AND id1="&$s_template_group_id&";", $hQuery)
    _SQLite_FetchData($hQuery, $aRow, False, True)
    _SQLite_QueryFinalize($hQuery)
    If $aRow[0] = "" Then
    _SQLite_Exec(-1, "DELETE FROM perm_server_group WHERE ROWID="&$s_rowid&";")
    _console_write("DELETE", "Deleted PERM:"&$s_rowid&":"&$s_perm_id&" GRP:"&$s_chosen_server_grp_svrid&":"&$s_server_group_id)
    EndIf
    Next
    Else
    MsgBox(16, "SQLite Error: "&$iRval, _SQLite_ErrMsg())
    EndIf
    GUICtrlSetData($hl_console, "Now: Finished")
    __sqlite_close()
    EndFunc

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

    Func _load_all_groups()
    _load_template_groups()
    _load_server_groups()
    GUICtrlSetState($hb_transfer_button, 64)
    EndFunc

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

    Func _load_template_groups()
    $s_template_groups = ""
    __sqlite_open()
    Local $aResult, $iRows, $iColumns, $iRval
    $iRval = _SQLite_GetTable(-1, "SELECT name FROM groups_server WHERE server_id = 0 AND type = 0;", $aResult, $iRows, $iColumns)
    If $iRval = $SQLITE_OK Then
    For $i = 2 To $aResult[0]
    $s_template_groups &= "|"&$aResult[$i]
    Next
    Else
    MsgBox(16, "SQLite Error: "&$iRval, _SQLite_ErrMsg())
    EndIf
    __sqlite_close()
    GUICtrlSetData($hc_template_groups, $s_template_groups)
    GUICtrlSetState($hc_template_groups, 64)
    EndFunc

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

    Func _load_server_groups()
    $s_server_groups = ""
    __sqlite_open()
    Local $aResult, $iRows, $iColumns, $iRval
    $iRval = _SQLite_GetTable(-1, "SELECT server_id, name FROM groups_server WHERE server_id != 0 AND type = 1 ORDER BY server_id;", $aResult, $iRows, $iColumns)
    If $iRval = $SQLITE_OK Then
    For $i = 3 To $aResult[0] Step 2
    $s_server_groups &= "|"&$aResult[$i]&":"&$aResult[$i+1]
    Next
    Else
    MsgBox(16, "SQLite Error: "&$iRval, _SQLite_ErrMsg())
    EndIf
    __sqlite_close()
    GUICtrlSetData($hc_server_groups, $s_server_groups)
    GUICtrlSetState($hc_server_groups, 64)
    EndFunc

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

    Func __sqlite_file_lookup()
    If $b_sqlite_opened Then __sqlite_close()
    $s_ts3sqlite_file = FileOpenDialog("ts3sqlite file search", @ScriptDir, "ts3sqlite(ts3server.sqlitedb)", 1 + 2)
    GUICtrlSetData($hi_ts3sqlite_input, $s_ts3sqlite_file)
    EndFunc

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

    Func __sqlite_open()
    _SQLite_Startup()
    $s_ts3sqlite_path = GUICtrlRead($hi_ts3sqlite_input)
    _SQLite_Open($s_ts3sqlite_path)
    $b_sqlite_opened = True
    EndFunc

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

    Func __sqlite_close()
    _SQLite_Close()
    _SQLite_Shutdown()
    $b_sqlite_opened = False
    EndFunc

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

    Func _exit()
    If $b_sqlite_opened Then __sqlite_close()
    Exit
    EndFunc

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

    While 1 * Sleep(10)
    WEnd

    [/autoit]
    • Offizieller Beitrag

    Ich kann keinen Fehler entdecken. Zumindest kommt keiner bei Programmstart. Weiteres testen geht nicht, da ich keine Datenbankdatei habe.

  • ja da liegt das Problem, wenn man dann transferieren will, da wird ja auch erst die funktion genutzt
    kann dir jetzt leider nicht unsere DB geben wegen der Sicherheit xD

    • Offizieller Beitrag

    Das du die DB nicht rausgeben kannst verstehe ich. Kannst du nicht eine Test DB anlegen? Wie soll man dir sonst helfen?