I have been fascinated at the number of serious bugs in the later rich edit controls, to effectively gain the multilevel undo there appears to be a massive number of workarounds to get it to work predictably. Here is the latest.
mov cfm.cbSize, sizeof CHARFORMAT
mov cfm.dwMask, CFM_COLOR
m2m cfm.crTextColor, qes.txtcolour
invoke PostMessage,hEdit,EM_SETCHARFORMAT,SCF_ALL,ADDR cfm
This code more or less works fine locally until you pass the data to another instance with the HWND_BROADCAST handle and some of the time it works but other times it drops the text colour. The back colour changes fine as do all of the other settings but this message is unreliable.
Hutch,
This works fine for me, under all circumstances. Why are you using PostMessage?
SetSelFormat proc CharFt:DWORD, CharFtMask:DWORD
LOCAL charfmt:CHARFORMAT2
call ClearLocals
inc CtChgFormat
mov charfmt.cbSize, sizeof CHARFORMAT2
mrm charfmt.dwMask, CharFtMask
mrm charfmt.crTextColor, CharFt
sm hRE, EM_GETCHARFORMAT, SCF_SELECTION, ADDR charfmt
mov eax, CharFt
.if CharFtMask==CFM_COLOR
.if charfmt.crTextColor==eax
invoke GetSysColor, COLOR_WINDOWTEXT
.endif
mov charfmt.crTextColor, eax
mov eax, CFE_AUTOCOLOR
or charfmt.dwEffects, eax ; get rid of CFE_AUTOCOLOR
xor charfmt.dwEffects, eax
.elseif CharFtMask==CFM_BACKCOLOR
.if charfmt.crBackColor==eax
invoke GetSysColor, COLOR_WINDOW
.endif
mov charfmt.crBackColor, eax
mov eax, CFE_AUTOBACKCOLOR
or charfmt.dwEffects, eax ; get rid of CFE_AUTOBACKCOLOR
xor charfmt.dwEffects, eax
.elseif CharFtMask==CFM_SIZE
or CharFtMask, CFM_FACE
mov ecx, offset MyFont ; sizing not possible with SysFont
.if charfmt.yHeight==eax
mov eax, SizeNormal
mov ecx, offset SysFont
.endif
mov charfmt.yHeight, eax
invoke lstrcpy, addr charfmt.szFaceName, ecx ; max 32 chars
.else
xor charfmt.dwEffects, eax ; sending twice toggles... in theory!
.endif
; sm=invoke SendMess...
; hRE=handle RichEd
sm hRE, EM_SETCHARFORMAT, SCF_SELECTION, ADDR charfmt
ret
SetSelFormat endp
JJ,
Its not the single instance that is the problem and Sendmessage works OK there, its when you send a HWND_BROADCAST message to all instances of the editor that at least some of them some of the time do not update the text colour. PostMessage helped a little and SleepEx helped a little more but it seems to be a timing issue in richedit from getting too many messages at the same time.
I am approaching the problem in a different way.
Quote from: hutch-- on July 04, 2008, 12:15:14 AM
I have been fascinated at the number of serious bugs in the later rich edit controls
Just spent half an evening trying to find a workaround for the fact that EM_GETTEXTRANGE returns a buffer that delimits lines with
0D instead of
0D0A. I guess it's by design :boohoo:
(actually, I am absolutely sure it's by design. Why waste precious disk space for line feeds?)