Reputation: 1021
I want to catch the tab change event of a CMFCTabCtrl. Below is the code I'm trying to do that. But it does not catch the change event.
BOOL SurvChatDlg::OnNotify( WPARAM wParam, LPARAM lParam, LRESULT*
pResult )
{
if(((LPNMHDR)lParam)->code==TCN_SELCHANGE)
{
int i = m_TabControl.GetActiveTab();
AfxMessageBox("Changed");
}
return CDialog::OnNotify( wParam, lParam, pResult );
}
Upvotes: 4
Views: 5900
Reputation: 1126
If you want to catch the post tab change, the tab that will be active, need AFX_WM_CHANGE_ACTIVE_TAB ie;
ON_REGISTERED_MESSAGE(AFX_WM_CHANGE_ACTIVE_TAB,OnTabSetActive)
LRESULT CYourClass::OnTabSetActive(WPARAM wParam, LPARAM lParam)
{
const int iActiveTab = (int)wParam;
int iCheckActiveTab = m_wndTabs.GetActiveTab(); //CMFCTabCtrl m_wndTabs;
m_wndTabs.SetActiveTab(iActiveTab); //good idea to also add this depending on usage.
return 0;
}
And if you require manually changing the tab call using;
SendMessage(AFX_WM_CHANGE_ACTIVE_TAB, iTabNum2ChangeTo, 0);
Posted the above after trying to find a solution to my problem where using
CMFCTabCtrl::SetActiveTab()
would crash but in debug mode only. And this OP was googles top answer.
AFX_WM_CHANGING_ACTIVE_TAB appears to catch the event prior to the actual tab change, hence why hasn't worked for the OP, and can be checked by;
int iCheckActiveTab = m_wndTabs.GetActiveTab();
Upvotes: 1
Reputation: 5132
According to this forum thread, you need to handle the AFX_WM_CHANGING_ACTIVE_TAB message sent to the parent window.
This forum thread has more code samples.
Upvotes: 1