html设置字体facename,CRichEdit控件操作使用
一般性問題
1.??? 代碼編譯通過了,運(yùn)行后RichEdit控件不顯示,在InitInstance中添加
BOOL CWinApp::InitInstance ()
{
…
AfxInitRichEdit(); - RichEdit 1.0
或 AfxInitRichEdit2(); - RichEdit 2.0
…
}
2.??? 升級默認(rèn)的RichEdit版本,默認(rèn)的版本有BUG,在InitInstance中添加
BOOL CWinApp::InitInstance ()
{
…
LoadLibrary("RICHED20.DLL");
…
FreeLibrary();
}
如果是CRichEditView基類的話,可用如下消息機(jī)制:
BOOL CRichEditView::PreCreateWindow(CREATESTRUCT& cs)
{
if (LoadLibraryA("RICHED20.DLL") == NULL)
{
AfxMessageBox(_T("Fail to load /"riched20.dll/"."),MB_OK | MB_ICONERROR);
PostMessage(WM_QUIT,0,0);
return FALSE;
}
m_strClass = RICHEDIT_CLASSA;
return CRichEditView::PreCreateWindow(cs);
}
3.??? 在RichEdit控件的輸入框中最后追加一行
CRichEditCtrl.SetSel(-1, -1);
CRichEditCtrl.ReplaceSel((LPCTSTR)str);
4.??? 限制RichEdit控件的字?jǐn)?shù)
CRichEditCtrl.LimitText(long nChars)
5.??? 設(shè)置RichEdit控件的換行切換
如果是CRichEditView基類的話,可用如下消息機(jī)制:
BOOL CRichEditView::OnInitialUpdate()
{
…
m_nWordWrap = WrapNone;
WrapChanged();
…
}
如果是在Dialog,可使用SetTargetDevice,并在RichEdit的屬性里面加上want return
CRichEditCtrl.SetTargetDevice(m_dcTarget, GetPrintWidth());
WrapChanged實(shí)際上也是調(diào)用
CRichEditCtrl.SetTargetDevice(NULL, 0); //m_nWordWrap == WrapToWindow
CRichEditCtrl.SetTargetDevice(NULL, 1); //m_nWordWrap == WrapNone
CRichEditCtrl.SetTargetDevice(NULL, 2);// m_nWordWrap == WrapToTargetDevice
6.??? 設(shè)置RichEdit控件不帶格式的數(shù)據(jù)粘貼
CRichEditCtrl.PasteSpecial(CF_TEXT);
7.??? 設(shè)置RichEdit控件的滾動條自動隨輸入滾動到最后一行
int nFirstVisible = CRichEditCtrl.GetFirstVisibleLine();
if (nFirstVisible > 0)
{
CRichEditCtrl.LineScroll(-nFirstVisible, 0);
}
或CRichEditCtrl.PostMessage(WM_VSCROLL, SB_BOTTOM, 0);
8.設(shè)置RichEdit控件的撤銷輸入次數(shù)(只能用在RICHED20以上)
SendMessage(EM_SETTEXTMODE, TM_MULTILEVELUNDO, 0);
SendMessage(EM_SETUNDOLIMIT, 100, 0);
TM_MULTILEVELUNDO 支持多取消(默認(rèn)值),可通過EM_SETUNDOLIMIT設(shè)置最大次數(shù)
9.設(shè)置RichEdit控件的OnChange事件
EM_SETEVENTMASK 設(shè)置 ENM_CHANGE
long lMask = GetEventMask();
lMask |= ENM_CHANGE;
lMask &= ~ENM_PROTECTED;
SetEventMask(lMask);
10.設(shè)置RichEdit控件的只讀屬性
CRichEditCtrl::SetReadOnly(BOOL bReadOnly = TRUE );
通過設(shè)置PROTECTED實(shí)現(xiàn)選中的文本只讀,參見如下文章:
http://www.codeguru.com/Cpp/controls/richedit/article.php/c2401/
函數(shù)應(yīng)用
1. 設(shè)置RichEdit控件的顯示字體
CHARFORMAT cf;
ZeroMemory(&cf, sizeof(CHARFORMAT));
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask|=CFM_BOLD;
cf.dwEffects|=CFE_BOLD; //粗體,取消用cf.dwEffects&=~CFE_BOLD;
cf.dwMask|=CFM_ITALIC;
cf.dwEffects|=CFE_ITALIC; //斜體,取消用cf.dwEffects&=~CFE_ITALIC;
cf.dwMask|=CFM_UNDERLINE;
cf.dwEffects|=CFE_UNDERLINE; //斜體,取消用cf.dwEffects&=~CFE_UNDERLINE;
cf.dwMask|=CFM_COLOR;
cf.crTextColor = RGB(255,0,0); //設(shè)置顏色
cf.dwMask|=CFM_SIZE;
cf.yHeight =200; //設(shè)置高度
cf.dwMask|=CFM_FACE;
strcpy(cf.szFaceName ,_T("隸書")); //設(shè)置字體
CRichEditCtrl.SetSelectionCharFormat(cf);
2.設(shè)置RichEdit控件的顯示字體的行間距(只能用在RICHED20以上)
PARAFORMAT2 pf;
pf.cbSize = sizeof(PARAFORMAT2);
pf.dwMask = PFM_NUMBERING | PFM_OFFSET;
pf.wNumbering = PFN_BULLET; //注意PFM_NUMBERING
pf.dxOffset = 10;
VERIFY(SetParaFormat(pf));
常用的dwMask有如下列表:
PFM_NUMBERING 成員 wNumbering 才起作用
1 項(xiàng)目符號,默認(rèn)用PFN_BULLET.
2 使用阿拉伯?dāng)?shù)字 (1, 2, 3, ...).
3 使用小寫字母 (a, b, c, ...).
4 使用大寫字母 (A, B, C, ...).
5 使用小寫羅馬數(shù)字 (i, ii, iii, ...).
6 使用大寫羅馬數(shù)字 (I, II, III, ...).
7 自定義,字符見成員 wNumberingStart.
PFM_OFFSET 成員 dxOffset 才起作用,縮進(jìn),單位twips
PFM_STARTINDENT 成員 dxStartIndent 才起作用,首行縮進(jìn)
PFM_SPACEAFTER 成員 dySpaceAfter 才起作用,段間距
PFM_LINESPACING 成員 dyLineSpacing 才起作用,行間距
3.設(shè)置RichEdit控件的透明背景(只能用在RICHED20以上)
long style = ::GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE);
style &= WS_EX_TRANSPARENT;
::SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, style);
或 CreateEx(),然后把WS_EX_TRANSPARENT樣式加上
4.獲取或者寫入RichEdit控件的內(nèi)容
GetWindowText
使用EM_GETTEXTEX
GETTEXTEX gt;
gt.cb = 200;
gt.flags = GT_DEFAULT;
gt.codepage = CP_ACP ;
gt.lpDefaultChar = NULL;
gt.lpUsedDefChar = NULL;
SendMessage(EM_GETTEXTEX,(WPARAM)>,(LPARAM)text);
StreamOut(主要用于RTF等格式輸出)
static DWORD CALLBACK;
MyStreamOutCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
CFile* pFile = (CFile*) dwCookie;
pFile->Write(pbBuff, cb);
*pcb = cb;
return 0;
}
CFile cFile(TEXT("myfile.rtf"), CFile::modeCreate|CFile::modeWrite);
EDITSTREAM es;
es.dwCookie = (DWORD) &cFile; //設(shè)置用例參數(shù),以便回調(diào)函數(shù)調(diào)用
es.pfnCallback = MyStreamOutCallback;
pmyRichEditCtrl->StreamOut(SF_RTF, es);
讀入可以此類推,SetWindowText, EM_SETTEXTEX, StreamIn
5.查找RichEdit控件中的字符串
FINDTEXTEX ft;
ft.chrg.cpMin = 0;
ft.chrg.cpMax = -1;
ft.lpstrText = "|";
long lPos = FindText(0, &ft);
如果要繼續(xù)查找,修改cpMin,如
int nCount = 0;
do
{
long lPos = GetRichEditCtrl().FindText(0, &ft);
if( -1 == lPos) break;
ft.chrg.cpMin = lPos + strlen(ft.lpstrText);
++nCount;
}while(TRUE);
6. 以Html格式保存RichEdit控件中的內(nèi)容
臨時(shí)做法可先轉(zhuǎn)為RTF格式,再通過RTF-to-HTML Converter,參考如下文章:
http://www.codeguru.com/Cpp/controls/richedit/conversions/article.php/c5377/
8.??? 重載OnProtected函數(shù)以得到RichEdit對應(yīng)的消息,如粘貼等
void CRichEditorView::OnProtected(NMHDR* pNMHDR, LRESULT* pResult)
{
ENPROTECTED* pEP = (ENPROTECTED*)pNMHDR;
switch (pEP->msg)
{
case WM_KEYDOWN: //按鍵,判斷pEP->wParam
case WM_PASTE: //粘貼
case WM_CUT: //剪切
case EM_SETCHARFORMAT:
default:
break;
};
*pResult = FALSE;
}
聊天常用
1. 設(shè)置RichEdit控件的鏈接功能(只能用在RICHED20以上)
LoadLibrary(_T("Riched20.dll"));
創(chuàng)建RichEdit2.0控件
CreateEx(0, _T("RichEdit20A"), NULL, WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_TABSTOP
|ES_READONLY|ES_WANTRETURN|ES_MULTILINE, rect.left, rect.top, cx, cy, pParentWnd->m_hWnd, (HMENU)nID, NULL);
設(shè)置選中的文字為鏈接顯示
CHARFORMAT2 cf2;
ZeroMemory(&cf2, sizeof(CHARFORMAT2));//
cf2.cbSize = sizeof(CHARFORMAT2);
cf2.dwMask = CFM_LINK;
cf2.dwEffects |= CFE_LINK;
m_cRichEdit.SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf2);
支持鏈接的點(diǎn)擊響應(yīng)
m_cRichEdit.SetEventMask(ENM_LINK);
響應(yīng)鏈接的點(diǎn)擊EN_LINK
BEGIN_MESSAGE_MAP(CMyRichEdit, CRichEditCtrl)
ON_NOTIFY_REFLECT(EN_LINK, OnURL)
END_MESSAGE_MAP()
......
void CMyRichEdit::OnURLClick(NMHDR *pNmhdr, LRESULT *pResult)
{
TCHAR LinkChar[512];
ENLINK *pLink = (ENLINK *)pNmhdr;
if (pLink->msg == WM_LBUTTONUP)
{
SetSel(penLink->chrg); //這是鏈接的文字范圍
long Res = GetSelText((char *)LinkChar); //這是鏈接文字
…
}
}
自動識別鏈接
UINT nMask = SendDlgItemMessage(IDC_RICHEDIT_MESSAGE, EM_GETEVENTMASK, 0, 0);
SendDlgItemMessage(IDC_RICHEDIT_MESSAGE, EM_SETEVENTMASK, 0, nMask | NM_LINK);
SendDlgItemMessage(IDC_RICHEDIT_MESSAGE, EM_AUTOURLDETECT, TRUE, 0);
BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
NMHDR* pNmHdr = (NMHDR *)lParam;
if(pNmHdr->idFrom == IDC_RICHEDIT_MESSAGE && pNmHdr->code == EN_LINK)
{
ENLINK *pLink = (ENLINK *)lParam;
if (pLink->msg == WM_LBUTTONDOWN)
{
SendDlgItemMessage(IDC_RICHEDIT_MESSAGE, EM_EXSETSEL, 0, (LPARAM)&(pLink->chrg));
ShellExecute(GetSafeHwnd(), "open", m_wndREMessage.GetSelText(), 0, 0, SW_SHOWNORMAL);
}
}
return CDialog::OnNotify(wParam, lParam, pResult);
}
2.在RichEdit中插入位圖
參考如下文章:
http://www.codeguru.com/Cpp/controls/richedit/article.php/c2417/
http://www.codeguru.com/Cpp/controls/richedit/article.php/c5383/
自定義在RichEdit中插入對象的圖標(biāo)
http://www.blogcn.com/user3/jiangsheng/blog/1319738.html
http://www.codeguru.com/richedit/richeditrc.html
3.在RichEdit顯示GIF動畫
常用的是通過QQ的imageole.dll(也有用Gif89.dll的)
http://www.xiaozhou.net/cooldog/blogview.asp?logID=82
http://www.codeproject.com/richedit/AnimatedEmoticon.asp
在richedit控件中插入動態(tài)GIF(Native C++版)
http://blog.joycode.com/jiangsheng/archive/2004/12/15/41209.aspx
4.IRichEditOleCallback的使用
http://61.186.252.131/Expert/topic/905/905844.xml?temp=.8379022
5.類似MSN信息發(fā)送框的制作(上)
http://www.vckbase.com/document/viewdoc/?id=1087
內(nèi)容包含:實(shí)現(xiàn)右鍵菜單,圖片插入,讀取/寫入RTF格式字符串
6.自定義RichEdit控件
http://www.vckbase.com/document/viewdoc/?id=328
內(nèi)容包含:鼠標(biāo)右鍵消息,消息映射,字體變換
轉(zhuǎn)載】MFC中的CEdit與CRichEdit使用技巧2008-03-14 15:41VC中在對話框上使用Rich Edit控件前一定要用AfxInitRichEdit()初
始化RichEdit環(huán)境.
--------------------------------------------------------------------------------
1.設(shè)置edit只讀屬性
方法一:
m_edit1.SetReadOnly(TRUE);
方法二:
::SendMessage(m_edit1.m_hWnd, EM_SETREADONLY, TRUE, 0);
--------------------------------------------------------------------------------
2.判斷edit中光標(biāo)狀態(tài)并得到選中內(nèi)容(richedit同樣適用)
int nStart, nEnd;
CString strTemp;
m_edit1.GetSel(nStart, nEnd);
if(nStart == nEnd)
{
strTemp.Format(_T("光標(biāo)在%d"), nStart);
AfxMessageBox(strTemp);
}
else
{
//得到edit選中的內(nèi)容
m_edit1.GetWindowText(strTemp);
strTemp = strTemp.Mid(nStart) - strTemp.Mid(nEnd);
AfxMessageBox(strTemp);
}
注:GetSel后,如果nStart和nEnd,表明光標(biāo)處于某個(gè)位置(直觀來看就是光標(biāo)在閃動);
如果nStart和nEnd不相等,表明用戶在edit中選中了一段內(nèi)容。
--------------------------------------------------------------------------------
3.在edit最后添加字符串
CString str;
m_edit1.SetSel(-1, -1);
m_edit1.ReplaceSel(str);
--------------------------------------------------------------------------------
4.隨輸入自動滾動到最后一行(richedit同樣適用)
方法一:(摘自msdn)
// The pointer to my edit.
extern CEdit* pmyEdit;
int nFirstVisible = pmyEdit->GetFirstVisibleLine();
// Scroll the edit control so that the first visible line
// is the first line of text.
if (nFirstVisible > 0)
{
pmyEdit->LineScroll(-nFirstVisible, 0);
}
方法二:
m_richedit.PostMessage(WM_VSCROLL, SB_BOTTOM, 0);
--------------------------------------------------------------------------------
5.如何限制edit輸入指定字符
可以從CEdit派生一個(gè)類,添加WM_CHAR消息映射。下面一個(gè)例子實(shí)現(xiàn)了限定輸入16進(jìn)制字符的功能。
void CMyHexEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if ( (nChar >= '0' && nChar <= '9') ||
(nChar >= 'a' && nChar <= 'f') ||
(nChar >= 'A' && nChar <= 'F') ||
nChar == VK_BACK ||
nChar == VK_DELETE)??? //msdn的virtual key
{
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
}
--------------------------------------------------------------------------------
6.如何使用richedit
添加AfxInitRichEdit();
CxxxApp::InitInstance()
{
AfxInitRichEdit();
.............
}
AfxInitRichEdit()功能:裝載 RichEdit 1.0 Control (RICHED32.DLL).
--------------------------------------------------------------------------------
7.如何使用richedit2.0 or richedit3.0
使用原因:由于RichEdit2.0A自動為寬字符(WideChar),所以它可以解決中文亂碼以及一些漢字問題
方法一:(msdn上的做法,適用于用VC.NET及以后版本創(chuàng)建的工程)
To update rich edit controls in existing Visual C++ applications to version 2.0,
open the .RC file as text, change the class name of each rich edit control from?? "RICHEDIT" to
"RichEdit20a".
Then replace the call to AfxInitRichEdit with AfxInitRichEdit2.
方法二:以對話框?yàn)槔?#xff1a;
(1)??? 增加一全局變量 HMODULE hMod;
(2)??? 在CxxxApp::InitInstance()中添加一句hMod = LoadLibrary(_T("riched20.dll"));
在CxxxApp::ExitInstance()中添加一句FreeLibrary(hMod);
(3)??? 在對話框上放一個(gè)richedit,文本方式打開.rc文件修改該richedit控件的類名"RICHEDIT" to "RichEdit20a".
(4)??? 在對話框頭文件添加 CRichEditCtrl m_richedit;
在OnInitDialog中添加 m_richedit.SubclassDlgItem(IDC_RICHEDIT1, this);
--------------------------------------------------------------------------------
8.改變r(jià)ichedit指定區(qū)域的顏色及字體
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("隸書"));//設(shè)置字體
m_richedit1.SetSel(1, 5); //設(shè)置處理區(qū)域
m_richedit1.SetSelectionCharFormat(cf);
--------------------------------------------------------------------------------
9.設(shè)置行間距(只適用于richedit2.0)
PARAFORMAT2 pf;
pf2.cbSize = sizeof(PARAFORMAT2);
pf2.dwMask = PFM_LINESPACING | PFM_SPACEAFTER;
pf2.dyLineSpacing = 200;
pf2.bLineSpacingRule = 4;
m_richedit.SetParaFormat(pf2);
--------------------------------------------------------------------------------
10.richedit插入位圖
--------------------------------------------------------------------------------
11.richedit插入gif動畫
--------------------------------------------------------------------------------
12.richedit嵌入ole對象
--------------------------------------------------------------------------------
13.使richedit選中內(nèi)容只讀
--------------------------------------------------------------------------------
14.打印richedit
--------------------------------------------------------------------------------
15.richeidt用于聊天消息窗口
--------------------------------------------------------------------------------
16.解決richedit的EN_SETFOCUS和EN_KILLFOCUS無響應(yīng)的問題
--------------------------------------------------------------------------------
17.richedit拼寫檢查
--------------------------------------------------------------------------------
18.改變edit背景色
Q117778:How to change the background color of an MFC edit control
http://support.microsoft.com/kb/117778/en-us
--------------------------------------------------------------------------------
19.當(dāng)edit控件的父窗口屬性是帶標(biāo)題欄WS_CAPTION和子窗口WS_CHILD時(shí),不能設(shè)置焦點(diǎn)SetFocus
Q230587:PRB: Can't Set Focus to an Edit Control When its Parent Is an Inactive Captioned Child Window
http://support.microsoft.com/kb/230587/en-us
--------------------------------------------------------------------------------
20. 在Edit中回車時(shí),會退出對話框
選中Edit的風(fēng)格Want Return。
MSDN的解釋如下:
ES_WANTRETURN??? Specifies that a carriage return be inserted when the user presses the ENTER key while entering
text into a multiple-line edit control in a dialog box. Without this style, pressing the ENTER key has the same
effect as pressing the dialog box's default pushbutton. This style has no effect on a single-line edit control.
--------------------------------------------------------------------------------
21. 動態(tài)創(chuàng)建的edit沒有邊框的問題
m_edit.Create(....);
m_edit.ModifyStyleEx(0, WS_EX_CLIENTEDGE, SWP_DRAWFRAME);
--------------------------------------------------------------------------------
22. 一個(gè)能顯示RTF,ole(包括gif, wmv,excel ,ppt)的例子
轉(zhuǎn)自
Environment: VC6 SP4, 2000.
Follow these 10 easy steps to build the OutLookRichEdit control:
Insert a rich edit control into the dialog.
Call AfxInitRichEdit() in the InitInstance of the App class or in InitDialog.
If it does not exist, copy OutLookRichEdit.cpp and OutLookRichEdit.h to the project directory.
Click the menu choice Project-Add to Project-Files and select the above-copied files to add the wrapper class to
your project.
Import the hand cursor into the resource and rename it "IDC_LINK".
Use Classwizard to add a member variable of the rich edit control (CRichEditCtrl).
Include the OutLookRichEdit.h file in the dialog's header file and change the declaration of rich edit member
variable, as in
CRichEditCtrl??? m_ctrlText1;
to
COutLookRichEdit m_ctrlText1;
In InitDialog(), add the following code.
m_ctrlText1.SetRawHyperText(_T("Click
to see the about box."));
At this level, if you build the project and run it, you can see the rich edit control with linked text, but
nothing would happen if you clicked on the link.
To Show a dialog while the link is clicked, you have to add some more code in the dialog class. Before that, have
a closer look at the preceding code and hypertext syntax. The link text is enclosed between the "$" symbols and
the corresponding dialog's resource value 100 (About Box), enclosed in "#" symbols.
You can find the #define values of dialogs in the resource.h file.
Use ClassWizard to map OnNotify of the dialog and write the corresponding implementation code in .cpp file, like:
BOOL CDEMODlg::OnNotify(WPARAM wParam,
LPARAM lParam,
LRESULT* pResult)
{
NMHDR* pNmHdr = (NMHDR*) lParam;
if(IDC_RICHEDIT1 == pNmHdr->idFrom){
switch(pNmHdr->code)
{
case IDD_ABOUTBOX:
CAboutDlg oDlg;
oDlg.DoModal ();
break;
}
}
return CDialog::OnNotify(wParam, lParam, pResult);
}
Now, build and run the project. It is recommended that you set the read-only attribute to the rich edit control.
Downloads
Download demo project - 23 Kb
Download source - 6 Kb
在RichEdit中插入Bitmap
COleDataSource src;
STGMEDIUM sm;
sm.tymed=TYMED_GDI;
sm.hBitmap=hbmp;
sm.pUnkForRelease=NULL;
src.CacheData(CF_BITMAP, &sm);
LPDATAOBJECT lpDataObject =
(LPDATAOBJECT)src.GetInterface(&IID_IDataObject);
pRichEditOle->ImportDataObject(lpDataObject, 0, NULL);
lpDataObject->Release();
字體設(shè)置代碼
最后添加字體變換函數(shù):
CHARFORMAT cf;
LOGFONT lf;
memset(&cf, 0, sizeof(CHARFORMAT));
memset(&lf, 0, sizeof(LOGFONT));
//判斷是否選擇了內(nèi)容
BOOL bSelect = (GetSelectionType() != SEL_EMPTY) ? TRUE : FALSE;
if (bSelect)
{
GetSelectionCharFormat(cf);
}
else
{
GetDefaultCharFormat(cf);
}
//得到相關(guān)字體屬性
BOOL bIsBold = cf.dwEffects & CFE_BOLD;
BOOL bIsItalic = cf.dwEffects & CFE_ITALIC;
BOOL bIsUnderline = cf.dwEffects & CFE_UNDERLINE;
BOOL bIsStrickout = cf.dwEffects & CFE_STRIKEOUT;
//設(shè)置屬性
lf.lfCharSet = cf.bCharSet;
lf.lfHeight = cf.yHeight/15;
lf.lfPitchAndFamily = cf.bPitchAndFamily;
lf.lfItalic = bIsItalic;
lf.lfWeight = (bIsBold ? FW_BOLD : FW_NORMAL);
lf.lfUnderline = bIsUnderline;
lf.lfStrikeOut = bIsStrickout;
sprintf(lf.lfFaceName, cf.szFaceName);
CFontDialog dlg(&lf);
dlg.m_cf.rgbColors = cf.crTextColor;
if (dlg.DoModal() == IDOK)
{
dlg.GetCharFormat(cf);//獲得所選字體的屬性
if (bSelect)
SetSelectionCharFormat(cf);???? //為選定的內(nèi)容設(shè)定所選字體
else
SetWordCharFormat(cf);???????? //為將要輸入的內(nèi)容設(shè)定字體
}
在RichEdit中實(shí)現(xiàn)超鏈接
在RichEdit中實(shí)現(xiàn)超鏈接
責(zé)任編輯:admin 在CBuilder上制作 更新日期:2005-8-6
首先在Form上放置一個(gè)RichEdit。
在窗體的構(gòu)造函數(shù)中添加以下代碼:
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
unsigned mask = SendMessage(RichEdit1->Handle, EM_GETEVENTMASK, 0, 0);
SendMessage(RichEdit1->Handle, EM_SETEVENTMASK, 0, mask | ENM_LINK);
SendMessage(RichEdit1->Handle, EM_AUTOURLDETECT, true, 0);?? //自動檢測URL
RichEdit1->Text = "歡迎訪問C++ Builder/n"
"網(wǎng)址: http://www.ccrun.com/n"
"偶的信箱:/n"
"mailto::info@ccrun.com /n"
"嘿嘿/n";
}
重載窗體的WndProc
1。在.h中添加:
protected:
virtual void __fastcall WndProc(Messages::TMessage &Message);
2。在.cpp中添加:
//---------------------------------------------------------------------------
void __fastcall TMainForm::WndProc(Messages::TMessage &Message)
{
if (Message.Msg == WM_NOTIFY)
{
if (((LPNMHDR)Message.LParam)->code == EN_LINK)
{
ENLINK* p = (ENLINK *)Message.LParam;
if (p->msg == WM_LBUTTONDOWN)
{
SendMessage(RichEdit1->Handle, EM_EXSETSEL, 0, (LPARAM)&(p->chrg));
ShellExecute(Handle, "open", RichEdit1->SelText.c_str(), 0, 0, SW_SHOWNORMAL);
}
}
}
TForm::WndProc(Message);
}
總結(jié)
以上是生活随笔為你收集整理的html设置字体facename,CRichEdit控件操作使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在计算机控制系统中 常常需要设计,微型计
- 下一篇: BIOS 启动类型:Legacy+UEF