【问题】

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. MHDD硬盘坏道检测修复教程(转)

    MHDD算是在DOS下比较专业的检测工具,比一些GUI的好用很多,并且现在有人专门做成硬件机器卖到了电脑城,电脑城一般倒卖硬盘的都使用这种机器. 进入MHDD 上面图片中就可以看到硬盘是ST34081 ...

  2. CentOS 7.x,不重新编译 PHP,动态安装 imap 扩展

    先前的教程:PHP5不重新编译,如何安装自带的未安装过的扩展,如soap扩展? # 安装依赖包 yum install -y libc-client-devel /usr/local/src/cent ...

  3. AngularJS动态设置CSS

    使用AngularJS动态设置CSS大致有2种思路: 1.通过动态设置class名称 比如先定义2个样式: .show-true{    display:block;} .show-flase{    ...

  4. 【Devops】【Jenkins】Jenkins插件安装失败处理方法

    本篇解释:Jenkins插件安装失败处理方法 不论是刚启动成功后进行的推荐插件安装,还是后期使用Jenkins过程中进行插件的安装.出现插件安装失败的问题,可以通过本篇解决! [注意,插件下载安装失败 ...

  5. WordPress主题开发:开启feed功能

    开启feed功能 步骤一:在模版文件的<head></head>元素中添加wp_head()函数,且wp_head()函数要放在</head>标签之前,而且紧邻&l ...

  6. 真探第一季/全集True Detective1迅雷下载

    真探 第一季 True Detective Season 1 (2014)真相如探 / 真爱如探本季看点:这部剧采用多视角叙事,伍迪·哈里森与马修·麦康纳饰演两名侦探搭档,他们一起调查一桩17年前的悬 ...

  7. 2016 移动应用质量大数据报告--转自腾讯Bugly

    2016年,在“互联网+”战略的推动下,移动互联网与越来越多传统行业的结合更加紧密,用户使用移动互联网的工作场景.生活场景.消费场景都在悄然发生着改变, 移动互联网产品在智能硬件.医疗.汽车.旅游.教 ...

  8. [C#技术] DataSet(DataTable)轻松的通过Sum、Aver、Count等统计出相关结果

    我们在使用Sql ******这些数据库时,可以轻松的通过Sum.Aver.Count等统计出相关结果,那么,在已经把数据检索出来的DataSet(DataTable)中呢?特别是通过Web Serv ...

  9. Orchard模块开发全接触4:深度改造前台

    这里,我们需要做一些事情,这些事情意味着深度改造前台: 1:为商品增加 添加到购物车 按钮,点击后功能实现: 2:商品排序: 3:购物车预览,以及添加 结算 按钮: 4:一个显式 购物车中有*个 商品 ...

  10. Gerrit代码审查工具

    1 Gerrit简介 Gerrit,一种免费.开放源代码的代码审查软件,使用网页界面.利用网页浏览器,同一个团队的软件程序员,可以相互审阅彼此修改后的程序代码,决定是否能够提交,退回或者继续修改. 1 ...