Click here to Skip to main content
15,868,016 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

 
GeneralMy vote of 5 Pin
Shao Voon Wong9-Feb-20 15:12
mvaShao Voon Wong9-Feb-20 15:12 
QuestionLicense? Pin
Member 10018999-Apr-15 8:11
Member 10018999-Apr-15 8:11 
AnswerRe: License? Pin
Massimiliano Conte22-Oct-15 22:13
Massimiliano Conte22-Oct-15 22:13 
GeneralExplanation of some magic numbers Pin
Bati92-Dec-08 10:50
Bati92-Dec-08 10:50 
GeneralRe: Explanation of some magic numbers Pin
Massimiliano Conte2-Dec-08 20:57
Massimiliano Conte2-Dec-08 20:57 
QuestionEvent handling in the parent Dialog? Pin
Seife13-Sep-07 3:59
Seife13-Sep-07 3:59 
Questionpb when using your code !!! [modified] Pin
aabdoos15-Dec-06 1:43
aabdoos15-Dec-06 1:43 
QuestionIDC_PLACEHOLDER what's it? Pin
shinshit10-Nov-06 2:16
shinshit10-Nov-06 2:16 
AnswerRe: IDC_PLACEHOLDER what's it? Pin
Massimiliano Conte10-Nov-06 3:02
Massimiliano Conte10-Nov-06 3:02 
QuestionCenter dialog on startup? Pin
rturrentine25-May-05 6:03
rturrentine25-May-05 6:03 
GeneralSome notes and adjustements Pin
Davide Zaccanti27-Mar-05 20:32
Davide Zaccanti27-Mar-05 20:32 
GeneralGreat but... Pin
pgiustinoni28-Feb-05 14:01
pgiustinoni28-Feb-05 14:01 
GeneralResizing original dialog Pin
andrew_lowry15-Apr-04 3:50
andrew_lowry15-Apr-04 3:50 
Generalfix for embedded visual c++ 4.0 Pin
14-Mar-04 7:42
suss14-Mar-04 7:42 
Many thanks for your excellent work!

This class is very usefull if you write software for Win CE!

I had the same problem mentioned in another post:
I couldn't scroll the content of the window. The sample application worked with Win XP but didn't work with Win CE. After a few trial and errors I figured out that I could move the content using ScrollWindow() in OnInitDialog(). Nothing happens if you call this function after when dialog is displayed.

I tried some Invalidate() / UpdateWindow() commands in OnVScroll() without any luck.

So my first fix was this:

ShowWindow(SW_HIDE);
ScrollWindow(...);
ShowWindow(SW_SHOW);

This really worked but looked quite ugly.

A better way is replacing ScrollWindow() with ScrollWindowEx() and passing SW_SCROLLCHILDREN:
ScrollWindowEx(..., NULL, NULL, NULL, NULL, SW_ERASE|SW_INVALIDATE|SW_SCROLLCHILDREN);

Cool | :cool:

It's not a bug it's a feature... Poke tongue | ;-P
QuestionHow can I implement this for a Dialog and not a for a child of a Dialog? Pin
DanYELL8-Feb-04 7:54
DanYELL8-Feb-04 7:54 
AnswerRe: How can I implement this for a Dialog and not a for a child of a Dialog? Pin
Massimiliano Conte8-Feb-04 22:46
Massimiliano Conte8-Feb-04 22:46 
QuestionHow can I get this to work with a CFormView? Pin
DanYELL6-Feb-04 6:05
DanYELL6-Feb-04 6:05 
GeneralTab Key and Scroll Dialog box Pin
Anonymous28-Jan-04 22:10
Anonymous28-Jan-04 22:10 
Generalscrollbar position on start Pin
teamghost16-Oct-03 1:47
teamghost16-Oct-03 1:47 
Generalit helped me Pin
sanskypotov3-Sep-03 0:01
sanskypotov3-Sep-03 0:01 
GeneralRe: it helped me Pin
NiFF21-Jun-05 6:07
NiFF21-Jun-05 6:07 
GeneralExact same problem as Keith Pin
yklam15-Jul-03 5:00
yklam15-Jul-03 5:00 
GeneralSolution Found Pin
yklam21-Jul-03 4:50
yklam21-Jul-03 4:50 
QuestionHow to use this powerful class in embedded visual c++ 3.0? Pin
keithse26-Jun-03 11:38
keithse26-Jun-03 11:38 
AnswerRe: How to use this powerful class in embedded visual c++ 3.0? Pin
Kaiserle21-Jul-03 3:44
Kaiserle21-Jul-03 3:44 

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.