【问题】

I am developing a small application in MFC... there is a little problem..hope you guys would help me regarding this...Here we go..the problem is...I have 6 little edit control(Text box) in which I will allow the user to enter some numbers..I have limited the number of chars/textbox as 4 but its allowing the user to copy and paste n numbers....How do I restrict the copy paste option in an Edit control....Please help me...

【答案】

I found 2 ways of solving the problem....please check the below...

1st method:

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()

};

Then you will need to edit the .cpp file for this class like so

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.

}

2nd method: Handle the ON_EN_CHANGE event and capture the text in the CString and check if its more than the limited character..if its..you can clear the text box with a warning message...

 

 

来自:https://stackoverflow.com/questions/2316041/how-to-restrict-copy-paste-in-a-textbox-in-mfc 

how to restrict copy paste in a Textbox, in MFC?的更多相关文章

  1. Perform Cut Copy Paste Operations Using Cut_Region Copy_Region Paste_Region Commands In Oracle Forms

    You can do Select, Cut, Copy and Paste operations on text items in Oracle Forms using Select_All, Cu ...

  2. eclipse cut copy paste plugin

    The Cut Copy Paste Plus plug-in enhances the standard Cut, Copy and Paste commands in Eclipse IDE. W ...

  3. Copy Paste DWG to older 3ds Max

    Hi, This is quick tutorial: how to install Auto Cad scripts to be able to copy from newer Auto Cad t ...

  4. vim - copy/paste a word

    1. http://stackoverflow.com/questions/7797068/copying-a-word-and-pasting-over-a-word viwp - visually ...

  5. 兼容Android 和 ios JavaScript copy paste

    <!DOCTYPE html> <html> <head> <title>关于我们Frame</title> <meta charse ...

  6. ubuntu terminal copy paste

    copy: ctrl + insert paste: shift + insert

  7. Pyperclip could not find a copy/paste mechanism for your system.

    sudo apt-get install xsel sudo apt-get install xclip pip install gtk to install the gtk Python modul ...

  8. 【Android】Android之Copy and Paste

    Android为复制粘贴提供了一个强大的基于剪切板的框架,它支持简单和复杂的数据类型,包括纯文本,复杂的数据结构,二进制流,甚至app资源文件.简单的文本数据直接存储在剪切板中,而复杂的数据则存储的是 ...

  9. In line copy and paste to system clipboard

    On the Wiki Wiki Activity Random page Videos Photos Chat Community portal To do    Contribute  Watch ...

随机推荐

  1. Java clone() 浅克隆与深度克隆(转)

    以下文字转自:桔子园 http://www.blogjava.net/orangelizq/archive/2007/10/17/153573.html 现在Clone已经不是一个新鲜词语了,伴随着“ ...

  2. Cocos2d-x 3.0游戏开发之虚拟机IOS环境:匹配才是好,莫要随便升级软件

    尊重开发人员的劳动成果.转载的时候请务必注明出处:http://blog.csdn.net/haomengzhu/article/details/34110449 做为一个买不起MAC的Coder,仅 ...

  3. Linux 用户和用户操作

    1,创建组 groupadd test 增加一个test组 2,修改组 groupmod -n test2 test 将test组的名子改成test2 3,删除组 groupdel test2 删除  ...

  4. 使用PHP+Sphinx建立高效的站内搜索引擎

      1.    为什么要使用Sphinx   假设你现在运营着一个论坛,论坛数据已经超过100W,很多用户都反映论坛搜索的速度非常慢,那么这时你就可以考虑使用Sphinx了(当然其他的全文检索程序或方 ...

  5. 并查集(Union-Find) 应用举例 --- 基础篇

    本文是作为上一篇文章 <并查集算法原理和改进> 的后续,焦点主要集中在一些并查集的应用上.材料主要是取自POJ,HDOJ上的一些算法练习题. 首先还是回顾和总结一下关于并查集的几个关键点: ...

  6. 用SDWebImage加载FLAnimatedImage

    用SDWebImage加载FLAnimatedImage 效果 源码 https://github.com/YouXianMing/Animations // // GifPictureControl ...

  7. java把指定文字输出为图片流,支持文字换行

    public class IamgeUtils { private static final int WIDTH = 350; private static final int HEIGHT = 10 ...

  8. mariadb 重置密码

    1. sudo身份打开 /etc/mysql/my.cnf 在[mysqld]节点下增加如下代码: skip-grant-tables #忽略密码授权 2. 杀掉mysql进程,重启mariadb,这 ...

  9. 实用ExtJS教程100例-004:等待对话框Ext.MessageBox.wait

    在前面两节中,我们分别演示了ExtJS三种常用的对话框和ExtJS带有进度条的对话框.在本节内容中,我们来看看ExtJS中的等待对话框. 首先来看一个简单的例子[查看在线示例]: 这种对话框会一直滚动 ...

  10. Kubernetes基础

    Kubernetes是什么 Kubernetes是当今最流行的开源容器管理平台,它就是大名鼎鼎的Google Borg的开源版本.Google在2014年推出了Kubernetes,本文发布时最新的版 ...