1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
void RichEditControl::AppendText(char *text, bool isBold, bool isItalic,
bool isUnderlined, COLORREF color, char *font, long fontHeight )
{
CHARFORMAT cf;
ZeroMemory(&cf,sizeof(cf));
cf.cbSize=sizeof(cf);
SendMessage(hRichEditWnd, EM_GETCHARFORMAT, SCF_ALL, (LPARAM)&cf);
DWORD dwEf = 0;
if(isBold) dwEf = CFE_BOLD;
if(isItalic)dwEf = dwEf | CFE_ITALIC;
if(isUnderlined) dwEf = dwEf | CFE_UNDERLINE;
cf.crTextColor = color;
if(font != NULL)
{
lstrcpy(cf.szFaceName,font);
}
cf.yHeight = fontHeight;
cf.dwMask = CFM_UNDERLINE | CFM_COLOR | CFM_BOLD |CFM_ITALIC | CFM_FACE | CFM_SIZE ;
cf.dwEffects = dwEf;
CHARRANGE cr;
cr.cpMin = GetWindowTextLength (hRichEditWnd);
cr.cpMax = cr.cpMin + strlen(text);
SendMessage(hRichEditWnd, EM_EXSETSEL, 0, (LPARAM)&cr);
SendMessage(hRichEditWnd,EM_SETCHARFORMAT,SCF_SELECTION, (LPARAM) &cf);
SendMessage (hRichEditWnd, EM_REPLACESEL, 0, (LPARAM) ((LPSTR) text));
}
| |