OnKeyDown function problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lopat
    New Member
    • Aug 2007
    • 3

    OnKeyDown function problem

    Hi!
    I have a problem using the OnKeyDown function in Visual C++ 6.0. The problem is that the source code seems to be all right, but when I press a button I only get a speaker beep and nothing else happens, the function code isn't executed. In the dialog box I also have 2 scrolls and I think that after starting the application they get focus or something like that and the keybord event doesn't even occur. Using keybord I can only move the scrolls with cursors, but that's not what I had in mind:) Can anybody help me?
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    I do not think a dialog box receives keyboard messages.

    Even if it did since the control (scrollbar) is the window with input focus the keyboard events would go there.

    What keys did you want the scrollbars to respond to?

    Comment

    • lopat
      New Member
      • Aug 2007
      • 3

      #3
      I wanted to use W S A D keys. If I disable the scrollbars everything seems to work fine.

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Originally posted by lopat
        I wanted to use W S A D keys. If I disable the scrollbars everything seems to work fine.
        That is because when the scrollbars are disabled they can not have the input focus.

        You want to use W S A D to control the scrollbars?

        If so then subclassing them would let you do it, is this a WIN32 or MFC application?

        Comment

        • lopat
          New Member
          • Aug 2007
          • 3

          #5
          It is a MFC application

          Comment

          • Banfa
            Recognized Expert Expert
            • Feb 2006
            • 9067

            #6
            You will need to subclass the scrollbars, intercept the keydown messages you are interested in (those for A S D W) and then handle them.

            Handling them may just be posting them to the parent window (the dialog box) so that it can handle them or it may be taking other direct action.

            In MFC this sublass is easy, create a new class with CScrollBar as it's parent class. Then you can just added new message map entries to the message map of your class and then where your dialog class is defined use your derived class instead of the default CScrollBar class.

            Comment

            Working...