【问题】

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. LINUX IO 图解

    http://blog.chinaunix.net/uid/29075379/cid-183430-list-1.html

  2. poi workbook转成流

    try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); workbook.write(bos); byte[] barray = ...

  3. Idea2018激活破解

    原文:https://www.imsxm.com/2018/07/idea-2018-1-5-crack-patcher.html 最近更新了Intellij IDEA到2018.1.5之后,使用之前 ...

  4. 关于面试总结6-SQL经典面试题

    前言 用一条SQL 语句查询xuesheng表每门课都大于80 分的学生姓名,这个是面试考sql的一个非常经典的面试题 having和not in 查询 xuesheng表每门课都大于80 分的学生姓 ...

  5. ArrayList的总结

    1.ArrayList的特点 主要特点:按照插入顺序来保存元素,可以利用下标来查找值 2.ArrayList的优点: 按照下标访问元素最快 3.ArrayList的缺点: 在中间插入元素很慢 删除元素 ...

  6. tsung执行时报Can't locate Template.pm的解决

    [root@openfire-x86v-app01 20141118-0931]# tsung_stats creating subdirectory data creating subdirecto ...

  7. 真爱如血第七季/全集True Blood迅雷下载

    第七季 True Blood Season 7(2014)看点:由于日本科学家合成了一种人造血,一夜之间,吸血鬼不再是人们心中那富有传奇色彩的怪物,而是能与人类和平相处的朋友.已经播出五年的HBO吸血 ...

  8. Android动画学习笔记大集合

    其实动画这个东西我已经了解过很长一段时间了,但是一直没系统的整理过.关于android中的各种动画虽然都会用,但总怕自己会慢慢遗忘.这回看了几篇动画分析的文章,自己也学到了一些东西,在此就梳理一下. ...

  9. [Android Pro] AndroidStudio IDE界面插件开发(进阶篇之Editor)

    转载请注明出处:[huachao1001的专栏:http://blog.csdn.net/huachao1001/article/details/53885981] 我们开发AndroidStudio ...

  10. ASP.NET Core 中间件 中间件(Middleware)和过滤器(Filter)的区别

    https://www.cnblogs.com/savorboard/p/5586229.html 前言 在上篇文章主要介绍了DotNetCore项目状况,本篇文章是我们在开发自己的项目中实际使用的, ...