OnInitDialog 中调用的方法:
void ChookDlg::add_tab_items()
{
tab_item_ptrs.push_back( tab_item_ptr( new CTabSLSensor ) );
tab_item_ptrs.push_back( tab_item_ptr(new user_dlg) );
tab_item_ptrs.push_back( tab_item_ptr( new admin_dlg ) );
for ( auto tab_item_res_id = first_tab_item_res_id, idx = 0U; tab_item_res_id != last_tab_item_res_id + 1; ++tab_item_res_id, ++idx )
{
ASSERT(tab_item_ptrs.at(idx)->Create(tab_item_res_id, this)); // calls OnInitDialog
tab_item_ptrs.at(idx)->ShowWindow(SW_HIDE);
mapped_tab_items[static_cast< tab_item >(idx)] =
tab_item_image_container(
tab.InsertItem(tab.GetItemCount(), _T("SL Sensor"), tab_item_ptrs.back().get()),
tab_item_ptrs.at(idx)
);
}
}
tab 是一个继承 CTabCtrl 的 CMyTabCtrl 类型的对象。 这是插入方法:
LONG CMyTabCtrl::InsertItem(int nItem, LPCTSTR lpszItem, CMyTabCtrlTab *myTabCtrlTab)
{
UINT mask = TCIF_PARAM;
LPARAM lParam = reinterpret_cast<LPARAM>(myTabCtrlTab);
if (NULL != lpszItem) {
mask |= TCIF_TEXT;
}
ASSERT(myTabCtrlTab != NULL);
LONG retval = CTabCtrl::InsertItem(mask, nItem, lpszItem, 0, lParam);
if (retval < 0)
return retval;
CRect windowRect;
GetWindowRect(&windowRect);
AdjustRect(FALSE, &windowRect);
// The left border is 3 pixel, the bottom border 2 pixel and the right border 1 pixel
// Adjust to 1 pixel at each side.
// windowRect.left -= 2;
// windowRect.bottom += 1;
GetParent()->ScreenToClient(&windowRect);
myTabCtrlTab->SetWindowPos(&wndTop, windowRect.left, windowRect.top, windowRect.Width(), windowRect.Height(), SWP_HIDEWINDOW);
return retval;
}
调试断言失败在 winocc.cpp 中的第 318 行引发:
BOOL CWnd::SetWindowPos(const CWnd* pWndInsertAfter, int x, int y, int cx,
int cy, UINT nFlags)
{
ASSERT(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL));
模板设置正确。
这是 OnInitDialog:
BOOL ChookDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
ASSERT((IDM_RECONNECT & 0xFFF0) == IDM_RECONNECT);
ASSERT(IDM_RECONNECT < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
CString strReconnectMenu;
bNameValid = strReconnectMenu.LoadString(IDS_RECONNECT);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_RECONNECT, strReconnectMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// initialize tab item pointers container
add_tab_items();
tab.ChangeTab( static_cast< int >( tab_item::sensor ) );
return TRUE; // return TRUE unless you set the focus to a control
}
标签声明:
private:
CMyTabCtrl tab;