News | Articles | Libraries | Developer Tools | Books | Forum Links | Search   
Sections:
 

QA: How do I scroll the contents of a dialog?

By Joao Paulo Figueira, September 22, 2003.
Print version

Question

I have a dialog that does not fit on the screen. How can I scroll its contents?

Answer

The short answer is no: dialogs were not meant to be scrolled. However, we can achieve a similar effect using a dialog, a scroller window and a property page. The principles are the same as the ones presented by Daniel Strigl's article QA: How can I create a wizard style dialog?.

Implementation

This solution uses three classes: CScrollDialog, CPageContainer and a CPropertyPage-derived class. This one is created like a normal property page without border. You can add all the controls you want (screen size is not a limitation).

The property page is managed (scrolled) by an instance of CPageContainer. This class serves the only purpose of containing the property page and managing the scrolling. It also manages the data updating when the user clicks OK on the containig dialog.

Finally, the CScrollDialog is the class that implements the containing dialog. In the sample application, this dialog contains a property sheet-like header and the child dialog (contained in an instance of CPageContainer), occupies the rest of the user area.

In a nutshell: CScrollDialog contains CPageContainer that contains a CPropertyPage.

Using the Scrollable Dialog

Using the dialog is simple. You declare an instance of CScrollDialog and another of the CPropertyPage-derived class. Set the dialog variables, use the SetPage() method, and you are set:

// CChildView::OnScrollDialog // // Displays the scroll dialog // void CChildView::OnScrollDialog() { CScrollDialog dlg(_T("Scroll Dialog Demo")); CDemoPage page; page.m_strName = m_strName; dlg.SetPage(&page); if(IDOK == dlg.DoModal()) { m_strName = page.m_strName; } }

And that's it.

Sample

You can download a sample here - ScrollDlgDemo.zip (150K).

Related resources:

Discuss

Discuss this article. Here you can write your comments and read comments of other developers.
Rate this article:     Poor Excellent    
 12345 
© 2001-2005 Pocket PC Developer Network, a division of Spb Software House