【问题】

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. JDK7新特性<八>异步io/AIO

    概述 JDK7引入了Asynchronous I/O.I/O编程中,常用到两种模式:Reactor 和 Proactor.Reactor就是Java的NIO.当有事件触发时,我们得到通知,进行相应的处 ...

  2. redis 写磁盘出错 Can’t save in background: fork: Cannot allocate memory (转)

    查看 Redis 日志 发现系统在频繁报错: [26641] 18 Dec 04:02:14 * 1 changes in 900 seconds. Saving… [26641] 18 Dec 04 ...

  3. MEF框架简介

    下面主要介绍一下MEF的架构,希望从总体上有所了解,更改OpenExpressApp后我会再写篇文章介绍一下如何在OpenExpressApp中使用MEF的. 主要示意图 各种Export提供者从目录 ...

  4. .net加载失败的程序集重新加载

    在.net程序中,程序集是Lazy加载的,只有在用的时候才会去加载,当程序集加载失败时,会触发AppDomain.AssemblyResolve的事件,在这个事件中,我们甚至还可以进行补救,从别得地方 ...

  5. 【linux】linux命令grep + awk 详解

    linux命令grep  +  awk 详解 grep:https://www.cnblogs.com/flyor/p/6411140.html awk:https://www.cnblogs.com ...

  6. WordPress主题开发:WP_Query基本用法

    为什么要学WP_Query? wordpress默认会根据网址调用数据,不能满足我们所有建站要求,而WP_Query可以用于查询任何你想要的内容,相当于自定义数据调用. 便于记忆,在讲用法之前我们回顾 ...

  7. Python:Opening Python Classes

    I won’t reply to that post much, because it’s mostly… well, not useful to respond to. But people oft ...

  8. POJ 1135 Domino Effect (Dijkstra 最短路)

    Domino Effect Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9335   Accepted: 2325 Des ...

  9. “finally block does not complete normally”的警告解决

    但是,java里面不是可以保证finally一定会执行的么,为什么不可以在finally块做return??? 细细看道来: debug一下这个函数,就会惊讶的发现, 里面抛出的异常会被finally ...

  10. 在Redhat 7.3中采用离线方式安装Docker

    本文环境 Redhat Linux 7.3.Docker 18. 写在前面 Docker CE默认是不支持Redhat的,如果你想在Redhat安装,可以使用静态二进制包.这是我多次尝试RPM后得出的 ...