tags:

views:

54

answers:

1

Hi all,

I have a control derived from a CWnd object that has its custom implemented tooltip system . The tooltip is implemented using a CDialog and works fine but I have a problem to know when I have to hide it.

The tooltip shows up when the mouse hover over the control (WM_MOUSEHOVER) and it's hidden when the mouse leaves the control (WM_MOUSELEAVE). So far so good. The problem is that the dialog where the control is set can be hidden from the menu (not destroyed it can be displayed again from the menu). When this happens the WM_MOUSELEAVE event is not sent to the control and the tooltip is not removed...it appears over the new dialog.

My question is: is there a way to know that the control is being hidden? I know I can capture the WM_SHOWWINDOW message for the dialog where the control is set but I want to do it from the control itself so I can use the control elsewhere without having to add extra code.

Thanks in advance!

Javier

+2  A: 

Generally, if you have a custom control that needs to have dialog messages forwarded on to it you use sub-classing. Something like the following

BOOL CMyDialog::OnInitDialog() 
{
    m_MyCtrl.SubclassDlgItem(IDC_MY_CTRL_ID,this);
    CMyDialog::OnInitDialog();
    return TRUE;
}

then you can process dialog messages from your control, e.g.

BEGIN_MESSAGE_MAP(CMyCtrl, CWnd)
    //{{AFX_MSG_MAP(CMyCtrl)
    ON_WM_SHOWWINDOW()
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CMyCtrl::OnShowWindow(BOOL bShow,UINT nStatus ) 
{
.
.
}

You still have to modify host dialog code to a small extent to utilise the control, but your control is re-usable.

Shane MacLaughlin