prevent window closing
-
i have created a modal window using MFC, as soon as ENTER key is pressed the window is destroyed. what to do to avoid this?
Add a function to the dialog class
//In MyDlg.h file
virtual void OnOK();//in MyDlg.Cpp
void CMyDlg::OnOK()
{
//Remove this line if already there
//CDialog::OnOK();
}hope this helps and get a good MFC book :D
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
-
i have created a modal window using MFC, as soon as ENTER key is pressed the window is destroyed. what to do to avoid this?
Add a handler for the Ok and Cancel buttons and remove the call to OnOk() and OnCancel() in these functions.
-
i have created a modal window using MFC, as soon as ENTER key is pressed the window is destroyed. what to do to avoid this?
I prefer to override PreTranslateMessage and handle the CR myself
BOOL CMyDialog::PreTranslateMessage(MSG* pMsg)
{
if ((pMsg->message == WM_KEYUP) || (pMsg->message == WM_KEYDOWN))
{
if (pMsg->wParam == VK_RETURN)
{
// TODO: Process all we want from the RETURN key// Ignore further processing
return TRUE;
}
}
return CDialog::PreTranslateMessage(pMsg);
}Ant. I'm hard, yet soft.
I'm coloured, yet clear.
I'm fruity and sweet.
I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)