MFC, How to avoid closing of the dialog boxes when ESCAPE key or ENTER key is pressed.


/ Published in: C++
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // 1st approach. http://msdn.microsoft.com/en-us/magazine/cc301409.aspx
  2. BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
  3. ON_MESSAGE(DM_GETDEFID, OnGetDefID)
  4. ....
  5. END_MESSAGE_MAP()
  6.  
  7. LRESULT CMyDlg::OnGetDefID(WPARAM wp, LPARAM lp)
  8. {
  9. return MAKELONG(0,DC_HASDEFID);
  10. }
  11.  
  12. // 2nd approach.
  13.  
  14. BOOL DialogName::PreTranslateMessage(MSG* pMsg)
  15. {
  16. // TODO: Add your specialized code here and/or call the base class
  17. if(pMsg->message==WM_KEYDOWN)
  18. {
  19. if(pMsg->wParam==VK_RETURN || pMsg->wParam==VK_ESCAPE)
  20. {
  21. pMsg->wParam=NULL ;
  22. }
  23. }
  24.  
  25. return CDialog::PreTranslateMessage(pMsg);
  26. }

URL: http://www.codersource.net/mfc_dialog_message.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.