tags:

views:

37

answers:

4

I have a window that creates a lot of other common controls such as menus, toolbars with buttons and combo boxes, and a status bar. The problem is that the window never receives a WM_KEYDOWN message whenever I press Enter or Esc, but I need to handle these. Is there any common control that is known to interrupt these keys?

A: 

You can try a few things. 1) If the window is already open, try Window1.Focus(); (MSDN tells you that to focus, a form has to be visible, enabled, and have a handler) 2) If it's not open, try Window1.Activate();

In addition, WM_KEYDOWN can be annoying, you may want to try using SendKeys.Send() or SendKeys.SendWait() to send keystrokes.

codersarepeople
When did I say anything about sending keystrokes? The window is in focus; every other key except Enter and Esc are received by its WndProc.
kaykun
A: 

Windows always sends WM_KEY*** messages to the window that has focus. So, all controls that take focus "interrupt" keyboard messages.

The general way to handle this is implicit in the operation of the IsDialogMessage function.

Keyboard messages are posted to the applications message queue. It is expected that keyboard messages that apply to the application as a whole are processed in the applications message loop. These keystrokes are normally called 'accelerators' and there is an API to deal with them: TranslateAccelerator

Create an accelerator table describing the keystrokes, modify the message loop to pass all messages to TranslateAccelerator first, and you should be good to go.

Chris Becke
A: 

If you don't receive Enter and Esc keydowns, then you're most likely using the dialog translation mechanism: Enter is to dismiss the dialog with OK, Esc to dismiss it with Cancel.

If you need those two keys, you have to intercept the WM_GETDLGCODE message and handle the DLGC_WANTMESSAGE flag. See kb83302 for more details.

Stefan
A: 

I'm writing a plugin for Outlook right now. I have a WinForms control hosted inside and it never receives the backspace key because it looks like the WM_KEY*** is actually turned into a WM_COMMAND in order to implement keyboard accelerators, as is probably your case. Have you tried SPY++?

bowenl2