这种效果,得到你这10个金钱不容易,我敲了这么多代码,不容易呀,好久没有敲这么多au3代码了。
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <SendMessage.au3>
#include <EditConstants.au3>
#include <GuiRichEdit.au3>
Global $hGui, $hRichText
$hGui = GUICreate("Colored Text", 300, 200)
$hRichText = _RichText_Create($hGui, 0, 0, 290, 190)
_RichText_InsertText($hRichText, "成成爆成爆")
GUISetState()
_RichText_SetSel($hRichText, 0, 1)
_RichText_SetColor($hRichText, 0x0000FF, True)
_RichText_SetSel($hRichText, 2, 3)
_RichText_SetColor($hRichText, 0x00FF00, True)
_RichText_SetSel($hRichText, 4, 5)
_RichText_SetColor($hRichText, 0xFF0000, True)
_RichText_SetSel($hRichText, 0, 0)
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Func _RichText_Create($hGui, $iLeft, $iTop, $iWidth, $iHeight, $sStyle = 0, $sExStyle = 0)
Local $hRichEdit, $sDefStyle, $hLib
If Not IsHWnd($hGui) Then $hGui = HWnd($hGui)
$sDefStyle = BitOR($WS_CHILD, $WS_VISIBLE, $WS_CLIPSIBLINGS)
If $sStyle <> -1 Then $sDefStyle = BitOR($sDefStyle, $ES_WANTRETURN, $ES_NOHIDESEL, $WS_HSCROLL, $WS_VSCROLL, $ES_MULTILINE)
$hLib = DllCall("kernel32.dll", "long", "LoadLibrary", "str", "RichEd20.dll")
If Not @error Then $hLib = $hLib[0]
$hRichEdit = DllCall("user32.dll", "long", "CreateWindowEx", "long", $sExStyle, "str", "RichEdit20A", "str", "", _
"long", $sDefStyle, "long", $iLeft, "long", $iTop, "long", $iWidth, "long", $iHeight, _
"hwnd", $hGui, "long", 0, "hwnd", $hGui, "long", 0)
If Not @error Then
_WinAPI_SetFont($hRichEdit[0], _WinAPI_GetStockObject($DEFAULT_GUI_FONT))
Return $hRichEdit[0]
Else
SetError(1, 1, 1)
EndIf
Return 0
EndFunc
Func _RichText_InsertText($hRichEdit, $sText = "")
Local $lResult, $tStruct
If Not IsHWnd($hRichEdit) Then $hRichEdit = HWnd($hRichEdit)
$tStruct = DllStructCreate("dword;uint")
DllStructSetData($tStruct, 1, $ST_SELECTION)
DllStructSetData($tStruct, 2, $CP_ACP)
Return _SendMessage($hRichEdit, $EM_SETTEXTEX, DllStructGetPtr($tStruct), $sText, 0, "ptr", "str")
EndFunc
Func _RichText_SetSel($hRichEdit, $iStart, $iEnd)
Local Const $EM_HIDESELECTION = ($WM_USER + 63)
If Not IsHWnd($hRichEdit) Then $hRichEdit = HWnd($hRichEdit)
_SendMessage($hRichEdit, $EM_SETSEL, $iStart, $iEnd)
_SendMessage($hRichEdit, $EM_HIDESELECTION, 0)
EndFunc
Func _RichText_SetColor($hWnd, $hColor, $iSelec = True)
Local $tCharFormat, $pCharFormat
$tCharFormat = DllStructCreate("uint cbSize;int dwMask;dword dwEffects;long yHeight;long yOffset;uint crTextColor;" _
& "byte bCharSet;byte bPitchAndFamily;char szFaceName[32];ushort wWeight;short sSpacing;uint crBackColor;uint lcid;dword dwReserved;short sStyle;ushort wKerning" _
& ";byte bUnderlineType;byte bAnimation;byte bRevAuthor;byte bReserved1")
DllStructSetData($tCharFormat, "cbSize", DllStructGetSize($tCharFormat))
DllStructSetData($tCharFormat, "dwMask", 0x40000000)
DllStructSetData($tCharFormat, "crTextColor", $hColor)
$pCharFormat = DllStructGetPtr($tCharFormat)
Return _SendMessage($hWnd, $WM_USER + 68, $iSelec, $pCharFormat)
EndFunc
|