Board index » Visual Studio » newbie question
|
cecilsheng
|
|
cecilsheng
|
newbie question
Visual Studio105
hi, how can I disable my dialog from closeing when the esc or enter key is pressed? - |
| Roy
Registered User |
Tue Nov 25 19:33:29 CST 2003
Re:newbie question
Maximus
There are many ways to attack this problem -- the first one that I recommend is to provide implementations to the two virtual function that handle this in the CDialog base class, specifically OnOK and OnCancel. I usutally provide implementation for these and in the implementationI do nothing, i.e. {} Next, I would rename the IDs for the two buttons, and remove the default setting on the OK button. Then I would provide message map entries and handlers for the new buttons - ID_MYOK and ID_MYCANCEL, or something like that. Other approaches may include something with PreTranslateMessage to consume the ESC/Enter keys. That would look something like this: /* ************************** */ BOOL CMyONOK::PreTranslateMessage(MSG* pMsg){ if(pMsg->message == WM_KEYDOWN){ if(pMsg->wParam == VK_ESCAPE) return 0; if(pMsg->wParam == VK_RETURN) return 0; } BOOL sts = CDialog::PreTranslateMessage(pMsg); return sts; } /* ************************** */ regards roy fine "Maximus" <ikillpeople@videotron.ca>wrote in message Quotehi, - |
| Scott
Registered User |
Tue Nov 25 19:50:51 CST 2003
Re:newbie question
Maximus wrote:
Quotehi, message handlers. -- Scott McPhillips [VC++ MVP] - |
| Roy
Registered User |
Tue Nov 25 20:07:20 CST 2003
Re:newbie question"Scott McPhillips [MVP]" <scottmcp@mvps.org.nowhere>wrote in message QuoteMaximus wrote: at all. what shall i do now? Heres the code: BEGIN_MESSAGE_MAP(CSecondChance, CDialog) ON_BN_CLICKED(IDCANCEL, MYCANCEL) ON_BN_CLICKED(IDOK, MYOK) END_MESSAGE_MAP() // CSecondChance message handlers void CSecondChance::MYCANCEL(){} void CSecondChance::MYOK(){} roy - |
| Scott
Registered User |
Tue Nov 25 22:20:25 CST 2003
Re:newbie questionQuote>Add message handers for IDOK and IDCANCEL and do nothing inside the -- Scott McPhillips [VC++ MVP] - |
| Roy
Registered User |
Tue Nov 25 23:05:21 CST 2003
Re:newbie question"Scott McPhillips [MVP]" <scottmcp@mvps.org.nowhere>wrote in message Quote>>Add message handers for IDOK and IDCANCEL and do nothing inside the void CSecondChance::MYOK(){ Call CDialog::OnOK(); } rlf - |
| Stokie
Registered User |
Tue Nov 25 23:15:26 CST 2003
Re:newbie question
I think he's yanking your chain Scott!
"Roy Fine" <rlfine@twt.obfuscate.net>wrote in message Quote
- |
| GuitarBill
Registered User |
Wed Nov 26 04:07:10 CST 2003
Re:newbie question
Yes. you need to add a handler for WM_COMMAND (override
the OnCommand method), and make it something like this: BOOL CMyDlg::OnCommand(WPARAM wParam, LPARAM lParam) { // Dont close child on <enter>/<escape> if ((wParam == IDOK) || (wParam == IDCANCEL)) return TRUE; return CDialog::OnCommand(wParam, lParam); } Quote-----Original Message----- |
