IntelliMouse support

IntelliMouse support

This article was submitted .

This sample demonstrates how to add IntelliMouse support to a WTL window.

IntelliMouse is a Microsoft invention that allows you to pan and zoom data in a window using the middle mouse button. The idea saw its light when the new mouse-wheel appeared on Microsoft mouse hardware, and using different combinations of scrolling, clicking and the CTRL and SHIFT keys, one can pan, zoom and scale windows with the middle mouse-button (or mouse-wheel).

The IntelliMouse SDK (there is actually an IntelliMouse SDK) defines the following actions:

  Mouse Control Operation
  Wheel rotation Scrolling
  Ctrl+wheel rotation Zooming
  Shift+wheel rotation Datazoom
  Wheel button click and drag Panning
  Wheel button click Autoscroll

Scrolling and zooming seems logical actions for the mouse, but "Autoscroll"? These are actually subtle features in various Internet Explorer and Office products. IE lets you move back and forward in the URL history, and Office also defines some neat behaviours in different views.

On some systems the IntelliMouse system may seem to already magically work on all applications you load. This is because it has the IntelliMouse mouse driver installed. This driver hooks up all child windows and adds scroll support for many of them, including the TreeView and ListView controls, and seems to translate scrolling into WM_VSCROLL and WM_HSCROLL messages if the application doesn't handle the middle mouse itself. On systems without this driver, you'll have to add the support yourself.

To obtain the "MS Office 97 Logo approval" your application was actually required to support IntelliMouse (I don't think any product have been discarded because of this feature though... or for any missing feature for that matter). This is of course a promotional stunt, but don't be afraid to add cool user-friendly navigation to your own application. Lack of mouse-wheel support is just something that annoys users who are used to work in MS Office products.

How to use it

The sample contains a generic class, CIntelliMouseImpl which has the basic implementation of an IntelliMouse system. Your software probably requires a different / custom method of scrolling the view, so re-defining the scrolling mechanism, the way movement is communicated to the view window or the way the scrolling speed is determined, might be needed. To do this, you derive from the CIntelliMouseImpl class and implement your own custom IntelliMouse class where all the scrolling rules are defined.

This will basically just be a simple class where you override the following callback methods:

  void OnInstall(HWND)
  int OnCalculate(POINT, SIZE&)
  void OnMove(POINT)
  void OnZoom(POINT)
  void OnScroll(POINT)
  void OnDataScroll(POINT)
The base class calls the OnCalculate method to determine the scrolling speed/movement and the shape of the cursor (arrow points in the direction of the scroll). The remaining methods are called when one of the IntelliSense actions should be carried out. Internally these actions will probably end up calling OnCalculate to help them asses how much to scroll.

To use the class, add your CIntelliMouseXXX member variable to a window class and call the installation method.

  CIntelliMouseXXX m_Pan;
Now, all you need to do is click on the middle mouse button.

Your window should include support for some kind of scrolling. The sample class provided in the download file simply manipulates the existing scrollbars in the parent class, and thus assuming that both WS_VSCROLL and WS_HSCROL are being handled and enabled in the parent.

The code subclasses the parent window (identified by m_hWnd in the Install method). It does this to monitor messages that causes the panning to be cancelled. Be carefull if you override message handlers for the mouse button actions in the main view, because the IntelliMouse system must be able to handle them as well.

Source Code Dependencies

Microsoft Visual C++ 6.0
Microsoft WTL 7.0 Library

Download Files

DownloadSource Code and Sample (103 Kb)

To the top