• <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>
            春暖花開(kāi)
            雪化了,花開(kāi)了,春天來(lái)了
            posts - 149,comments - 125,trackbacks - 0
            【原】CEdit & CRichEdit 使用技巧
            作者:lixiaosan
            日期:04/07/2006


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


            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è)位置(直觀來(lái)看就是光標(biāo)在閃動(dòng));
                         如果nStart和nEnd不相等,表明用戶(hù)在edit中選中了一段內(nèi)容。


            3.在edit最后添加字符串

                    CString str;
                    m_edit1.SetSel(-1, -1);
                    m_edit1.ReplaceSel(str);


            4.隨輸入自動(dòng)滾動(dòng)到最后一行(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è)類(lèi),添加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自動(dòng)為寬字符(WideChar),所以它可以解決中文亂碼以及一些漢字問(wèn)題

                方法一:(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.
                方法二:以對(duì)話框?yàn)槔?br>       (1)    增加一全局變量 HMODULE hMod;
                   (2)    在CxxxApp::InitInstance()中添加一句hMod = LoadLibrary(_T("riched20.dll"));
                          在CxxxApp::ExitInstance()中添加一句FreeLibrary(hMod);
                   (3)      在對(duì)話框上放一個(gè)richedit,文本方式打開(kāi).rc文件修改該richedit控件的類(lèi)名"RICHEDIT" to  "RichEdit20a".
                   (4)      在對(duì)話框頭文件添加 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ū)"));//設(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插入位圖

            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動(dòng)畫(huà)

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


            12.richedit嵌入ole對(duì)象

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


            13.使richedit選中內(nèi)容只讀

            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無(wú)響應(yīng)的問(wèn)題

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


            17.richedit拼寫(xiě)檢查

            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.當(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中回車(chē)時(shí),會(huì)退出對(duì)話框 

            選中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. 動(dòng)態(tài)創(chuàng)建的edit沒(méi)有邊框的問(wèn)題

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

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

            http://www.codeproject.com/richedit/COleRichEditCtrl.asp
            posted on 2008-07-24 13:01 Sandy 閱讀(559) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): 界面控件學(xué)習(xí)
            久久嫩草影院免费看夜色| 久久精品国产亚洲av瑜伽| 久久人人爽人人爽人人AV东京热| 99精品国产99久久久久久97| 精品无码久久久久久午夜| 久久精品九九亚洲精品天堂| 久久丝袜精品中文字幕| 中文字幕日本人妻久久久免费| 久久精品9988| 2021最新久久久视精品爱| 久久超乳爆乳中文字幕| 久久久久无码专区亚洲av| 人妻精品久久久久中文字幕69 | 久久美女人爽女人爽| 国产精品久久久久久五月尺| 99久久久精品| 亚洲国产精品高清久久久| 国产精品熟女福利久久AV| 亚洲精品无码久久一线| 亚洲?V乱码久久精品蜜桃| 久久综合九色综合97_久久久 | 久久99国产精品一区二区| 久久久久国产精品嫩草影院| 亚洲精品高清久久| 国内精品久久九九国产精品| 色偷偷久久一区二区三区| 日产精品久久久久久久| 久久九九久精品国产免费直播| 狠狠色婷婷综合天天久久丁香 | 久久久女人与动物群交毛片| 99久久香蕉国产线看观香| 思思久久99热只有频精品66| 超级碰久久免费公开视频| 99久久精品国内| 久久综合综合久久狠狠狠97色88| 久久99精品久久久久婷婷| 久久免费的精品国产V∧| 国产亚洲欧美精品久久久| 国产成人久久精品激情 | 久久96国产精品久久久| 国产精品久久久久久福利69堂|