كيفية تقييد نسخة النسخ في مربع النص ، في MFC؟

StackOverflow https://stackoverflow.com/questions/2316041

  •  22-09-2019
  •  | 
  •  

سؤال

أنا أقوم بتطوير تطبيق صغير في MFC ... هناك مشكلة صغيرة .. أتمنى أن تساعدني يا رفاق فيما يتعلق بهذا ... هنا نذهب .. المشكلة هي ... لدي 6 التحكم في التحرير الصغير (مربع نص) حيث سأسمح للمستخدم بإدخال بعض الأرقام .. لقد حصرت عدد chars/textbox كـ 4 ولكن يسمح للمستخدم بنسخ الأرقام والصقه .... كيف يمكنني تقييد خيار لصق النسخ في تحرير السيطرة .... الرجاء مساعدتي ...

هل كانت مفيدة؟

المحلول

لقد وجدت طريقتان لحل المشكلة .... يرجى التحقق من ...

الطريقة الأولى:

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()
};

ثم ستحتاج إلى تحرير ملف .cpp لهذه الفئة مثل ذلك

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.
}

الطريقة الثانية:التعامل مع ON_EN_CHANGE الحدث والتقاط النص في Cstring وتحقق مما إذا كان أكثر من الشخصية المحدودة .. إذا كان .. يمكنك مسح مربع النص برسالة تحذير ...

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top