|
-
July 14th, 2004, 01:31 PM
#1
CDialog + VK_RETURN Problem
I have a CDialog that I don't want to be closed when the <ENTER> key is pressed, but I can't figure out where to intercept the MFC auto-magic processing. I have tried overriding OnKeyDown, OnChar etc........ and many others, but I'm not getting it! Perhaps too little sleep. Anyhow, I'm sure this is simple, but just elusive right now. Can anyone help?
Thanks in advance.
-
July 14th, 2004, 01:35 PM
#2
Hi Koolski
See below.
Jeff
Code:
////////////////////////////////////////////////////////
//
// Hook up F5 to Refresh
//
BOOL CLtrPrtMonDlg::PreTranslateMessage( MSG* pMsg ) {
if( pMsg->message == WM_KEYDOWN ) {
if( pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE ) {
// Do it here
return TRUE;
} else if( pMsg->wParam == VK_F5 ) {
////////////////////////////////////////////////////////
//
// Call our Refresh
//
RefreshListView();
////////////////////////////////////////////////////////
//
// Any Non-Zero will do
//
return TRUE;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
-
July 14th, 2004, 01:54 PM
#3
Thanks! That did the trick.
-
July 14th, 2004, 01:57 PM
#4
Why don't just set an other button to default button??? (standard the default button is IDOK)....
When you are in an editbox or richedit, just use WantReturn...
Then the problem is solved too, without code
Then you still keep the escape key to close the application (so you stay as close as possible to the microsoft styleguide)
-
July 15th, 2004, 03:46 AM
#5
The answer could have been found in the following FAQ
-
July 15th, 2004, 03:59 AM
#6
 Originally Posted by jwalto1
Hi Koolski
See below.
Jeff
Code:
////////////////////////////////////////////////////////
//
// Hook up F5 to Refresh
//
BOOL CLtrPrtMonDlg::PreTranslateMessage( MSG* pMsg ) {
if( pMsg->message == WM_KEYDOWN ) {
if( pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE ) {
// Do it here
return TRUE;
} else if( pMsg->wParam == VK_F5 ) {
////////////////////////////////////////////////////////
//
// Call our Refresh
//
RefreshListView();
////////////////////////////////////////////////////////
//
// Any Non-Zero will do
//
return TRUE;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
No intention to be mean, but this is a hack and should not be used.
See this FAQ for a reason.
-
July 15th, 2004, 01:57 PM
#7
Hi Alin,
I was not aware that was considered a hack. I love reading Paul DiLascias.
Thanks,
Jeff
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|