WM_KEYDOWN oddity

This is a discussion on WM_KEYDOWN oddity within the Windows Programming forums, part of the Platform Specific Boards category; Probably a simple explanation for this, but it's eluded me so far. If I check for a WM_KEYDOWN message in ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    10

    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
    Epo
    Epo is offline
    Registered User
    Join Date
    Jun 2003
    Posts
    361
    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:
    Code:
    SetFocus(hWnd);
    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.

    Alternatively:
    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:
    http://msdn.microsoft.com/library/de...divcontrol.asp

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

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    10
    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, 05:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21