Book Image

Microsoft Visual C++ Windows Applications by Example

By : Stefan Bjornander, Stefan Björnander
Book Image

Microsoft Visual C++ Windows Applications by Example

By: Stefan Bjornander, Stefan Björnander

Overview of this book

Table of Contents (15 chapters)
Microsoft Visual C++ Windows Applications by Example
Credits
About the Author
About the Reviewer
Preface
Index

Catching the Keyboard Input


When the user presses a key on the keyboard, a message is sent to the view. We can catch that message in the same manner as we caught the mouse click.

Let us use the keyboard to simulate scroll movements.

RingView.cpp

void CRingView::OnKeyDown(UINT nChar, UINT nRepCnt,
                          UINT nFlags)
{
  switch (nCh

ar)
  {
    case VK_UP:
      OnVScroll(SB_LINEUP, 0, NULL);
      break;

    case VK_DOWN:
      OnVScroll(SB_LINEDOWN, 0, NULL);
      break;

    case VK_PRIOR:
      OnVScroll(SB_PAGEUP, 0, NULL);
      break;
    case VK_NEXT:
      OnVScroll(SB_PAGEDOWN, 0, NULL);
      break;

    case VK_LEFT:
      OnHScroll(SB_LINELEFT, 0, NULL);
      break;

    case VK_RIGHT:
      OnHScroll(SB_LINERIGHT, 0, NULL);
      break;

    case VK_HOME:
      OnHScroll(SB_LEFT, 0, NULL);
      break;

    case VK_END:
      OnHScroll(SB_RIGHT, 0, NULL);
      break;
  }

  CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
}