2010-02-23 2 views
2

MFC에서 작은 응용 프로그램을 개발 중입니다 ... 약간의 문제가 있습니다. 여러분이 저와 관련하여 도움을 주시기 바랍니다 ... 여기에 문제가 있습니다 ... 저는 6 개의 작은 편집 컨트롤 (Text 상자)에서 사용자가 일부 숫자를 입력 할 수 있도록 허용합니다. 문자/문자 수를 4로 제한했지만 사용자가 숫자를 복사하여 붙여 넣을 수 있습니다. 편집 컨트롤은 ... 내가 문제를 해결하는 두 가지 방법을 발견MFC에서 텍스트 상자에 붙여 넣기를 제한하는 방법?

답변

1

... 제발 도와주세요 ... ... 아래 확인하시기 바랍니다

첫번째 방법 :

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

그럼 당신은

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

2 방법과 같이,이 클래스의 .cpp 파일을 편집해야합니다ON_EN_CHANGE 이벤트를 처리하고 CString을의 텍스트를 캡처하고 있는지 확인 그것보다 더 제한된 문자는 ... 경고 메시지와 함께 텍스트 상자를 지울 수 있습니다 ...