Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

A Simple Way for Changing the Content of the Dialog

0.00/5 (No votes)
29 Feb 2004 1  
A simple way for changing the content of the dialog .

Destination

While elaborating on user's interface, we encounter with the issue of Dialog Content Window Changing while choosing any element of administration (Combo Box).

This article reproduces the method of realization of given chance.

Instruction

At first you are to create the parent window, the content of which will change, and place in it the element of administration managing the change. Let the falling list (ComboBox) control the change of the content of parent window. The child windows will be placed to the area framed by the rectangle control element - Picture, Type - Frame).

Now it's high time to create the child window - dialog window with the characteristics of Style - Child, Border - None and corresponding sizes. To create the child class for each dialog, children from CDialog.

  • CDialogDlg - parent's windows (Dialog based application);
  • CChildDlg1 - the first child's windows;
  • CChildDlg2 - the second child's windows.

Add to DialogDlg.h:

    #include "ChildDlg1.h";

    #include "ChildDlg2.h";

Add to determining the CDialogDlg class:

    public:
        CChildDlg1 m_View1;
        CChildDlg2 m_View2;

Then, add to the CDialogDlg::OnInitDialog() function, before return TRUE, the following text:

    CWnd* pWnd = GetDlgItem( IDC_FRAME );
    CRect rect;
    pWnd->GetWindowRect( &rect );
    ScreenToClient( &rect );

    //Creating a ChildDld1

    m_View1.Create( IDD_VIEW1, this );
    m_View1.ShowWindow( WS_VISIBLE | WS_CHILD );
    m_View1.SetWindowPos( pWnd, 0, rect.top, rect.right, 
                               rect.bottom, SWP_SHOWWINDOW );

    //Creating a ChildDld2

    m_View2.Create( IDD_VIEW2, this );
    m_View2.ShowWindow( WS_VISIBLE | WS_CHILD );
    m_View2.SetWindowPos( pWnd, 0, rect.top, rect.right, 
                               rect.bottom, SWP_HIDEWINDOW );

    m_Select.SetCurSel(0); //Setting first element of a ComboBox

To create function of the falling list (ComboBox), the content of which will change:

    if (m_Select.GetCurSel() == 0)
    {
        m_View1.ShowWindow(SW_SHOW);
        m_View2.ShowWindow(SW_HIDE);
    } 
    else
    {
        m_View1.ShowWindow(SW_HIDE);
        m_View2.ShowWindow(SW_SHOW);
    }

It's compiling and running.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here