What the...?

Something bad happened

We're not sure what, but we have a few guesses.

Problem: Object reference not set to an instance of an object.
Ticket: 7864825
Server: Web02
Scroll Window - CodeProject Click here to Skip to main content
11,715,022 members (74,883 online)
Click here to Skip to main content

Scroll Window

, 23 Mar 2008 CPOL 28.5K 1.9K 17
Rate this:
Please Sign up or sign in to vote.
A scroll window that surpasses the 16-bit limit and can be hosted by a dialog.



CScrollView cannot be created on a dialog. Furthermore, the size of the scrolling region is bound to the signed 16-bit limit.

To resolve the above problems, I wrote CScrollWindow which derives from CWnd. Besides, I removed the mapping mode support because I don't find it useful for anyone. All the dimensions are in device units. In addition, the window would not assert if you forget to set the scroll sizes. The default scrolling region size is 0x0.


Most of the code is based on the MFC source code of CScrollView.

Using the code

Although CScrollWindow works with any CWnd and derivatives, including CDialog, I embed it in a CFrameWnd in the below example. You would typically add a member of the type CSrcollWindow or derivatives in your CFrameWnd.

CScrollWindow m_ScrollWindow;

In the OnCreate of you CFrameWnd, create the scroll window and set the scroll sizes.

if (!m_ScrollWindow.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,
    CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL))
    TRACE0("Failed to create scroll window\n");
    return -1;
m_ScrollWindow.SetScrollSizes(CSize(65536, 65536));

Points of interest

When I was new to VC++, I was very surprised when an experienced programmer told me that he hated MFC, which was supposed to be great at that time. Now, when I am quite familiar with it, I realize that it has many limits that tied the hands and legs of the coder and hurt his brain. Nevertheless, it's better to find a way to live with it instead of leaving it.


This is the first version.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Tu (Le Hong)
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralMy vote of 2 Pin
RDSchaefer16-Apr-12 14:32
memberRDSchaefer16-Apr-12 14:32 
GeneralThis class CScrollWindow was exactly what I was looking for Pin
Blair Whitney19-May-08 15:46
memberBlair Whitney19-May-08 15:46 
GeneralSome suggestions Pin
Sam Levy24-Mar-08 12:11
memberSam Levy24-Mar-08 12:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150901.1 | Last Updated 23 Mar 2008
Article Copyright 2008 by Tu (Le Hong)
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid