Solved

Dialog Box Scrolling needed (VC++5.0)

Posted on 1998-08-17
3
174 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

810 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