MFC之CRichEdit改變指定區域的背景色和字體

MFC之CRichEdit改變指定區域的背景色和字體          注: m_richedit1表明ID爲IDC_RICHEDIT1的CRichEditCtrl控件的control類型的變量 1. 如何使用richedit 添加AfxInitRichEdit();        CxxxApp::InitInstance()         {              AfxInitRichEdit();           .............        }    AfxInitRichEdit()功能:裝載 RichEdit 1.0 Control (RICHED32.DLL).   2. 改變richedit指定區域的文字顏色及字體         CHARFORMAT cf;         ZeroMemory(&cf, sizeof(CHARFORMAT));         cf.cbSize = sizeof(CHARFORMAT);         cf.dwMask = CFM_BOLD | CFM_COLOR | CFM_FACE |                             CFM_ITALIC | CFM_SIZE | CFM_UNDERLINE;         cf.dwEffects = 0;         cf.yHeight = 12*12;//文字高度         cf.crTextColor = RGB(200, 100, 255); //文字顏色         strcpy(cf.szFaceName ,_T("隸書"));//設置字體         m_richedit1.SetSel(1, 5); //設置處理區域         m_richedit1.SetSelectionCharFormat(cf);   3.  改變richedit指定區域的文字背景顏色         CHARFORMAT2 cf; //聲明爲CHARFORMAT2結構,詳細見MSDN         ZeroMemory(&cf, sizeof(CHARFORMAT2));         cf.cbSize = sizeof(CHARFORMAT2);         cf.dwMask = CFM_BACKCOLOR;          cf.crBackColor=RGB(0, 255, 0); //背景顏色爲綠色          m_richedit1.SetSel(0, 2); //設置處理區域         m_richedit1.SendMessage(EM_SETCHARFORMAT,SCF_SELECTION,(LPARAM)&cf);
相關文章
相關標籤/搜索