RichEdit font dauerhaft ändern

  • Hi,

    ich hab mal wieder ein Problem mit der RichEditbox und zwar wollte ich den font ändern.

    Wenn ich mit dem Befel

    [autoit]

    _GUICtrlRichEdit_SetFont($RichEdit_Montag, 10, "Times")

    [/autoit]

    den font änder und mit

    [autoit]

    $Temp_Array_Font = _GUICtrlRichEdit_GetFont($RichEdit_Montag)
    _ArrayDisplay($Temp_Array_Font)

    [/autoit]

    überprüfe, stimmt es auch.

    Aber wenn ich dann später Text einfüge über

    [autoit]

    _GUICtrlRichEdit_SetText($RichEdit_Montag, @CRLF & @CRLF & @CRLF & @CRLF & " BITTE WARTEN!")

    [/autoit]

    und mit

    [autoit]

    $Temp_Array_Font = _GUICtrlRichEdit_GetFont($RichEdit_Montag)
    _ArrayDisplay($Temp_Array_Font)

    [/autoit]

    überprüfe ist es wieder "MS Shell Dlg" und Schriftgröße "8.25"

    Vielleicht kennt einer das Problem und kann mir helfen.

    EDIT:

    Ich hab festgestellt das die Einstellungen am Font bestehen bleiben wenn ich

    [autoit]

    _GUICtrlRichEdit_InsertText($hWnd, $sText)

    [/autoit]

    verwende, aber da gibt es natürlich das Problem das ich immer erst den ganzen alten Text löschen muss.

    mfg

    nefas

  • Da fehlt der nötige Parameter in der Funktion (funkioniert aber erst ab RichEdit 4.1) ;) Mit $SCF_DEFAULT als letztem Parameter sollte die folgende Funktion die Standard-Schrift setzen.

    Spoiler anzeigen
    [autoit]

    ;_GUICtrlRichEdit_SetFontEx($hWnd, Default, Default, Default, Default, $SCF_DEFAULT)

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _GUICtrlRichEdit_SetFontEx
    ; Description ...: Sets the font attributes of selected text or, if none selected, sets those of text inserted at the insertion point (change with $iSCF)
    ; Syntax.........: _GUICtrlRichEdit_SetFontEx($hWnd, $iPoints = Default[, $sName = Default[, $iCharset = Default[, $iLcid = Default[, $iSCF = $SCF_SELECTION]]]])
    ; Parameters ....: $hWnd - Handle to the control
    ; $iPoints - point size (Optional)
    ; $sName - the name of the font face, e.g. "Courier" not "Courier Bold" (Optional)
    ; $iCharSet - the character set (Optional) - one of:
    ; |$ANSI_CHARSET - 0
    ; |$BALTIC_CHARSET - 186
    ; |$CHINESEBIG5_CHARSET - 136
    ; |$DEFAULT_CHARSET - 1
    ; |$EASTEUROPE_CHARSET - 238
    ; |$GB2312_CHARSET - 134
    ; |$GREEK_CHARSET - 161
    ; |$HANGEUL_CHARSET - 129
    ; |$MAC_CHARSET - 77
    ; |$OEM_CHARSET - 255
    ; |$RUSSIAN_CHARSET - 204
    ; |$SHIFTJIS_CHARSET - 128
    ; |$SYMBOL_CHARSET - 2
    ; |$TURKISH_CHARSET - 162
    ; |$VIETNAMESE_CHARSET - 163
    ; $iLcid - see http://www.microsoft.com/globaldev/reference/lcid-all.mspx (Optional)
    ; $iSCF - $SCF_-Constant (see http://msdn.microsoft.com/en-us/library/…28VS.85%29.aspx) (Optional)
    ; Return values .: Success - True
    ; Failure - False and sets @error:
    ; |101 - $hWnd is not a handle
    ; |102 - $iPoints is not a positive number
    ; |103 - $sName is not alphabetic
    ; |104 - $iLcid is not a number
    ; Author ........: Chris Haslam (c.haslam)
    ; Modified.......: Prog@ndy
    ; Remarks .......: If a parameter is omitted (or is Default), the value is unchanged
    ; Related .......: _GUICtrlRichEdit_GetFont
    ; Link ..........: @@MsdnLink@@ EM_SETCHARFORMAT, @@MsdnLink@@ LOGFONT, http://www.hep.wisc.edu/~pinghc/books/…/l/logfont.html
    ; Example .......: Yes
    ; ===============================================================================================================================
    Func _GUICtrlRichEdit_SetFontEx($hWnd, $iPoints = Default, $sName = Default, $iCharset = Default, $iLcid = Default, $iSCF=$SCF_SELECTION)
    ; MSDN does not give a mask (CFM) for bPitchAndFamily so it appears that it cannot be set => omitted here
    Local $iDwMask = 0

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

    If Not IsHWnd($hWnd) Then Return SetError(101, 0, False)
    If Not ($iPoints = Default Or __GCR_IsNumeric($iPoints, ">0")) Then Return SetError(102, 0, False)
    If $sName <> Default Then
    Local $as = StringSplit($sName, " ")
    For $i = 1 To UBound($as) - 1
    If Not StringIsAlpha($as[$i]) Then Return SetError(103, 0, False)
    Next
    EndIf
    If Not ($iCharset = Default Or __GCR_IsNumeric($iCharset)) Then Return SetError(104, 0, False)
    If Not ($iLcid = Default Or __GCR_IsNumeric($iLcid)) Then Return SetError(105, 0, False)

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

    Local $tCharFormat = DllStructCreate($tagCHARFORMAT2)
    DllStructSetData($tCharFormat, 1, DllStructGetSize($tCharFormat))

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

    If $iPoints <> Default Then
    $iDwMask = $CFM_SIZE
    DllStructSetData($tCharFormat, 4, Int($iPoints * 20))
    EndIf
    If $sName <> Default Then
    If StringLen($sName) > $LF_FACESIZE - 1 Then SetError(-1, 0, False)
    $iDwMask = BitOR($iDwMask, $CFM_FACE)
    DllStructSetData($tCharFormat, 9, $sName)
    EndIf
    If $iCharset <> Default Then
    $iDwMask = BitOR($iDwMask, $CFM_CHARSET)
    DllStructSetData($tCharFormat, 7, $iCharset)
    EndIf
    If $iLcid <> Default Then
    $iDwMask = BitOR($iDwMask, $CFM_LCID)
    DllStructSetData($tCharFormat, 13, $iLcid)
    EndIf
    DllStructSetData($tCharFormat, 2, $iDwMask)

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

    Local $iRet = _SendMessage($hWnd, $EM_SETCHARFORMAT, $iSCF, DllStructGetPtr($tCharFormat), 0, "wparam", "ptr")
    If Not $iRet Then Return SetError(@error + 200, 0, False)
    Return True
    EndFunc ;==>_GUICtrlRichEdit_SetFontEx

    [/autoit]