Modal dialog - Close - ESC
-
How to prevent a modal dialog from closing when we hit ESC key? Thanks in advance, Sarvan AL
Hi While pressing ESC key by default ID_CANCEL(OnCancel) message is calling. So write code inside OnCancel() to prevent this. Check the keypressed and if it is ESC key then dont call CDialog::OnCancel(); regards Vallikumar A
-
Hi While pressing ESC key by default ID_CANCEL(OnCancel) message is calling. So write code inside OnCancel() to prevent this. Check the keypressed and if it is ESC key then dont call CDialog::OnCancel(); regards Vallikumar A
-
Hi While pressing ESC key by default ID_CANCEL(OnCancel) message is calling. So write code inside OnCancel() to prevent this. Check the keypressed and if it is ESC key then dont call CDialog::OnCancel(); regards Vallikumar A
vallikumar wrote:
Check the keypressed and if it is ESC key then dont call CDialog::OnCancel()
OnCancel will be called when Esc is pressed or the Cancel button with the id IDCANCEL is clicked.
Jesus Loves:rose:
--Owner Drawn:rose: --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord:rose:
-
How to prevent a modal dialog from closing when we hit ESC key? Thanks in advance, Sarvan AL
The
IsDialogMessage
API provides this functionality. You would have to filter the messages passed to it - this will not be possible for dialog in general as you have not got access to the message pump. An alternative, if you can't use this technique, would be to use hooks (SetWindowsHookEx
). Steve -
How to prevent a modal dialog from closing when we hit ESC key? Thanks in advance, Sarvan AL
The other guys have a point - My solution was like killing a gnat with a sledgehammer. Perhaps just use the
GetAsyncKeyState
to see if the escape key is down in aOnCancel
overide. -
How to prevent a modal dialog from closing when we hit ESC key? Thanks in advance, Sarvan AL
The simplest solution is to override the
PreTranslateMessage()
! Within the handler, write this code...if(pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_ESCAPE) wParam = NULL; //yeah you read it right!
Simple as pie :) Regards, Rajesh R. Subramanian You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each. -
The
IsDialogMessage
API provides this functionality. You would have to filter the messages passed to it - this will not be possible for dialog in general as you have not got access to the message pump. An alternative, if you can't use this technique, would be to use hooks (SetWindowsHookEx
). Steve:omg::wtf:
Jesus Loves:rose:
--Owner Drawn:rose: --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord:rose:
-
The simplest solution is to override the
PreTranslateMessage()
! Within the handler, write this code...if(pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_ESCAPE) wParam = NULL; //yeah you read it right!
Simple as pie :) Regards, Rajesh R. Subramanian You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each.Ladies and gentlemen, we have a winner. It's one of those solutions that once you hear, you feel stupid for not thinking of (assuming MFC is beging used). Steve
-
Ladies and gentlemen, we have a winner. It's one of those solutions that once you hear, you feel stupid for not thinking of (assuming MFC is beging used). Steve
LOL man. that made you dig deep to set a system-wide hook? It does happen, but. Regards, Rajesh R. Subramanian. You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each.
-
LOL man. that made you dig deep to set a system-wide hook? It does happen, but. Regards, Rajesh R. Subramanian. You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each.
I would have only set a thread local hook - But regardless your solution is still the way to go. Steve
-
How to prevent a modal dialog from closing when we hit ESC key? Thanks in advance, Sarvan AL
See the FAQ 7.4 How do I prevent a dialog from closing when the user presses Enter or Esc?[^] --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Shots do not hurt other players... yet
-
The simplest solution is to override the
PreTranslateMessage()
! Within the handler, write this code...if(pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_ESCAPE) wParam = NULL; //yeah you read it right!
Simple as pie :) Regards, Rajesh R. Subramanian You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each.Have you ever made a pie before?
-Prakash
-
I would have only set a thread local hook - But regardless your solution is still the way to go. Steve
no hooks are needed to do this.
-Prakash
-
The other guys have a point - My solution was like killing a gnat with a sledgehammer. Perhaps just use the
GetAsyncKeyState
to see if the escape key is down in aOnCancel
overide.Going after a gnat with a sledgehammer is always fun! :)
ZeePain! wrote:
This seems like one of those programs that started small, grew incrementally, building internal pressure, and finally barfed all over its source code sneakers. Or something.
-
no hooks are needed to do this.
-Prakash
I think we've established that -
PreTranslateMessage
was the best solution - Assuming we're using MFC. Steve -
I think we've established that -
PreTranslateMessage
was the best solution - Assuming we're using MFC. StevePreTranslateMessage is good but did you consider http://www.codeproject.com/script/comments/forums.asp?msg=1338886&forumid=1647#xx1338886xx[^]
-Prakash
-
PreTranslateMessage is good but did you consider http://www.codeproject.com/script/comments/forums.asp?msg=1338886&forumid=1647#xx1338886xx[^]
-Prakash
much better, and very simple !!! thanks to mickael...
TOXCCT >>> GEII power
[toxcct][VisualCalc 2.20][VCalc 3.0 soon...] -
much better, and very simple !!! thanks to mickael...
TOXCCT >>> GEII power
[toxcct][VisualCalc 2.20][VCalc 3.0 soon...]toxcct wrote:
thanks to mickael...
no doubt. :)
-Prakash
-
PreTranslateMessage is good but did you consider http://www.codeproject.com/script/comments/forums.asp?msg=1338886&forumid=1647#xx1338886xx[^]
-Prakash
That approach seemed to stop the dialog box from begin closed by any means so I ruled it out. I don't actually remember him saying he uses MFC, but that seems to be assumed in this forum. I try to steer clear of MFC in my own projects although I use it extensively at work. The MFC source code is a valuable resource however. Steve