Try   HackMD

MFC project disable copy & paste on CEdit

tags: mfc visual studio
  • CMyEdit.h
#pragma once #include "afxwin.h" class CMyEdit : public CEdit { public: CMyEdit(); // standard constructor ~CMyEdit(); protected: afx_msg LRESULT OnPaste(WPARAM wParam, LPARAM lParam); DECLARE_MESSAGE_MAP() };
  • CMyEdit.pp
#include "CMyEdit.h" CMyEdit::CMyEdit(){} CMyEdit::~CMyEdit(){} BEGIN_MESSAGE_MAP(CMyEdit, CEdit) ON_MESSAGE(WM_PASTE, &CMyEdit::OnPaste) END_MESSAGE_MAP() LRESULT CMyEdit::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 return true; }

把 edit 的 IDC_EDIT 使用上面新的 CMyEdit 來使用 Edit 欄位
IDC_EDIT 就是 UI 上 edit field 元件的 ID.

需要使用自訂的 CEdit 的 cpp 上面加上:

.h: (宣告) CMyEdit m_myEditControl; .cpp: (DoDataExchange function 加入) DDX_Control(pDX, IDC_EDIT, m_myEditControl);