Auto-Panning Windows

CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

It implements an MFC extension class that adds IntelliMouse panning to CScrollView or any window with scroll bars. There is already one example of this in circulation (George Shepherd and Scot Wingo at MSJ Dec97) but the implementation is quite weak. Their version caused lots of flickering, incorrect paintings etc. So I wrote my own auto-panning windows extention.

As part of the IntelliMouse specification, a variety of cursors defined to be used in IntelliMouse panning. When a user clicks the mouse wheel / middle mouse button to initiate scrolling or moves the cursor back to the neutral zone (the area around the panning origin), one of three standard cursors appears, telling the user what level of panning support is provided.

Auto-Panning Windows Example imageIndicates when two-dimensional panning is supported.

Auto-Panning Windows Example imageIndicates that vertical-only, one-dimensional panning is available.

Auto-Panning Windows Example imageIndicates that horizontal-only, one-dimensional panning is available.

This is achieved through creating only one addition control named CWheelWnd. The control is very simple. It creates a floating popup window over the scrolling window, and controls the movements of the scrolling window until presses mouse wheel button. To add this functionality to your CScrollView based window or any other scrolling window add the following code to your OnMButtonDown function.

void CAutoPanView::OnMButtonDown(UINT nFlags, CPoint point)
{
    BOOL bCtl = GetKeyState(VK_CONTROL) & 0x8000;
    if(!bCtl && nFlags == MK_MBUTTON)
    {
        MfxTrackAutoPan(this);
    }
    else
    {
        CScrollView::OnMButtonDown(nFlags, point);
    }
}

Also, given resources must be included to the project with given IDs.

Resource	ID
--------------  -------------
autopan.bmp	IDC_AUTOPAN
pan_up.cur	IDC_PAN_UP
pan_down.cur	IDC_PAN_DOWN
pan_left.cur	IDC_PAN_LEFT
pan_right.cur	IDC_PAN_RIGHT

Happy Scrolling 🙂

Download demo project – 38KB

Download source – 4.9KB

Date Posted: 5/6/98

Posted by: Pat Laplante.

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read