Click here to Skip to main content
Click here to Skip to main content

Scroll Window

, 23 Mar 2008
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.

ScrollWindow-SourceCode

Introduction

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.

Background

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.

History

This is the first version.

License

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)

Unknown
No Biography provided

Comments and Discussions

 
GeneralMy vote of 2 PinmemberRDSchaefer16-Apr-12 14:32 
GeneralThis class CScrollWindow was exactly what I was looking for PinmemberBlair Whitney19-May-08 15:46 
GeneralSome suggestions PinmemberSam 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 | Mobile
Web01 | 2.8.140721.1 | Last Updated 23 Mar 2008
Article Copyright 2008 by Tu (Le Hong)
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid