본문 바로가기

개발관련/MFC

TabCtrl for multi View

// CTab_CtrlDlg.h

1. make view ( will be attach to tab )

class Child_view : public CDialog
{
public:
     BOOL OnInitDialog();
protected:
     virtual void OnOK() {}
     virtual void OnCancel() {}
}
            

2. make member variable

#define MAX_VIEW    view_cnt                 // total view count
class Tab_CtrlDlg : public CDialog
{
public:
    CDialog       *child_tab[MAX_VIEW];    
    Child_view   child_view;
 
    ....
}

// CTab_CtrlDlg.cpp

1. create tab ( in OnInitDialog )

    CTabCtrl *pChildTab = (CTabCtrl*)GetDlgItem(IDC_TAB_MAIN);    
    child_view.Create( IDD_DLG_VIEW, pChildTab);

    child_tab[0] = &child_view;
                     ...
   
2. set rect

    CRect rect, orect;

    child_tab[0]->GetWindowRect(orect);
    rect.right = ( rect.left = 3) + orect.Width();
    rect.bottom = (rect.top = 25) + orect.Heigth();

    child_tab[0]->MoveWindow(rect);

3. view or hide ( using showWindow() )

    child_tab[0]->ShowWindow( TRUE or FALSE );