0

I am trying to achieve something similar to domain highlighting. I want part of my text in rich edit box to to be of different colour like we have in domain highlighting feature of IE.

Issue : I know we have to first use EM_EXSETSEL to select the required text and then apply EM_SETCHARFORMAT.

EM_EXSETSEL perform the required operation and required text get selected properly. However , when i execute the EM_SETCHARFORMAT , no change happens in the selected text.

Window is created using RICHEDIT_CLASS .

Any help would be appreciated.

Coding Mash
  • 3,338
  • 5
  • 24
  • 45

1 Answers1

0

How about something like this (to set bold, red text on the current selection):

   // Set up the CHARFORMAT structure
   CHARFORMAT cfm;
   cfm.cbSize = sizeof(cfm);    // Don't forget this!

   // Get char format
   ::SendMessage(hWnd, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&cfm);

   // Set the new effects
   cfm.dwEffects   = CFE_BOLD;
   cfm.crTextColor = RGB(255,0,0);
   cfm.dwMask      = CFM_BOLD | CFM_COLOR;

   // Set the new format
   ::SendMessage(hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cfm);

where hWnd is the window handle of the Rich Edit control.

If not... then post some code, so we can see where you might be going wrong...

Liam
  • 1,472
  • 1
  • 10
  • 14
  • I dont have access to code right now..but i can share the details.... As i listed that i required editing for Windowless operation ...so i am using Txsendmessage instead... Could you please suggest the reason to use EM_GETCHARFORMAT before SET call... my code is something like this cfm.dwEffects = 0; cfm.crTextColor = RGB(255,0,0); cfm.dwMask = FM_COLOR; // Set the new format ::SendMessage(hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cfm); do we need to exectue any more message to view the changed text color.. – user1842327 Nov 21 '12 at 15:47
  • 1
    No reason to use EM_GETCHARFORMAT first, this is cribbed from some of my code where I read the charformat, then checked to see if the proposed format was actually changing it to save time otherwise. The only thing I can think of is that it's probably a good idea to `memset(&cfm, 0, sizeof(cfm));` first, and you need to set the size: `cfm.cbSize = sizeof(cfm);` (if Windows doesn't recognize the size, because it's not initialized, it might just ignore you) – Liam Nov 21 '12 at 15:56
  • sorry i missed that thing....this is part of my code.... Also , i am using charformat2 structure instead of charformat – user1842327 Nov 21 '12 at 16:02
  • Never used windowless rich edit controls or TxSendMessage, sorry... not sure I can help more... – Liam Nov 21 '12 at 16:21