Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

format text in win32 rich edit

By: r00m on Jun 7th, 2011  |  syntax: C++  |  size: 0.56 KB  |  views: 66  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. HWND hEdit1 = GetDlgItem(g_hWnd, IDC_MAIN_EDIT);
  2.  
  3. // get string lengths
  4. int selStart = GetWindowTextLength(hEdit1);
  5. int selEnd = selStart + strlen(buffer) + 8;
  6.  
  7. // this calls the function to insert data before formating
  8. insertMessage((HWND) hWnd, buffer);
  9.  
  10. CHARRANGE cr;
  11. cr.cpMin = selStart;
  12. cr.cpMax = selEnd;
  13. SendMessage(hEdit1, EM_EXSETSEL, 0, (LPARAM)&cr);
  14.  
  15. CHARFORMAT2 cf;
  16. memset( &cf, 0, sizeof cf );
  17. cf.cbSize = sizeof(cf);
  18. cf.dwMask = CFM_COLOR;
  19. cf.crTextColor = RGB(255,0,0);
  20.  
  21. SendMessage(hEdit1, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);