WM_KEYDOWN and focus
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: WM_KEYDOWN and focus

  1. #1
    Join Date
    Dec 2007
    Location
    France
    Posts
    274

    WM_KEYDOWN and focus

    If I click on a button then it will keep the focus and I won't get any WM_KEYDOWN messages any more as long as I dont click outside and then back on the window.

    What is the cause of this behaviour and how to avoid it?

    The button:
    Code:
        switch (message)
        {
        case WM_CREATE:
            CreateWindowExA(WS_EX_CLIENTEDGE,"BUTTON", "Play",
                WS_CHILD|WS_VISIBLE,
                20, 20, 80, 25, hWnd,
                (HMENU)IDB_PLAY, 0, NULL);
    Last edited by MasterDucky; July 12th, 2014 at 05:50 AM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,608

    Re: WM_KEYDOWN and focus

    Quote Originally Posted by MasterDucky View Post
    If I click on a button then it will keep the focus and I won't get any WM_KEYDOWN messages any more as long as I dont click outside and then back on the window.

    What is the cause of this behaviour?
    It is "by design". Example: you "click" some button (press but release it yet!), but then you understand that this button-click would be wrong. So you move cursor from this button and after that release the button. In such a case no button-click event will be generated.
    Quote Originally Posted by MasterDucky View Post
    I... how to avoid it?
    What for?
    Victor Nijegorodov

  3. #3
    Join Date
    Dec 2007
    Location
    France
    Posts
    274

    Re: WM_KEYDOWN and focus

    Yes but I need to push that button to start the application. After that on the other hand I want to handle WM_KEYDOWN messages.

    But since the focus stays on the button I dont get the WM_KEYDOWN messages.

  4. #4
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,854

    Re: WM_KEYDOWN and focus

    In the code that handles the button click have you tried changing the focus?
    See http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  5. #5
    Join Date
    Dec 2007
    Location
    France
    Posts
    274

    Re: WM_KEYDOWN and focus

    It worked. Thank you.

    First I put it in the case that called the play() in the menu not on the button that's why it didn't work.

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,071

    Re: WM_KEYDOWN and focus

    Quote Originally Posted by MasterDucky View Post
    Yes but I need to push that button to start the application. After that on the other hand I want to handle WM_KEYDOWN messages.

    But since the focus stays on the button I dont get the WM_KEYDOWN messages.
    Forcible focus displacing is a sort of inelegant solution as for me.

    There are several standard mechanisms in Windows to process keyboard input transparently and independent of current focus location: 1) translating accelerators, 2) hooking message loop and 3) hooking keyboard input at low level. All those ones have their merits and demerits, depending on the ultimate goals to be achieved.
    Best regards,
    Igor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center