CMFCTabCtrl Tab Change Event

I want to catch the CMFCTabCtrl tab change event. Below is the code I'm trying to do. But he will 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 ); } 
+4
source share
2 answers

According to this forum topic , you need to process the AFX_WM_CHANGING_ACTIVE_TAB sent to the parent window.

This forum topic contains more code samples.

+2
source

If you want to catch a tab change, the tab that will be active needs AFX_WM_CHANGE_ACTIVE_TAB , i.e.

 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 need to manually change the tab call with;

  SendMessage(AFX_WM_CHANGE_ACTIVE_TAB, iTabNum2ChangeTo, 0); 

Sent above trying to find a solution to my problem when using

 CMFCTabCtrl::SetActiveTab() 

will fail, but only in debug mode. And this OP was googles best answer.

AFX_WM_CHANGING_ACTIVE_TAB appears to catch the event before the actual tab change, so why it did not work for the OP and can be checked:

 int iCheckActiveTab = m_wndTabs.GetActiveTab(); 
0
source

Source: https://habr.com/ru/post/1492230/


All Articles