简体   繁体   中英

Adding tabs to CTabCtrl in MFC

I am trying to add a CTabCtrl into my MFC application. I am trying to follow the MSDN directly.

MSDN添加标签

* MSDN: Adding Tabs to Tab Control

Here is what I have tried:

DDX_Control(pDX, TAB1, m_TabCtrl);

TC_ITEM ti;
ti.mask = TCIF_TEXT;
ti.pszText = _T("First Tab");

m_TabCtrl.InsertItem(0,&ti);

I am receiving the following error message: 断言失败

If I hit ignore, my CTabCtrl is shown, but without any tabs (just a gray square). If I hit retry, I get the breakpoint at:

_AFXCMN_INLINE BOOL CTabCtrl::SetItem(int nItem, TCITEM* pTabCtrlItem)
{ ASSERT(::IsWindow(m_hWnd)); return (BOOL)::SendMessage(m_hWnd, TCM_SETITEM, nItem, (LPARAM)pTabCtrlItem); }

I have tried adding the header #include "afxcmn.h" but it does not change anything.

I am simply trying to get named tabs to show on my application as a first step. Eventually I wish for the tabs to show modeless dialogs. Can someone tell me what I am doing wrong? Is there a better way to use tabs in MFC?

From your information provided, it's clear that it is ASSERTing on IsWindow(m_hWnd). So that means the window for your tab control has not been created yet when you call InsertItem().

Are you putting the CTabCtrl in a CDialog derived class or in some other CWnd derived class? Have you set a breakpoint on your DDX_Control() line of code to be sure 1) it is actually being called, and 2) that it is successful? I have a feeling that it is not even being called, because if it was, then you would have a valid m_hWnd, or you would get an ASSERT() at the point of your DDX_Control() call to say that it failed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM