help with tab control on a dialog

help with tab control on a dialog

Post by Christopher Cont » Thu, 08 May 1997 04:00:00

I'm trying to use a tab control on a dialog in such a way that it looks
as though there were a property sheet embedded on the dialog (along with
other controls which is why I'm not using a property sheet directly).  I
want to use dialog templates to specify the contents of each 'page', ala
CPropertyPage.  I have the creation code working-the tabs appear and
when you select the tabs the page is shown correctly.  Unfortunately, I
can't access any of the controls on the page.  Does any  one know why? I
figure it probably has something to do with the fact that the page is
really a dialog that I'm calling Create() on instead of DoModal().

Here are some excerpts:

in my init function I call:

void CMyDlg::TabbedDialogInit()
    DWORD dwDlgBase = GetDialogBaseUnits();
    int cxMargin = 2;
    int cyMargin = 2;
    TC_ITEM tie;

    // Add a tab for each of the three child dialog boxes.
    tie.mask = TCIF_TEXT | TCIF_IMAGE;
    tie.iImage = -1;
    tie.pszText = "First";
    TabCtrl_InsertItem(m_Tab.m_hWnd, 0, &tie);

    CPageDlg* pDlg = new CPageDlg(&m_Tab);
    m_PageArray.InsertAt(0, pDlg);

    // Determine the bounding rectangle for all child dialog boxes.
    RECT rcTab;

    if (pRsc->cx > rcTab.right)
            rcTab.right = pRsc->cx;
    if (pRsc->cy > rcTab.bottom)
            rcTab.bottom = pRsc->cy;
    rcTab.right = rcTab.right * LOWORD(dwDlgBase) / 4;
    rcTab.bottom = rcTab.bottom * HIWORD(dwDlgBase) / 8;

    // Calculate how large to make the tab control, so
    // the display area can accomodate all the child dialog boxes.
    TabCtrl_AdjustRect(m_Tab.m_hWnd, TRUE, &rcTab);
    OffsetRect(&rcTab, cxMargin - rcTab.left,
            cyMargin -;

    // Calculate the display rectangle.
    CopyRect(&m_rcDisplay, &rcTab);
    TabCtrl_AdjustRect(m_Tab.m_hWnd, FALSE, &m_rcDisplay);

    // Set the size and position of the tab control
//    m_Tab.SetWindowPos(NULL, 0, 0,
//            rcTab.right - rcTab.left, rcTab.bottom -,
//            SWP_NOZORDER | SWP_NOMOVE);

    // Simulate selection of the first item.


 and OnSelChanged (which is also called for TCN_SELCHANGED):

void CMyDlg::OnSelChanged()
    int iSel = TabCtrl_GetCurSel(m_Tab.m_hWnd);

    if (m_pActivePage != NULL)
        // Destroy the current child dialog box, if any.
        if (m_pActivePage->m_hWnd != NULL)

    CPageDlg* pDlg = m_PageArray[iSel];
    if (pDlg->m_hWnd == NULL)
        //create and position the dialog
        pDlg->Create(CPageDlg::IDD, &m_Tab);
        pDlg->SetWindowPos(NULL, m_rcDisplay.left,, 0,

    m_pActivePage = pDlg;



"Programming today is a race between software engineers
striving to build bigger and better idiot-proof programs, and the
trying to produce bigger and better idiots. So far, the Universe is
winning." -Rich Cook

replace .--- with .com for e-mail


help with tab control on a dialog

Post by Anti Snoo » Thu, 08 May 1997 04:00:00

Sure, Look Here:

:I'm trying to use a tab control on a dialog in such a way that it looks
:as though there were a property sheet embedded on the dialog (along with
:other controls which is why I'm not using a property sheet directly).  I
:want to use dialog templates to specify the contents of each 'page', ala


help with tab control on a dialog

Post by Roderick A. Bal » Thu, 08 May 1997 04:00:00

You may also be able to use a property sheet. What you need to do is
create a dialog box with a group box where you wish your property sheet
to be.  Declare an instance of this property sheet within your dialog
class and then in your OnInitDialog add the following:

        WS_CHILD | WS_VISIBLE, 0);

This will create the sheet with the group box as the parent of the
sheet.  You will probably need some other stuff to resize the sheet to
the size of the group box, I use:

        CRect rectWnd;
        SetWindowPos(NULL, 0, 0,

        CTabCtrl* pTab = GetTabControl();
        pTab->SetWindowPos(NULL, 0, 0,
                rectWnd.Width() - 15,
                rectWnd.Height() - 15,


in the OnInitDialog of the Property sheet.  You will also need to resize
the pages.

There is one problem with this (I am currently working on this now --
maybe someone else can enlighten me).  I cannot create another window
from one of the pages. If I call DoModal for a dialog box within one of
my page classes, it goes into an infinite loop somewhere and I end up
having to kill the program.  Maybe some one could give me some advice on

Anyway I hope this might be of use to someone.



1. How to control the tab order in dialog with a tab control?

I have a dialog which has a tab control and several other controls -- some
buttons and edit boxes.  A couple of the edit boxes are above the tab
control and a couple are below it.  The problem I have is with the tabbing
order.  When you tab through the controls in the dialog, the focus first
goes through the other controls in the dialog (the ones above and below
the tab control) and then the controls inside the tab control -- even
though the tab control is in the proper position in the dialog template.

I think what's happening is probably because the controls inside the tab
control in a dialog which is a child of the main dialog.  (I believe
that's the recommended way of doing it).  But it's very confusing for the
user for the tab order to work this way.

Is there an easy way of fixing this problem?  I know I could subclass the
appropriate controls in the dialog and handle the tab key myself, but I'd
prefer a more global solution (I have several dialogs like this).

I suspect that using property sheets would solve my problem, but switching
to property sheets isn't really practical for me.

Thanks for any assistance.
- Eric S.


3. Ctrl-tab and tab control in a dialog


5. Tab sequence in dialogs with tab controls

6. 80*86 and IEE 754

7. How to Tab between controls (not in dialog) - HELP

8. Network problem

9. Modeless Dialog Box & Tab Control HELP!!!!

10. Help finding tab order of dialog control?

11. HELP: Tabbed Dialog Controls

12. Tab navigation between a tab control and the displayed controls

13. HELP: What parameter shows which tab selected in a tabstrip or tabbed control?