• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 779
  • Last Modified:

sensing WM_KEYDOWN in modeless dialog

I have a modeless dialog with several controls in it (buttons, listbox, edit box).  Whenever the dialog box is selected, I want to be able to hit an accelerator key and have it pop up another dialog box.  I tried handling WM_KEYDOWN in the dialog box itself, and it didn't work--the messages are going to one of the controls (depending on which one has the focus).  Do I need to make each of the controls able to handle the WM_KEYDOWN message, or is there an easier way?  TIA for the help!
  • 2
1 Solution
danbindAuthor Commented:
Edited text of question.
Do it in PreTranslateMessage function. If you want to handle the message, return FALSE after preocessing. Otherwise let it go to next window..

BOOL CAdderDialog::PreTranslateMessage(MSG* pMsg)
      if (pMsg->message == WM_KEYDOWN) {
            TRACE0 (_T ("Key down\n"));
      return CDialog::PreTranslateMessage(pMsg);
danbindAuthor Commented:
Bingo!  This works, and makes sense.  Thanks a lot.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now