我想寫一個能在 Rich Edit Controller 中 ,任意改變某些文字的背景顏色的程式.即給 (座標,背景顏色) 便可由程式來做.
下列程式,不曉得那裡錯了,煩請指正,謝謝!
Type LogFont
lfHeight As Long
lfWidth As Long
lfEscapement As Long
lfOrientation As Long
lfWeight As Long
lfItalic As Byte
lfUnderline As Byte
lfStrikeOut As Byte
lfCharSet As Byte
lfOutPrecision As Byte
lfClipPrecision As Byte
lfQuality As Byte
lfPitchAndFamily As Byte
lfFaceName(LF_FACESIZE - 1) As Byte
End Type
Public nfont As LogFont
Type Charformat2
cbsize As Long
dwMask As Long
dwEffects As Long
yHeight As Long
yOffset As Long
crTextColor As Long
bCharSet As Byte
bPitchAndFamily As Byte
szFaceName(LF_FACESIZE - 1) As Byte
wWeight As Integer
sSpacing As Integer
crBackColor As Long
lcid As Long
dwReserved As Long
sStyle As Integer
wKerning As Integer
bUnderlineType As Byte
bAnimation As Byte
bRevAuthor As Byte
bReserved1 As Byte
End Type
Public Sub SetCharFormat(ByVal ObjHwnd As Long, ByVal TextColor As Long, ByVal Bkcolor As Long)
Dim result As Long, Charformat As Charformat2
Dim FaceName As String
Charformat.cbsize = LenB(Charformat)
result = SendMessage(ObjHwnd, EM_GETCHARFORMAT, 1&, Charformat)
Const SET_Mask = CFM_COLOR Or CFM_BACKCOLOR
Charformat.cbsize = LenB(Charformat)
Charformat.dwMask = SET_Mask
Charformat.crTextColor = TextColor
Charformat.crBackColor = Bkcolor
result = SendMessage(ObjHwnd, EM_SETCHARFORMAT, SCF_SELECTION, Charformat)
End Sub
然後在Command1 中 Call SetCharFormat(text1.hwnd,&hff,&hff00)