【问题】

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类成员变量默认初始化规则

    一个变量作为类成员使用的时候,如果没有被初始化,java会为其分配默认值: -------------------------------------------------------------- ...

  2. STM32 HAL drivers < STM32F7 >

    Overview of HAL drivers The HAL drivers were designed to offer a rich set of APIs and to interact ea ...

  3. 谨慎注意WebBrowser控件的DocumentCompleted事件

    引言 WebBrowser控件的DocumentCompleted事件一般就被认定为是在页面完全加载完毕后产生,而注释中也是这么写的: 但事实却并非如此. 首先它不一定会在完全加载完毕时才触发,有时就 ...

  4. 【Go命令教程】11. go vet 与 go tool vet

    命令 go vet 是一个 用于检查 Go 语言源码中静态错误的简单工具.与大多数 Go 命令一样,go vet 命令可以接受 -n 标记和 -x 标记.-n 标记用于只打印流程中执行的命令而不真正执 ...

  5. [Node.js]操作redis

    摘要 在实际开发中,免不了要操作mysql,mongodb,redis等数据存储服务器.这里先简单介绍如何操作redis. 一个例子 关于redis服务端的安装这里不再介绍,重点不在这里.感兴趣的可以 ...

  6. 一个完整的DLL远程注入函数

    函数名称: CreateRemoteDll() 返加类型:BOOL 接受参数: DLL路径,注入进程ID 其完整代码如下: BOOL CreateRemoteDll(const char *DllFu ...

  7. 整理:iOS 短信与电话事件的获取

    整理:iOS 短信与电话事件的获取   background information: Core Telephony iOS 4.0 的官方 API 裡頭,多了一個叫做 Core Telephony  ...

  8. 【多线程】java多线程实现生产者消费者模式

    思考问题: 1.为什么用wait()+notify()实现生产者消费者模式? wait()方法可以暂停线程,并释放对象锁 notify()方法可以唤醒需要该对象锁的其他线程,并在执行完后续步骤,到了s ...

  9. centos7安装debuginfo

    转自:https://www.72zk.com/show/blog/20 查看内核版本,查找对应的内核rpm文件 [root@localhost ~]#uname -rsp Linux 3.10.0- ...

  10. 实习医生风云第一至九季/全集Scrubs迅雷下载

    本季看点:<实习医生风云>一批医学院的学生来到圣心医院开始他们的实习生涯,但是从第一天起就发现这里并不是想象中安详宁静的医学圣地,从医生到护士甚至门卫个个不同寻常.内科实习医生杰迪是个聪明 ...