SHARE
TWEET

format text in win32 rich edit

r00m Jun 7th, 2011 80 Never
  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);
RAW Paste Data
Top