Solved

Dialog Box Scrolling needed (VC++5.0)

Posted on 1998-08-17
3
173 Views
Last Modified: 2010-04-10
Hi,

Looking for a step by step approach to implement scrolling in a dialog box. I have seen an answer to a previously asked question which says that once you add the scrollbars, scrolling will be implemented automatically if the text/control is out of the dialog box. I have tried and it does not work! The dialog box in the first place would not let me build controls that do not fit it. Would really appreciate if someone could help me on this !

Thanks,
Arnaud.
0
Comment
Question by:decornez
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
Answers2000 earned 50 total points
ID: 1170502
The scrollbars won't automatically move the controls around (CFormView will if you use it's scroll bars, but the implementation code is built into MFC not windows).

The easiest way to do this is to add scroll bars to your dialog, and respond to the scroll bar messages (WM_HSCROLL, WM_VSCROLL).  When you get the scroll messages, you then move all the other controls on the dialog.  For example to move a control one unit left, do something like this

CWnd * pCtrl = GetDlgItem(ID_CONTROL) ;
CRect rect ;
pCtrl->GetWindowRect( &rect ) ; // get old position, will be in screen coords
ScreenToClient( &rect ) ; // convert coords to position on dialog
rect += CPoint( -1, 0 ) ; // move 1 pixel left, 0 in vertical pos
pCtrl->MoveWindow( rect ) ; // move to new position

In your code you'll have to do this for all controls on the dialog.  You can write generic code using EnumChildren
0
 

Author Comment

by:decornez
ID: 1170503
The answer given to me looks good. I'll just have to try it out and see whether I can get it to work. Thanks.
0
 

Author Comment

by:decornez
ID: 1170504
I did try it in the end and it works perfectly. Great help from Answers2000 !
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now