zoukankan      html  css  js  c++  java
  • how to restrict copy paste in a Textbox, in MFC?

    【问题】

    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 

  • 相关阅读:
    NOIp2014 Day2T3 解方程 秦九韶算法
    Luogu P1082 同余方程 拓展欧几里得
    Luogu P1351 联合权值 前缀和
    [USACO06JAN]冗余路径Redundant Paths 无向图tarjan缩点
    P1073 最优贸易 dp
    LOJ #6279. 数列分块入门 3
    LOJ #6278. 数列分块入门 2
    分块
    字典树Trie
    KMP
  • 原文地址:https://www.cnblogs.com/time-is-life/p/8052871.html
Copyright © 2011-2022 走看看