亚洲免费乱码视频,日韩 欧美 国产 动漫 一区,97在线观看免费视频播国产,中文字幕亚洲图片

      1. <legend id="ppnor"></legend>

      2. 
        
        <sup id="ppnor"><input id="ppnor"></input></sup>
        <s id="ppnor"></s>

        限制文本編輯框輸入的中英文字符字?jǐn)?shù)

        字號(hào):

        在頭文件CXXXDlg.h中考試大提示:定義一個(gè)編輯框類CLimitLengthEdit
            class CLimitLengthEdit : public CWindowImpl
            {
            public:
            CLimitLengthEdit() {};
            virtual ~CLimitLengthEdit(){};
            BOOL SubclassWindow(HWND hWnd) {typedef CWindowImpl CWindowBase;return CWindowBase::SubclassWindow(hWnd);};
            protected:
            BEGIN_MSG_MAP(CLimitLengthEdit)
            END_MSG_MAP()
            };
            在CXXXDlg.h中CXXXDlg類的定義處加入消息映射以及響應(yīng)函數(shù)聲明
            protected:
            BEGIN_MSG_MAP(CRequestDlg)
            MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
            COMMAND_HANDLER(IDC_EDIT_MESSAGE,EN_CHANGE,OnEditChange) //IDC_EDIT_MESSAGE為編輯控件的ID
            REFLECT_NOTIFICATIONS_EX()
            END_MSG_MAP()
            LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
            LRESULT OnEditChange(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
            加入成員變量
            private:
            CLimitLengthEdit m_llEdit;
            在實(shí)現(xiàn)文件CXXXDlg.cpp中加入消息處理函數(shù)
            #define MAX_LIMIT_LEN 20 //考試大提示:字符長(zhǎng)度限制為中文10個(gè),英文20個(gè)
            LRESULT CRequestDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
            {
            m_llEdit.SubclassWindow(GetDlgItem(IDC_EDIT_MESSAGE));
            ::SetFocus(GetDlgItem(IDC_EDIT_MESSAGE));
            return 0;
            }
            LRESULT CRequestDlg::OnEditChange(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
            {
            CString strText;
            TCHAR msg[128];
            m_llEdit.GetWindowText(msg , 128);
            strText.Format(_T("%s"),msg);
            int nPixelPos = 0;
            int nCount = 0;
            int pos = 0;
            int iLen = strText.GetLength();
            for(int i = 0; i < iLen;)
            {
            if(IsDBCSLeadByte(strText[i]))
            {
            nCount ++;
            i += 2;
            if(i > 20)
            {
            HideCaret();
            m_llEdit.SetSel(0,-1);
            m_llEdit.ReplaceSel(strText.Left(i - 2));
            ShowCaret();
            m_llEdit.SetLimitText(nCount);
            break;
            }
            else
            {
            m_llEdit.SetLimitText(20);
            }
            }
            else
            {
            nCount ++;
            i++;
            if(i > 20)
            {
            HideCaret();
            m_llEdit.SetSel(0,-1);
            m_llEdit.ReplaceSel(strText.Left(i - 1));
            ShowCaret();
            m_llEdit.SetLimitText(nCount);
            break;
            }
            else
            {
            m_llEdit.SetLimitText(20);
            }
            }
            }
            strText.ReleaseBuffer();
            return FALSE;
            }