Auto-Panning Windows 2 | CodeGuru

Auto-Panning Windows 2

This code provides a simple way of adding full AutoScroll capability to pretty much any window, I have provided a demo program which also incorporates the all of the code you need. I believe it works the same way as Internet Explorer, that is all of the behaviour I have seen from IE. The cursor […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 6, 1998
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

This code provides a simple way of adding full AutoScroll capability
to pretty much any window, I have provided a demo program which also incorporates
the all of the code you need. I believe it works the same way as Internet
Explorer, that is all of the behaviour I have seen from IE. The cursor
changes in every direction just as it does in IE, it uses the pointers
and origin bitmaps pretty much the same as IE, these are the cursors and
bitmaps supplied with the Intellipoint SDK with slight modificatiosn to
the bitmaps.


How to use it


OWnd is a DLL, I did it this way because it seemd the easiest way to use


it without having to copy resource fiels etc all over the place, plus it


really is a component that is shared amongst projects. Simply include the


OWnd DLL project

 

in as a subproject of yours, include the OWndDLL.h


file in your relevant source files and call StartPanning(

) in your OnMButtonDown


message handler. That

s it really.



Additionally you can respond to the registered message OWND_WINDOW_UPDATE


if you want to perform extra scrolling, the registered message

 

is


sent every time a scroll event is issued, your message handler should look


something like this:

static const UINT uOriginWindowUpdateMessage = ::RegisterWindowMessage( OWND_WINDOW_UPDATE );

LRESULT CPanningWindowView::OnOriginWindowUpdate(WPARAM , LPARAM lParam)
//
// Process the update message sent by the origin window.
// You only need to respond to this message if you want to do extra or different scrolling
{
    //
    // psizeDistance will contain the distance the cursor is from the origin. We then use
    // this to calculate the new scroll position and the amount to scroll our window.
    const CSize *psizeDistance = reinterpret_cast<const CSize *>( lParam );
#ifdef _DEBUG
    afxDump<<_T("CPanningWindowView::OnOriginWindowUpdatesize")<<*psizeDistance<<_T("n");
#endif // _DEBUG
    //
    // Return 1 to signal to COriginWnd that you have handled the scrolling, return 0 if you
    // want COriginWnd to perform the scrolling.
    return 0;
}


The demo project shows all of this behaviour in the source file PanningWindowView.cpp.

This code imroves over the other examples posted to codeguru in the
following areas:



  • Much closer emulation of IE behaviour, I have tried to do exactly as IE
    does.

  • More easily extended and altered, the other examples have way too many
    hardcoded values scattered throughout the code.

  • Compiles at level four warnings with warnings as errors, it has been linted
    and it has been built and tested in UNICODE

  • Less code.


Please let me know of any bugs, fixes or modifications.

Download demo project and source code – 42KB

Date Posted: 6/24/98

Posted by: Pat Laplante.

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.