CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 1999
    Location
    United Kingdom
    Posts
    136

    Combining dialogs with tab controls

    What I want to do is to use a tab control instead of a property sheet. However, I still want to keep my dialogs as resources. How do I mimick a property sheet with a tab control? I would need to load the required dialog into memory and display within the tab control. Then, when the user selects a different tab, I would have to unload the dialog, load the new dialog and display it within the tab control.

    How do I go about this? How do I load a dialog from a resource template and display it within a view?

    Any ideas would be much appreciated,
    Oliver.


  2. #2
    Join Date
    Apr 1999
    Posts
    37

    Re: Combining dialogs with tab controls

    hi,
    You need a main dialog on which tab control needs to be placed.This main dialog is also going to be the parent of all the dialogs which are to be shown for each tab in the tab control.The size of the main dialog should be the size of the biggest of all your tab dialogs.When a tab button is pushed the following things need to happen.
    1.Hide the current active dialog.
    2.Check if the dialog associated with the tab button is already created.If its already created just show it else create and show it.


    There is no need to destroy dialogs when the user changes tabs.You can just hide/show.If you are using MFC ,there will be a CDialog derived class for each of the dialog.You need to create these dialogs as a child of the main dialog.All the tab dialogs can be destroyed when the user wants to close the main dialog.



  3. #3
    Join Date
    May 1999
    Location
    United Kingdom
    Posts
    136

    Re: Combining dialogs with tab controls

    Thanks for your help. That's what I'm doing now and looks good.

    I've also found some articles in CodeGuru on the subject:

    http://www.codeguru.com/dialog/Viewi...esources.shtml

    or even more useful for my problem:

    http://www.codeguru.com/dialog/Child...nADialog.shtml

    Thanks again,
    Oliver.


  4. #4
    Join Date
    Mar 1999
    Location
    St. Louis
    Posts
    45

    Re: Combining dialogs with tab controls

    The following code uses some of my external code- but it gets the point accross.
    The parent dialog resource has a tab control that I dynamically sub-class.

    Each other dialog is a CDialog- created from a resource template and inserted
    using the InsertPage method. I am not certain if VC++ supports templated methods.

    All sub-CDialogs are embedded inside the tab control. I keep an array of CWnd ptrs that I delete on destruction (MView). You could just declare all your CDialogs as members of KTabControl.

    Hope this gives you some ideas.

    class KTabControl : public CTabCtrl : public MView
    {
    DECLARE_DYNCREATE(KTabControl)
    public:
    KTabControl();
    };

    class KTabDialog : public KDialog
    {
    public:
    KTabDialog(UINT inID) : KDialog(inID) {
    mActivePage = nil;
    mTab = nil;
    }

    virtual ~KTabDialog()
    {
    mActivePage = nil;
    mTab = nil;
    }
    virtual void Setup(CDataExchange *);
    virtual void ListenToMessage( MessageT inMessage, void *ioParam);

    template <class ControlT>
    ControlT *InsertPage(UInt32 inID)
    {
    ControlT *c = new ControlT();
    c->Create(inID, mTab);
    return (ControlT *)this->InsertPage( c );
    }
    MPane *InsertPage(MPane *inWnd );


    CString GetViewTitle(CWnd * pView);

    protected:
    HWND mActivePage;
    KTabControl *mTab;
    DECLARE_MESSAGE_MAP()
    afx_msg void OnTabSelect();
    };

    #define unknown _T("Sheet")

    IMPLEMENT_DYNCREATE(KTabControl, CTabCtrl)
    KTabControl::KTabControl()
    {
    }

    BEGIN_MESSAGE_MAP(KTabDialog, KDialog)
    ON_NOTIFY(TCN_SELCHANGE, tab_Panes, OnTabSelect)
    END_MESSAGE_MAP()

    // you can iterate thru the sub dialogs and pass messages
    void KTabDialog::ListenToMessage( MessageT inMessage, void *ioParam)
    {
    KDialog *thePage = (KDialog *)mTab->GetWindow(GW_CHILD);
    while (thePage)
    {
    thePage->ListenToMessage( inMessage, ioParam );
    thePage = (KDialog *)thePage->GetWindow(GW_HWNDNEXT);
    }
    KDialog::ListenToMessage(inMessage, ioParam);
    }

    void KTabDialog::OnTabSelect()
    {
    if ( mActivePage )
    ::ShowWindow(mActivePage, false);

    TC_ITEM tabItem;
    tabItem.mask = TCIF_PARAM;
    tabItem.lParam = (long)nil;
    mTab->GetItem(mTab->GetCurSel(), &tabItem);
    mActivePage = (HWND)tabItem.lParam;

    if ( mActivePage )
    ::ShowWindow(mActivePage, true);
    }

    MPane *KTabDialog::InsertPage(MPane *inWnd )
    {
    if ( inWnd )
    {
    CWnd &wnd = *inWnd;
    wnd.ShowWindow(false);

    mTab->AdoptSubpane(inWnd);
    CString title;
    wnd.GetWindowText(title);
    TC_ITEM tabItem;
    tabItem.mask = TCIF_TEXT | TCIF_PARAM;
    tabItem.iImage = -1;
    tabItem.lParam = (long)wnd.m_hWnd;
    tabItem.pszText = title;
    mTab->InsertItem(mTab->GetItemCount(), &tabItem);

    if ( mTab->GetCurSel() == mTab->GetItemCount()-1 )
    {
    wnd.ShowWindow(true);
    mActivePage = wnd.m_hWnd;
    }
    };
    return inWnd;
    }

    void KTabDialog::Setup(CDataExchange *)
    {
    this->AttachSubpane((mTab = new KTabControl()), tab_Panes);
    }

    CString KTabDialog::GetViewTitle(CWnd * pView)
    {
    CString result;
    pView->GetWindowText(result);
    if (result.IsEmpty())
    result = unknown;
    return result;
    }






  5. #5
    Join Date
    Apr 1999
    Location
    Melbourne, VIC
    Posts
    72

    Re: Combining dialogs with tab controls

    Set the style to flat and child using modify style and then load the dlg into a CFormView.
    Henry


    \_|_|_|_/
    oOOOOOo
    (*^@ @^*)
    | O |
    \&_&/
    __-__
    /?;|;?\

    D_WZRDV_Z



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured