come limitare copia incolla in una casella di testo, in MFC?
-
22-09-2019 - |
Domanda
Sto sviluppando una piccola applicazione in MFC ... c'è un piccolo problem..hope voi ragazzi mi avrebbe aiutato per quanto riguarda questo ... Qui go..the problema è ... che ho 6 poco controllo di modifica ( casella di testo) in cui vi permetterà all'utente di inserire alcune numbers..I hanno limitato il numero di caratteri / testo come 4 ma la sua consentendo all'utente di copiare e incollare i numeri n .... come posso limitare la possibilità di copia incolla in un controllo di modifica .... Please help me ...
Soluzione
Ho trovato 2 modi per risolvere il problema .... si prega di verificare il seguito ...
1 ° metodo:
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()
};
Poi sarà necessario modificare il file cpp per questa classe in questo modo
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 ° metodo: Maneggiare il ON_EN_CHANGE evento e catturare il testo nel CString e verificare se la sua più che la character..if limitata its..you possibile deselezionare la casella di testo con un messaggio di avviso ...