Example: Low-Level Keyboard Handler

The KBdemo program is a modified version of the Panner program that uses the low-level keyboard handler rather than menu selections to control the panning. One important difference between the two programs is their message loops. Panner uses the "traditional" message loop, while KBdemo uses an animation-based message loop with the same structure as the Scroller example. That is, when the message queue is empty, KBdemo's message loop calls a function CheckForPanning(), which in turn checks if certain keys are pressed and then performs the requested panning.

Another difference between the two programs is how they disable further panning in a given direction once we've reached the edge of the image. Recall that Panner grays out the corresponding menu item when we can no longer pan in that direction, making it impossible to activate the menu item's event handler. KBdemo doesn't use a menu, so we instead use four global variables CanGoLeft, CanGoRight, CanGoUp, and CanGoDown. These globals are set to TRUE where we enable the analogous menu item in Panner, and FALSE where we disable it. We then use their values in CheckForPanning() to see whether or not we can pan in the requested direction.

In KBdemo, the four arrow keys are equivalent to Panner's Left, Right, Up, and Down menu items, and the Escape key is the equivalent of Panner's Reset menu item.

C/C++ version

C++Builder version

Delphi version

Visual Basic version

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.