2
我正在MFC中開發一個小應用程序......有一個小問題..希望你們能夠幫助我解決這個問題...我們現在去......問題是......我有6個小編輯控件(Text框),其中我將允許用戶輸入一些數字..我已經限制字符數/文本框爲4,但它允許用戶複製和粘貼n個數字....如何限制複製粘貼選項編輯控件....請幫我...如何在MFC中限制文本框中的複製粘貼?
我正在MFC中開發一個小應用程序......有一個小問題..希望你們能夠幫助我解決這個問題...我們現在去......問題是......我有6個小編輯控件(Text框),其中我將允許用戶輸入一些數字..我已經限制字符數/文本框爲4,但它允許用戶複製和粘貼n個數字....如何限制複製粘貼選項編輯控件....請幫我...如何在MFC中限制文本框中的複製粘貼?
我找到解決問題的2種方式....請檢查下面...
第1種方法:
class CNoPasteEdit: public CEdit
{
public:
CNoPasteEdit();
~CNoPasteEdit();
protected:
// This line will need to be added by hand because WM_PASTE is not available in
// class wizard
afx_msg void OnPaste(WPARAM wParam, LPARAM lParam);
afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
DECLARE_MESSAGE_MAP()
};
然後,你將需要編輯.cpp文件該類像這樣
CNoPasteEdit::CNoPasteEdit(){
// Put any construction code here
}
CNoPasteEdit:~:CNoPasteEdit(){
// Put any destruction code here
}
BEGIN_MESSAGE_MAP(CNoPasteEdit, CEdit)
// This line is needed because there is no default macro for WM_PASTE messages
// This line will also need to be added by hand
ON_MESSAGE(WM_PASTE, OnPaste)
ON_WM_CONTEXTMENU()
END_MESSAGE_MAP()
void CNoPasteEdit::OnPaste(WPARAM wParam, LPARAM lParam){
// Put any code here you want to execute when the user right clicks on the edit
// control. Just leave it blank to disable the menu
}
void CNoPasteEdit::OnContextMenu(CWnd* pWnd, CPoint point){
// Put any code here you want to execute when the user tries to paste into the edit
// conrtol. Just leave it blank to prevent pasting.
}
第二個方法: 處理好ON_EN_CHANGE事件,並捕捉到CString的文本,並檢查其超過有限的字符..如果它可以清除帶有警告信息的文本框...