The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: lingo on October 17, 2008, 02:52:14 PM

Title: Easy question about RichEdit control
Post by: lingo on October 17, 2008, 02:52:14 PM
How can we get the color of a selected text in a rich edit control?
After  EM_GETCHARFORMAT I have zero in the field crTextColor
of the CHARFORMAT struc.
The CFE_AUTOCOLOR character effect is NOT specified and the color
of selected text (just one symbol) is different from the color used by
the rich edit control... :wink





Title: Re: Easy question about RichEdit control
Post by: jj2007 on October 17, 2008, 03:19:40 PM
This works fine for me.

GetSelCol MACRO ctype:=<0>
  ifidn <ctype>, <1>
   mov eax, CFM_BACKCOLOR
  else
   mov eax, CFM_COLOR
  endif
  call GetTxtCol
  EXITM <eax>
ENDM

   MsgBox hex$(GetSelCol(0)), hex$(GetSelCol(1)), MB_OK

GetTxtCol proc
LOCAL charfmt:CHARFORMAT2
  m2m charfmt.cbSize, sizeof CHARFORMAT2
  mov charfmt.dwMask, eax
  push eax
  invoke SendMessage, hRichEdit, EM_GETCHARFORMAT, SCF_SELECTION, ADDR charfmt
  pop eax
  .if eax==CFM_COLOR
   mov eax, charfmt.crTextColor
  .else
   mov eax, charfmt.crBackColor
  .endif
  ret
GetTxtCol endp
Title: Re: Easy question about RichEdit control
Post by: lingo on October 17, 2008, 05:07:07 PM
Thanks,the problem is solved :wink