tags:

views:

167

answers:

3

MFC Library Reference
CWnd::OnLButtonDown

void CMyCla::OnLButtonDown(UINT nFlags, CPoint point)
{
    CWnd::OnLButtonDown(nFlags, point);
}


void CMyTreeCla::OnLButtonDown(UINT nFlags, CPoint point)
{
    CTreeCtrl::OnLButtonDown(nFlags, point);
}

I know the inheritance.

class CTreeCtrl : public CWnd
{
......
}

Is there any clear rule to follow when i want to call OnLButtonDown()?

Thank you.

+1  A: 

If you want the parent class implementation to be called first then you call the parent class's OnLButtonDown() and then add your implementation.

Ramakrishna
hello Ramakrishna. thank you too.
Nano HE
+1  A: 

I think this is what you want.

In your class header, you will need to declare the message map, and also write the function header.

Class myCWnd : public CWnd
{
    DECLARE_MESSAGE_MAP() //note, no semi colon

    afx_msg void OnLButtonDown( UINT nFlags, CPoint pt );
};

in the cpp file:

BEGIN_MESSAGE_MAP(myCWnd, CWnd)
    ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()

void myCWnd::OnLButtonDown( UINT nFlags, CPoint pt )
{
    //do what you want here

    CWnd::OnLButtonDown(nFlags, pt); //call base class method
}
YoungPony
hello neeul. thank you.
Nano HE
+1  A: 

Usually, you do what you want to do with the event in your implementation and then you call the implementation of the parent class. This codeguru post shows a nice example in step 2 of the tutorial. But this depends on what exactly you want to do with the OnLButtonDown event, so it might be the other way around in your case.

I assume the inheritance in your example is as follows:

class CMyCla : public CWnd
{
}

class CMyTreeCla : public CTreeCtrl
{
......
}

So indeed, as you do, you do your thing in either OnLButtonDown and then call the parent implementation:

void CMyCla::OnLButtonDown(UINT nFlags, CPoint point)
{
    // Your stuff here
    // blah
    // end your stuff
    CWnd::OnLButtonDown(nFlags, point);
}


void CMyTreeCla::OnLButtonDown(UINT nFlags, CPoint point)
{
    // Your stuff here
    // blah
    // end your stuff
    CTreeCtrl::OnLButtonDown(nFlags, point);
}
jilles de wit