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

Thread: fail to catch WM_KEYDOWN in a modeless dialog

  1. #1
    Join Date
    Jul 2002
    Posts
    372

    fail to catch WM_KEYDOWN in a modeless dialog

    hi,

    my application main window is a modeless dialog.
    no matter what i did, i failed to catch the WM_KEYDOWN message.

    anything that i miss about a modeless dialog ?

    thanks

  2. #2
    Join Date
    May 2005
    Posts
    121

    Re: fail to catch WM_KEYDOWN in a modeless dialog

    Are you using MFC?

    If you are then you can achieve what you want by overriding PreTranslateMessage. Not being able to catch WM_KEYDOWN etc is a common problem.

    Have a look here: http://www.codeproject.com/dialog/pretransdialog01.asp

    Or just google for WM_KEYDOWN dialog PreTranslateMessage! :-)

    Markus

  3. #3
    Join Date
    Jul 2002
    Posts
    372

    Re: fail to catch WM_KEYDOWN in a modeless dialog

    hi,

    already done that, with no help.
    i dont even see key strokes in the Spy++.

    very wired...

  4. #4
    Join Date
    May 2002
    Location
    India
    Posts
    268

    Re: fail to catch WM_KEYDOWN in a modeless dialog

    Hi,
    Are you trying to catch for any specific key or for all keys? Some keys not caught by OnKeyDown will be caught in OnChar. Can you tell us whcih key(s) you are trying to catch?
    Life is short, enjoy it with a smile as long as it lasts.
    User error. Replace User and press any key when ready. - Anonymous

  5. #5
    Join Date
    Jul 2002
    Posts
    372

    Re: fail to catch WM_KEYDOWN in a modeless dialog

    VK_RETRUN and VK_ESCAPE.
    no matter what i try i fail to catch them.

  6. #6
    Join Date
    Feb 2002
    Posts
    3,788

    Re: fail to catch WM_KEYDOWN in a modeless dialog

    Quote Originally Posted by neo_the_1
    VK_RETRUN and VK_ESCAPE.
    no matter what i try i fail to catch them.
    instead of trying to trap those keys, you can handle OnOK() - which correspond to VK_RETURN and OnCancel() - VK_ESCAPE. This is the normal way of doing things.

  7. #7
    Join Date
    Feb 2000
    Location
    Rennes, France
    Posts
    624

    Re: fail to catch WM_KEYDOWN in a modeless dialog

    Does it happen on a specific control, like a listcontrol??
    You can check that in the properties you check the box : Want key input, or Want Return
    I had trouble with that. Hopefully I needed to handle the RETURN key, so I overrode OnOK();

    Marina
    Please go vote for your country!

  8. #8
    Join Date
    May 1999
    Location
    DELAWARE, USA
    Posts
    9,917

    Re: fail to catch WM_KEYDOWN in a modeless dialog

    neo_the_1,
    My advice is stay away from PreTranslateMessage. It is not a good place to do anything but translating accelerators, filtering tooltip messages, translating dialog messages.

    Dialog that contains at least one control, never has focus.
    Marina Vaillant already addressed first point: what control you are trying to do it?
    Did you assign any accelerator keys?
    What keystrokes are you trying to catch?
    We need more information; what is exactly that is giving you a hard time?
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  9. #9
    Join Date
    May 2002
    Location
    India
    Posts
    268

    Re: fail to catch WM_KEYDOWN in a modeless dialog

    My advice is stay away from PreTranslateMessage. It is not a good place to do anything but translating accelerators, filtering tooltip messages, translating dialog messages.
    I strongly agree with this. As pointed out in other replies it will better if you try & override OnOK & OnCancel.
    Life is short, enjoy it with a smile as long as it lasts.
    User error. Replace User and press any key when ready. - Anonymous

  10. #10
    Join Date
    Jul 2002
    Posts
    372

    Re: fail to catch WM_KEYDOWN in a modeless dialog

    i forgot to mention that i remoed the OK\Cancel button.
    i managed to catch WM_KEYDOWND in a child button.
    thank you all.

  11. #11
    Join Date
    May 1999
    Location
    DELAWARE, USA
    Posts
    9,917

    Re: fail to catch WM_KEYDOWN in a modeless dialog

    Quote Originally Posted by neo_the_1
    i forgot to mention that i remoed the OK\Cancel button.
    i managed to catch WM_KEYDOWND in a child button.
    thank you all.

    Why did you do that?
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

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




On-Demand Webinars (sponsored)