Thread: WM_KEYDOWN oddity

  1. #1
    Registered User
    Join Date
    Sep 2005

    WM_KEYDOWN oddity

    Probably a simple explanation for this, but it's eluded me so far. If I check for a WM_KEYDOWN message in the window procedure for a completely blank dialog window (ie. no controls, buttons etc.), it's detected, but if there are any controls in the resource script for the dialog box (even just a single line of static text), the WM_KEYDOWN message seemingly goes undetected. Any ideas?

  2. #2
    Registered User
    Join Date
    Jun 2003
    I'm pretty sure it's due to your main window losing focus. If the HWND of your Main Window was hWnd, you'd have to use:
    To return the focus back to your window, and the WM_KEYDOWN will fire again. You'll just have to find the areas in your code where it's appropriate to return the focus back to your main window and throw that in (I.e. after the creation of any new child windows).

    The reason behind this is that in cases like an Edit Box, it wouldn't make sense if the user was typing in it, and at the same time firing off WM_KEYDOWNs, otherwise some pretty crazy things could be happening.

    Some controls (Static, Listbox, Button, etc.) can be created with the *_NOTIFY style. For a Listbox, it is LBS_NOTIFY, which sends Click notifications (the default doesn't send these messages). Other controls have their own special style for notification, while others, like the Edit, doesn't. You can read more about it here:

    However, I don't think there is a style flag which changes any KeyPress notifications.
    Last edited by Epo; 09-06-2005 at 10:55 PM.
    Pentium 4 - 2.0GHz, 512MB RAM
    NVIDIA GeForce4 MX 440
    Visual Studio .Net 2003
    DX9 October 2004 Update (R.I.P. VC++ 6.0 Compatability)

  3. #3
    Registered User
    Join Date
    Sep 2005
    Thanks. I think I need to experiment a bit with Get/SetFocus() to determine/set where the keyboard focus needs to be.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. EOF Oddity
    By Anonymous in forum C Programming
    Replies: 9
    Last Post: 11-28-2002, 04:51 AM
Website Security Test