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
Using the code
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
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");
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.