Click here to Skip to main content
15,867,453 members
Articles / Desktop Programming / MFC
Article

How to implement a scrollable child dialog

Rate me:
Please Sign up or sign in to vote.
4.96/5 (52 votes)
11 May 2003Public Domain1 min read 252K   9.3K   86   36
How to implement a scrollable child dialog

Sample Image - ScrollableChildDialog.jpg

Introduction

Many times it happened to me (and I hope to you too!) the need for a kind of child dialog, to use as a control inside a more bigger dialog or window or view etc. Filling this child dialog of controls is easy. Set the size of it to fit inside the parent window is not so easy. So, here is the scrollable child dialog, which i found veeeeery useful in my applications.

The code

The code is really simple and is strongly based on the MSDN article HOWTO: Create a Resizable Dialog Box with Scroll Bars (Q262954). I simply created the scrollable dialog template choosing the WS_CHILD and WS_VSCROLL styles and used class wizard to add WM_SIZE, WM_MOUSEWHEEL and WM_VSCROLL messages. To use the code in your project follow these steps:

  1. Add dlgscrollable.h and dlgscrollable.cpp to your project
  2. Create your own dialog resource template and replace the resource identifier in the header file
  3. In the parent window, add a member variable like CDlgScrollable* m_pdlgScrollable and in the OnInitDialog function, create the new CDlgScrollable object.
  4. In the parent dialog resource template, you can use a static as a placeholder to calc the rectangle of my scrollable child control.
  5. You can easily change the "hand" cursors, loading different resources as needed

It's obviously really simple add support for horizontal scroll, it's symmetric and I didn't really need that... :P

And so...

That's all! I'm sorry for my bad English (I'm Italian), this is my first article. Hope not my last one! Thanx to DD and GM for their suggestions and comments, this is the last version of the code, or at least the last version for the next two months! Have fun!

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication


Written By
Software Developer (Senior) Leonardo
Italy Italy
Hi Smile | :)
I was born in 1970 (Augusta - Italy).
I live in Taranto - Italy.
I work in Taranto - Italy.
I like computer science!!!
That's all!

Comments and Discussions

 
GeneralMousewheel does not work. Pin
Brian van der Beek22-May-03 5:08
Brian van der Beek22-May-03 5:08 
GeneralRe: Mousewheel does not work. Pin
Massimiliano Conte23-May-03 1:40
Massimiliano Conte23-May-03 1:40 
GeneralRe: Mousewheel does not work. Pin
sonu_22413-Aug-07 1:50
sonu_22413-Aug-07 1:50 
GeneralRe: Mousewheel does not work. Pin
adzm5-Feb-10 9:43
adzm5-Feb-10 9:43 
GeneralJust one more thing... Pin
Iv7-May-03 6:10
Iv7-May-03 6:10 
GeneralRe: Just one more thing... Pin
Massimiliano Conte7-May-03 20:27
Massimiliano Conte7-May-03 20:27 
GeneralAlternatives to a scrollbar... Pin
Duncan Edwards Jones7-May-03 0:52
professionalDuncan Edwards Jones7-May-03 0:52 
GeneralQuite incredible indeed... Pin
Stephane Rodriguez.7-May-03 0:42
Stephane Rodriguez.7-May-03 0:42 
...that you won't find any code for this in CodeProject/CodeGuru. I have had this need no more than a few days ago, to help me contain an xml-based UI.
Thanks for the article. Wink | ;)
GeneralRe: Quite incredible indeed... Pin
Anonymous8-May-03 5:33
Anonymous8-May-03 5:33 
GeneralRe: Quite incredible indeed... Pin
Anonymous8-May-03 7:10
Anonymous8-May-03 7:10 
GeneralRe: Quite incredible indeed... Pin
Anonymous8-May-03 11:30
Anonymous8-May-03 11:30 

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

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