Welcome

Wheresoever you go, go with all your heart. (Confucius)

11/16/2010

[MFC] using Formview Dialog

In many case of the form design,
you need to attach the designed form to other forms.
To achieve this purpose, we can use the formview dialog.
The formview dialog is not special.
Of options of the general dialog, you set up such as Boder = false and Style = Child.

For example, consider that IDD_FORMVIEW and IDD_FORMVIEW2 is designed.

And you want to attach these to other form views or dialogs.
The source code is the following

// CTestLocalPanel *panel;   -- class CTestLocalPanel : public CDialog for IDD_FORMVIEW
// CTestLocalPanel *panel2;   -- class CTestLocalPanel2 : public CDialog for IDD_FORMVIEW2

void CTestMFCView::OnBnClickedButton1()
{
    if( panel2 )
    {
        panel2->ShowWindow(SW_HIDE);
        panel2->DestroyWindow();
        delete panel2;
        panel2 = 0;
    }
    if( !panel )
    {
        CRect rect;
        panel = new CTestLocalPanel();
        panel->Create(IDD_FORMVIEW, this);
        panel->GetWindowRect(&rect);
        panel->MoveWindow(5, 150, rect.Width(), rect.Height()); // Moving Dialog forms into the specific position
        panel->ShowWindow(SW_SHOW);
    }

    UpdateData(false);
}
void CTestMFCView::OnBnClickedButton2()
{
    if( panel )
    {
        panel->ShowWindow(SW_HIDE);
        panel->DestroyWindow();
        delete panel;
        panel = 0;
    }
    if( !panel2 )
    {
        CRect rect;
        panel2 = new TestLocalPanel2();
        panel2->Create(IDD_FORMVIEW1, this);
        panel2->GetWindowRect(&rect);
         ->MoveWindow(5, 150, rect.Width(), rect.Height());
        panel2->ShowWindow(SW_SHOW);
    }

    UpdateData(false);
}

No comments: