dialog box IDCANCEL message when button is focused?

I have a dialog box with several buttons. I want to be able to use the escape key to close the dialog box. I'm currently using the IDCANCEL identified on the WM_COMMAND message to do this. However, if I have a button currently focused, pressing the escape key causes a system beep and doesn't send the IDCANCEL message. Is there a way to fix this without using Accelerators?

TIA

--Chris
[418 byte] By [flyingcowofdoom] at [2007-11-19 6:28:27]
# 1 Re: dialog box IDCANCEL message when button is focused?
Are you using MFC? If so, there shouldn't be any problem with having a button in focus and pressing ESC - the dlg should still go away.

Can you zip up your project and attach it, so we can take a look at your button handling code?

Arjay
Arjay at 2007-11-11 0:31:02 >
# 2 Re: dialog box IDCANCEL message when button is focused?
No, I'm not using MFC. The program is a DLL and does not have a message loop, which is why I can't use accelerators. I also have a system hotkey for a different function, but that also beeps when a button is focused. This won't run on your computer because you do not have the appropriate databases, and unfortunately I can't post them. I hope you will be able to help anyway.

TIA

--Chris
flyingcowofdoom at 2007-11-11 0:32:02 >
# 3 Re: dialog box IDCANCEL message when button is focused?
Maybe u should look for a WM_KEYDOWN command and look for the ESC key pressed
miteshpandey at 2007-11-11 0:33:04 >
# 4 Re: dialog box IDCANCEL message when button is focused?
No, I'm not using MFC. The program is a DLL and does not have a message loop, which is why I can't use accelerators. I also have a system hotkey for a different function, but that also beeps when a button is focused.Sorry, I won't be able to help. What I can suggest is to create a couple of very simple projects (an exe and dll) that will help you isolate your issue. By doing this, you will be able to determine if there is a messaging problem in your approach, or if some other part of the application is interferring.

In other words, divide and conquer. Good luck.

Arjay
Arjay at 2007-11-11 0:34:10 >
# 5 Re: dialog box IDCANCEL message when button is focused?
Does tabbing work ? I suspect the message pump code is doing something fishy..
kirants at 2007-11-11 0:35:11 >
# 6 Re: dialog box IDCANCEL message when button is focused?
Bingo! Thank you miteshpandey, that worked perfectly!

--Chris
flyingcowofdoom at 2007-11-11 0:36:13 >
# 7 Re: dialog box IDCANCEL message when button is focused?
I am curious. Does tabbing across buttons work ? I am suspecting, the message pump isn't calling IsDialogMessage.
kirants at 2007-11-11 0:37:06 >
# 8 Re: dialog box IDCANCEL message when button is focused?
Yes, tabbing does work.

--Chris
flyingcowofdoom at 2007-11-11 0:38:09 >