如何在MFC中限制文本框中的复制粘贴?

如何在MFC中限制文本框中的复制粘贴?,mfc,editcontrol,Mfc,Editcontrol,我正在开发一个MFC的小应用程序。。。有一个小问题…希望你们能帮我解决这个问题…我们开始…问题是…我有6个小编辑控件(文本框)在其中,我将允许用户输入一些数字。我已将字符/文本框的数量限制为4,但允许用户复制和粘贴n个数字…如何限制编辑控件中的复制粘贴选项…请帮助我…我找到了两种解决问题的方法…请检查以下内容 第一种方法: class CNoPasteEdit: public CEdit { public: CNoPasteEdit(); ~CNoPasteEdit(); protected:

我正在开发一个MFC的小应用程序。。。有一个小问题…希望你们能帮我解决这个问题…我们开始…问题是…我有6个小编辑控件(文本框)在其中,我将允许用户输入一些数字。我已将字符/文本框的数量限制为4,但允许用户复制和粘贴n个数字…如何限制编辑控件中的复制粘贴选项…请帮助我…

我找到了两种解决问题的方法…请检查以下内容

第一种方法:

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中的文本,并检查其是否超过限制字符。。如果超过限制字符。。您可以使用警告消息清除文本框