Advertisement
r00m

format text in win32 rich edit

Jun 7th, 2011
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  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);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement