Aruna Karunarathna
Aruna Karunarathna

Reputation: 1021

How to close tab in CMFCTabCtrl

I have used CMFCTabCtrl in my MFC application and I have enabled the active tab close button.

m_TabControl.EnableActiveTabCloseButton();

But when I click close button, the tab is not closed. How to close the tab properly??..

Thanks.

Upvotes: 0

Views: 1910

Answers (2)

Roger Rowland
Roger Rowland

Reputation: 26279

When you click the close button, a WM_CLOSE message is sent to the window that was used in the AddTab during initialisation.

So, in that child window, add a WM_CLOSE message handler and do something like this:

void CMyTabWindow::OnClose()
{
    // nb - must be created with the tab ctrl as parent
    CMFCTabCtrl *pTab = static_cast<CMFCTabCtrl*>(GetParent());
    pTab->RemoveTab(pTab->GetActiveTab());
}

Upvotes: 1

Sivaraman
Sivaraman

Reputation: 458

Try with DeleteItem(index) on your CTabCtrl. This will remove the tab from your tab control.

Upvotes: 0

Related Questions