开发者

getting 'undeclared identifier' error

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.


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).


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) 


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜