A Scrollable Dialog Class (CScrollDialog)

Environment: VC6 SP4, NT4 SP3, Win98

MFC's CDialog class is a powerful and flexible class but it has its shortcomings. If we wish to allow the user to resize the dialog and still retain access to all controls within the dialog, then we must either resize/displace the controls within the dialog, or implement any scrolling functionality ourselves.

There are already a good number of articles in CodeGuru which address the first option. This article essentially presents a solution to the second option, the scrollable dialog option. The class presented here is intended to serve as a starting point for those of you who should ever need to implement scrollability in a dialog; it can be used without modification, or it can be tailored to your needs.

To implement a CScrollDialog, simply do the following:

  1. Derive your dialog from CScrollDialog rather than from CDialog.
  2. Add the header definition at the top of your dialog's header file (ie. #include "ScrollDialog.h")
  3. Size your dialog template in the resource editor to its ideal dimensions.

That's it! Upon creation, the ScrollDialog stores its initial dimensions for later reference. Anything smaller than these will enable the corresponding scrollbar(s).

The code was written with MFC version 4.22, and compiles cleanly with Warning level 4. Unicode compatibility is unknown.

Last but not least, I must mention that the window gripper implementation was drawn from code snippets found in the CodeGuru site. Enjoy.


Download demo project - 20 KB

Download source - 4 KB

This article was originally published on July 3rd, 1999

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date