Before using the rich Edit Control in the dialog box in VC, you must use afxinitrichedit () to initialize the RichEdit environment. 1. method 1: m_edit1.setreadonly (true); Method 2: sendmessage (m_edit1.m_hwnd, em_setreadonly, true, 0); method 2. determine the cursor status in edit and obtain the selected content (RichEdit is also applicable) int nstart, nend; cstring strtemp; m_edit1.getsel (nstart, nend); If (nstart = nend) {strtemp. format (_ T ("cursor at % d"), nstart); Afxmessagebox (strtemp);} else {// get the content m_edit1.getwindowtext (strtemp) selected by Edit; strtemp = strtemp. mid (nstart)-strtemp. mid (nend); afxmessagebox (strtemp);} Note: After getsel, if nstart and nend indicate that the cursor is in a certain position (intuitively, the cursor is flashing ); if nstart and nend are not equal, the user selects a piece of content in edit. -------------------------------------------------------------------------------- 3. add the string cstring STR; m_edit1.setsel (-1,-1); m_edit1.replacesel (STR); substring 4. method 1: (from msdn) // the pointer to my edit. extern cedit * pmyedit; int nfirstvisible = pmyedit-> getfirstvisibleline (); // scroll the EDI T control so that the first visible line // is the first line of text. if (nfirstvisible> 0) {pmyedit-> linescroll (-nfirstvisible, 0);} Method 2: m_richedit.postmessage (wm_vscroll, sb_bottom, 0); limit 5. how to restrict the edit input to a specified character? A class can be derived from cedit to add the wm_char message ing. The following example provides a limited input of hexadecimal characters. Void cmyhexedit: onchar (uint nchar, uint nrepcnt, uint nflags) {If (nchar> = '0' & nchar <= '9 ') | (nchar> = 'A' & nchar <= 'F ') | nchar = vk_back | nchar = vk_delete) // msdn virtual key {cedit: onchar (nchar, nrepcnt, nflags);} limit 6. how to Use RichEdit to add afxinitrichedit (); cxxxapp: Initinstance () {afxinitrichedit ();.............} afxinitrichedit (): loads RichEdit 1.0 control (riched32.dll ). ------------------------------------------------------------------------------ 7. how to Use richedit2.0 or richedit3.0: Because richedit2.0a is automatically a wide character (widechar), it can solve Chinese garbled characters and some Chinese Character problems. Method 1: (msdn practices are applicable to VC. to update rich edit controls in existing visual c ++ applications to version 2.0, Open. 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. Method 2: Take the dialog box as an example: (1) Add a global variable hmodule hmod; (2) In cxxxapp: initinstance () add a hmod = loadlibrary (_ T ("RICHED20.DLL"); add a freelibrary (hmod) in cxxxapp: exitinstance (); (3) put a RichEdit in the dialog box and open it in text. the RC file modifies the RichEdit control class name "RichEdit" to "rich Edit20a ". (4) add cricheditctrl m_richedit in the header file of the dialog box; add m_richedit.subclassdlgitem (idc_richedit1, this) in oninitdialog; limit 8. change the color and font 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. dweffect S = 0; cf. yheight = 12*12; // text height cf. crtextcolor = RGB (200,100,255); // text color strcpy (cf. szfacename, _ T (""); // set the font m_richedit1.setsel (1, 5); // set the processing area m_richedit1.setselectioncharformat (CF); Limit 9. set row spacing (richedit2.0 only) paraformat2 PF; pf2.cbsize = sizeof (paraformat2); pf2.dwmask = pfm_linespacing | pfm_spaceafter; pf2.dy Linespacing = 200; pf2.blinespacingrule = 4; m_richedit.setparaformat (pf2); limit 10. richEdit insert bitmap q220844: how to insert a bitmap into an RTF document using the RichEdit control in Visual C ++ 6.0 http://support.microsoft.com/default.aspx? SCID = KB; en-US; 220844 http://www.codeguru.com/Cpp/controls/richedit/article.php/c2417/ http://www.codeguru.com/Cpp/controls/richedit/article.php/c5383/ ---------------------------------------------------------------------------- 11. RichEdit insert GIF animation http://www.codeproject.com/richedit/AnimatedEmoticon.asp limit 12. RichEdit embedded Import OLE object http://support.microsoft.com/kb/141549/en-us into 13. Make RichEdit Select Content read-only http://www.codeguru.com/cpp/controls/richedit/article.php/c2401/ into 14. Print RichEdit http://www.protext.com/MFC/RichEdit3.htm ----------------------------------------------- ------------------------------- 15. richeidt used for chat message window http://www.vckbase.com/document/viewdoc? Id = 1087 http://www.codeproject.com/richedit/chatrichedit.asp http://www.codeguru.com/Cpp/controls/richedit/article.php/c2395/ limit 16. Solve RichEdit's en_setfocus and en_killfocus unresponsive problem http://support.microsoft.com/kb/181664/en-us limit 17. RichEdit spelling check http :// Www.codeproject.com/com/autospellcheck.asp ------------------------------------------------------------------------------ 18. change the edit background color q117778: how to change the background color of an MFC Edit Control http://support.microsoft.com/kb/117778/en-us -------------------------------------------------------------------------------- 19. when the parent window property of the edit control includes the title bar ws_caption and the Child Window ws_child, the focus setfocus q230587: PRB cannot be set.: 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 Limit 20. When you press enter in edit, the dialog box will exit and select the edit style want return. The msdn explanation is as follows: 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. m_edit.create (....); m_edit.modifystyleex (0, ws_ex_clientedge, swp_drawframe); -------------------------------------------------------------------------- 22. an example of http://www.codeproject.com/richedit/COleRichEditCtrl.asp that can display RTF, Ole (including GIF, WMV, Excel, PPT) is transferred from http://blog.csdn.net/lixiaosan/archive/2006/04/06/652795.aspx 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 wowould 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 "$" symb OLS 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 onmenty of the dialog and write the corresponding implementation code in. CPP file, like: bool cdemodlg: onnotify (wparam, 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 insert bitmap coledatasource SRC; stgmedium Sm; Sm IN RichEdit. tymed = tymed _ GDI; SM. hbitmap = hbmp; SM. punkforrelease = NULL; SRC. cachedata (cf_bitmap, & sm); lpdataobject = (lpdataobject) SRC. getinterface (& iid_idataobject); pricheditole-> importdataobject (lpdataobject, 0, null); lpdataobject-> release (); Add the font conversion function: charformat CF; logfont lf; memset (& CF, 0, sizeof (charformat); memset (& lf, 0, sizeof (logfont )); // determine whether the content bool bselect = (getselectiontype ()! = Sel_empty )? True: false; If (bselect) {getselectioncharformat (CF);} else {getdefaultcharformat (CF);} // obtain the relevant font attribute bool bisbold = cf. dweffects & cfe_bold; bool bisitalic = cf. dweffects & cfe_italic; bool bisunderline = cf. dweffects & cfe_underline; bool bisstrickout = cf. dweffects & cfe_strikeout; // sets the attribute lf. lfcharset = cf. bcharset; LF. lfheight = cf. yheight/15; LF. lfpitchandfamily = cf. bpitchandfamily; LF. lf Italic = 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); // obtain the attributes of the selected font if (bselect) setselectioncharformat (CF); // set the selected font else setwordcharformat (CF) for the selected content ); // set the font for the content to be entered} implement hyperlink in RichEdit implement hyperlink responsibility edit in RichEdit: Admin is created on cbuilder Updated on: A RichEdit is first placed on the form. Add the following code to the form constructor: _ 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 ); // automatically detect URL richedit1-> text = "Welcome to C ++ Builder/N" "url: http://www.ccrun.com/N" "Even mailbox:/N" "mailto :: info@ccrun.com/N "" /N ";} reload wndproc 1 of the form. Add: protected: Virtual void _ fastcall wndproc (messages: tmessage & message); 2 in. h. In. add: // invalid void _ fastcall tmainform: wndproc (messages: tmessage & message) {If (message. MSG = wm_policy) {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 );}