• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            CEdit & CRichEdit 使用技巧

            http://blog.csdn.net/lixiaosan/

            【原】CEdit & CRichEdit 使用技巧

            作者:lixiaosan
            日期:04/07/2006

            注:
                    m_edit1代表ID為IDC_EDIT1的CEdit控件的control類型的變量
                    m_richedit1代表ID為IDC_RICHEDIT1的CRichEditCtrl控件的control類型的變量


            1.設置edit只讀屬性

                方法一:
                            m_edit1.SetReadOnly(TRUE);
                方法二:
                            ::SendMessage(m_edit1.m_hWnd, EM_SETREADONLY, TRUE, 0);


            2.判斷edit中光標狀態并得到選中內容(richedit同樣適用)

                    int nStart, nEnd;
                    CString strTemp;

                    m_edit1.GetSel(nStart, nEnd);
                    if(nStart == nEnd)
                    {
                        strTemp.Format(_T("光標在%d"), nStart);
                        AfxMessageBox(strTemp);
                    }
                    else
                    {
                        //得到edit選中的內容    
                        m_edit1.GetWindowText(strTemp);
                        strTemp = strTemp.Mid(nStart) - strTemp.Mid(nEnd);
                        AfxMessageBox(strTemp);
                    }
                注:GetSel后,如果nStart和nEnd,表明光標處于某個位置(直觀來看就是光標在閃動);
                         如果nStart和nEnd不相等,表明用戶在edit中選中了一段內容。


            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派生一個類,添加WM_CHAR消息映射。下面一個例子實現了限定輸入16進制字符的功能。

               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及以后版本創建的工程)
                        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.
                方法二:以對話框為例:
                   (1)    增加一全局變量 HMODULE hMod;
                   (2)    在CxxxApp::InitInstance()中添加一句hMod = LoadLibrary(_T("riched20.dll"));
                          在CxxxApp::ExitInstance()中添加一句FreeLibrary(hMod);
                   (3)      在對話框上放一個richedit,文本方式打開.rc文件修改該richedit控件的類名"RICHEDIT" to  "RichEdit20a".
                   (4)      在對話框頭文件添加 CRichEditCtrl m_richedit;
                          在OnInitDialog中添加 m_richedit.SubclassDlgItem(IDC_RICHEDIT1, this);


            8.改變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);


            9.設置行間距(只適用于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插入位圖

            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插入gif動畫

            http://www.codeproject.com/richedit/AnimatedEmoticon.asp


            12.richedit嵌入ole對象

            http://support.microsoft.com/kb/141549/en-us


            13.使richedit選中內容只讀

            http://www.codeguru.com/cpp/controls/richedit/article.php/c2401/


            14.打印richedit

            http://www.protext.com/MFC/RichEdit3.htm



            15.richeidt用于聊天消息窗口

            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/


            16.解決richedit的EN_SETFOCUS和EN_KILLFOCUS無響應的問題

            http://support.microsoft.com/kb/181664/en-us


            17.richedit拼寫檢查

            http://www.codeproject.com/com/AutoSpellCheck.asp


            18.改變edit背景色

            Q117778:How to change the background color of an MFC edit control
            http://support.microsoft.com/kb/117778/en-us


            19.當edit控件的父窗口屬性是帶標題欄WS_CAPTION和子窗口WS_CHILD時,不能設置焦點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中回車時,會退出對話框 

            選中Edit的風格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. 動態創建的edit沒有邊框的問題

                m_edit.Create(....);
                m_edit.ModifyStyleEx(0, WS_EX_CLIENTEDGE, SWP_DRAWFRAME);

            22. 一個能顯示RTF,ole(包括gif, wmv,excel ,ppt)的例子

            http://www.codeproject.com/richedit/COleRichEditCtrl.asp

            posted on 2007-04-29 20:59 PeakGao 閱讀(3094) 評論(4)  編輯 收藏 引用 所屬分類: C++技術

            評論

            # xdywdnja 2008-04-06 08:43 xdywdnja

            gjwgdmpd http://hxurfwxp.com rygvtudv dhhasnbc <a href="http://ntwzxwoj.com">bwacmbwp</a> [URL=http://awjxkjqo.com]sxebiyww[/URL]   回復  更多評論   

            # secretogogue 2009-08-14 17:03 secretogogue

            One of the lessons of history is that nothing is often a good thing to do and always a clever thing to say.  回復  更多評論   

            # senega 2009-08-16 21:04 senega

            Always be nice to those younger than you, because they are the ones who will be writing about you.  回復  更多評論   

            # xsbctqbb 2009-08-28 04:09 xsbctqbb

            <a href="http://qzbihykk.com">axgxiflo</a> [URL=http://gjogvkkg.com]zxtqqjmz[/URL] gnvkcuff http://etuvuoes.com lauaozas pujjfuur   回復  更多評論   

            <2009年8月>
            2627282930311
            2345678
            9101112131415
            16171819202122
            23242526272829
            303112345

            導航

            統計

            常用鏈接

            留言簿(9)

            隨筆分類(67)

            隨筆檔案(65)

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久99精品综合国产首页| 久久久久亚洲精品男人的天堂| 久久国产热这里只有精品| 国产精品成人无码久久久久久| 中文字幕成人精品久久不卡| 国产福利电影一区二区三区久久久久成人精品综合 | 精品国际久久久久999波多野| 久久亚洲AV成人无码电影| 中文国产成人精品久久不卡| 久久亚洲精品中文字幕| 久久99精品久久久久久噜噜| 综合网日日天干夜夜久久| 久久99久久99小草精品免视看| 亚洲欧美久久久久9999| 久久亚洲欧美国产精品| 香蕉99久久国产综合精品宅男自 | 国内精品久久久人妻中文字幕| 伊人久久综合热线大杳蕉下载| 77777亚洲午夜久久多喷| 久久精品国产WWW456C0M| 久久综合给久久狠狠97色| 亚洲国产精品嫩草影院久久| 亚洲国产精久久久久久久| 无码日韩人妻精品久久蜜桃 | 久久er国产精品免费观看2| 色综合久久夜色精品国产| 夜夜亚洲天天久久| 狠狠色丁香婷婷综合久久来| 久久久无码精品亚洲日韩蜜臀浪潮 | 狠狠干狠狠久久| 亚洲欧美伊人久久综合一区二区| 久久噜噜久久久精品66| 亚洲国产成人久久综合一 | 久久精品成人影院| 国内精品免费久久影院| 日本道色综合久久影院| 久久福利青草精品资源站| 99热成人精品热久久669| 久久精品黄AA片一区二区三区| 亚洲午夜久久久久久久久电影网 | 国产精品久久久久9999|