views:

53

answers:

3

Following the tutorial at http://www.codersource.net/mfc/mfc-tutorials/ctabctrl.aspx , I have declared the function ActivateTabDialogs() in my header file and called it inside another function in my class. The compiler gives error C2065: 'ActivateTabDialogs' : undeclared identifier, at the line ActivateTabDialogs(); inside the definition of the function OnSelChange(). What am I violating here?

Here's my declaration part in the header file TCGeriArama_TabCtrl.h

class CTCGeriArama_TabCtrl : public CTabCtrl
{
// Construction
public:
    CTCGeriArama_TabCtrl();

// Attributes

    //Array to hold the list of dialog boxes/tab pages for CTabCtrl
    int m_DialogID[2];

    int m_nPageCount;

    //CDialog Array Variable to hold the dialogs 
    CDialog *m_Dialog[2];

public:
// Operations
    //Function to Create the dialog boxes during startup
    void InitDialogs();

    //Function to activate the tab dialog boxes
    void ActivateTabDialogs();

Here's the definition of ActivateTabDialogs() and the part I'm calling it inside TCGeriArama_TabCtrl.cpp

void CTCGeriArama_TabCtrl::ActivateTabDialogs()
{
    int nSel = GetCurSel();
    if(m_Dialog[nSel]->m_hWnd)
        m_Dialog[nSel]->ShowWindow(SW_HIDE);

    CRect l_rectClient;
    CRect l_rectWnd;

    GetClientRect(l_rectClient);
    AdjustRect(FALSE,l_rectClient);
    GetWindowRect(l_rectWnd);
    GetParent()->ScreenToClient(l_rectWnd);
    l_rectClient.OffsetRect(l_rectWnd.left,l_rectWnd.top);
    for(int nCount=0; nCount < m_nPageCount; nCount++){
        m_Dialog[nCount]->SetWindowPos(&wndTop, l_rectClient.left, l_rectClient.top, l_rectClient.Width(), l_rectClient.Height(), SWP_HIDEWINDOW);
    }
    m_Dialog[nSel]->SetWindowPos(&wndTop, l_rectClient.left, l_rectClient.top, l_rectClient.Width(), l_rectClient.Height(), SWP_SHOWWINDOW);

    m_Dialog[nSel]->ShowWindow(SW_SHOW);

}

//Selection change event for the class derived from CTabCtrl
void OnSelchange(NMHDR* pNMHDR, LRESULT* pResult)
{
    // TODO: Add your control notification handler code here
    ActivateTabDialogs(); // HERE'S WHERE THE COMPILER GIVES THE ERROR
    *pResult = 0;
}

Thanks.

+1  A: 

In the link given by you the function OnSelchange is a member function.

So try changing

void OnSelchange(NMHDR* pNMHDR, LRESULT* pResult)

to:

void CTCGeriArama_TabCtrl::OnSelchange(NMHDR* pNMHDR, LRESULT* pResult) 
codaddict
well I was getting two errors actually, the only way I could get rid of one was to remove that MyTabCtrl part, this 'undeclared' error was unaffected
Halo
@Halo: Show us both the errors, you should not be dropping the class name.
codaddict
Ok I'm putting it back as a member function and now getting "error C2039: 'OnSelchange' : is not a member of 'CTCGeriArama_TabCtrl'". Should I post a new topic for that or go on from here?
Halo
+2  A: 

Well apparently OnSelChange is a free function. ActiveTabDialogs is a member-function of the class CTCGeriArama_TabCtrl. Member functions have to be called on an instance of the class they are a member of. There are two options:

  1. Make OnSelChange a member function of CTCGeriArama_TabCtrl too.
  2. Change the call to someObj.ActiveTabDialogs() and provide OnSelChange with a reference to a CTCGeriArama_TabCtrl-instance.

From the looks of it OnSelChange is a callback-function. It would probably be difficult to make it a member-function as that would change it's pointer-type. If this is a callback for some framework you are using, you should check if that framework provides some mechanism to pass context-information to the callback-handler (probably what the NMHDR* pNMHDR-parameter is for).

Space_C0wb0y
Thanks, I make OnSelChange a member function, and now the compiler gives "error C2039: 'OnSelchange' : is not a member of 'CTCGeriArama_TabCtrl'". I guess this was the main problem and not ActivateTabDialogs()?
Halo
@Halo: It really depends on what you want to achieve. Maybe you should open a different question stating the design-problem you are truing to solve, and think of a way to implement a solution after that.
Space_C0wb0y
A: 

Turns out that I didn't add the handler using the class wizard, and put the function OnSelChange() manually, and that was causing the problem. Thanks a lot for your attention

Halo
@Halo: You can accept your own answer. This may help others who have to same problem to find it.
Space_C0wb0y
will do, the site allows it after two days
Halo