E
Egbert Nierop \(MVP for IIS\)
Hi,
I have a class, see below, that needs to be subclassed in a dialog.
Inside the dialog (OnInitDialog), I need something like this.
m_MyControl.SubclassWindow(GetDlgItem(IDC_MyControl).m_hWnd);
m_MyControl.SetMouseHover(reinterpret_cast
<CMouseHover::ONMOUSEHOVER>(&mainWin::OnMouseHover)); //
Line above, will produce a casting error. I've seen some articles on this
theme http://www.progdoc.de/papers/chameleon/value/value.html but I simply
don't get it.
What can I do to fix this?
Thanks!
// for Subclassing controls so we have support for OnMouseHover and
OnMouseLeave
class CMouseHover: public CWindowImpl<CMouseHover>
{
public:
CMouseHover(): m_bIsMouseOver(false) , OnMouseHover(NULL),
OnMouseLeave(NULL)
{
}
//declare event signature
typedef void (CALLBACK* ONMOUSEHOVER)(int nFlags, int ID, POINT pt);
typedef void (CALLBACK* ONMOUSELEAVE)(int ID);
void SetMouseHover(ONMOUSEHOVER ptr) throw()
{
OnMouseHover = ptr;
}
ONMOUSEHOVER OnMouseHover;
ONMOUSELEAVE OnMouseLeave;
private:
bool m_bIsMouseOver;
BEGIN_MSG_MAP(CMouseHover)
MESSAGE_HANDLER(WM_MOUSEHOVER, OnMouseHover_System)
MESSAGE_HANDLER(WM_MOUSELEAVE, OnMouseLeave_System)
MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove_System)
END_MSG_MAP()
LRESULT OnMouseHover_System(UINT, WPARAM wParam, LPARAM lParam, BOOL&)
throw()
{
if (OnMouseHover != NULL)
{
POINT pt ={GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
UINT nFlags = (UINT)wParam;
OnMouseHover(nFlags, GetDlgCtrlID(), pt);
}
return FALSE;
}
LRESULT OnMouseLeave_System(UINT, WPARAM, LPARAM, BOOL&) throw()
{
if (OnMouseLeave != NULL)
{
TRACKMOUSEEVENT evntTrack;
evntTrack.cbSize = sizeof(TRACKMOUSEEVENT);
evntTrack.hwndTrack = m_hWnd;
evntTrack.dwHoverTime = HOVER_DEFAULT;
evntTrack.dwFlags = TME_CANCEL | TME_LEAVE | TME_HOVER;
TrackMouseEvent(&evntTrack);
m_bIsMouseOver = false;
OnMouseLeave(GetDlgCtrlID());
}
return 0;
}
LRESULT OnMouseMove_System(UINT, WPARAM, LPARAM, BOOL&) throw()
{
ATLASSERT:IsWindow(m_hWnd));
if (!m_bIsMouseOver)
{
TRACKMOUSEEVENT evntTrack;
evntTrack.cbSize = sizeof(TRACKMOUSEEVENT);
evntTrack.hwndTrack = m_hWnd;
evntTrack.dwHoverTime = HOVER_DEFAULT;
evntTrack.dwFlags = TME_LEAVE | TME_HOVER;
if (TrackMouseEvent(&evntTrack) == TRUE)
m_bIsMouseOver = true;
}
//must return zero
return FALSE;
}
};
I have a class, see below, that needs to be subclassed in a dialog.
Inside the dialog (OnInitDialog), I need something like this.
m_MyControl.SubclassWindow(GetDlgItem(IDC_MyControl).m_hWnd);
m_MyControl.SetMouseHover(reinterpret_cast
<CMouseHover::ONMOUSEHOVER>(&mainWin::OnMouseHover)); //
Line above, will produce a casting error. I've seen some articles on this
theme http://www.progdoc.de/papers/chameleon/value/value.html but I simply
don't get it.
What can I do to fix this?
Thanks!
// for Subclassing controls so we have support for OnMouseHover and
OnMouseLeave
class CMouseHover: public CWindowImpl<CMouseHover>
{
public:
CMouseHover(): m_bIsMouseOver(false) , OnMouseHover(NULL),
OnMouseLeave(NULL)
{
}
//declare event signature
typedef void (CALLBACK* ONMOUSEHOVER)(int nFlags, int ID, POINT pt);
typedef void (CALLBACK* ONMOUSELEAVE)(int ID);
void SetMouseHover(ONMOUSEHOVER ptr) throw()
{
OnMouseHover = ptr;
}
ONMOUSEHOVER OnMouseHover;
ONMOUSELEAVE OnMouseLeave;
private:
bool m_bIsMouseOver;
BEGIN_MSG_MAP(CMouseHover)
MESSAGE_HANDLER(WM_MOUSEHOVER, OnMouseHover_System)
MESSAGE_HANDLER(WM_MOUSELEAVE, OnMouseLeave_System)
MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove_System)
END_MSG_MAP()
LRESULT OnMouseHover_System(UINT, WPARAM wParam, LPARAM lParam, BOOL&)
throw()
{
if (OnMouseHover != NULL)
{
POINT pt ={GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
UINT nFlags = (UINT)wParam;
OnMouseHover(nFlags, GetDlgCtrlID(), pt);
}
return FALSE;
}
LRESULT OnMouseLeave_System(UINT, WPARAM, LPARAM, BOOL&) throw()
{
if (OnMouseLeave != NULL)
{
TRACKMOUSEEVENT evntTrack;
evntTrack.cbSize = sizeof(TRACKMOUSEEVENT);
evntTrack.hwndTrack = m_hWnd;
evntTrack.dwHoverTime = HOVER_DEFAULT;
evntTrack.dwFlags = TME_CANCEL | TME_LEAVE | TME_HOVER;
TrackMouseEvent(&evntTrack);
m_bIsMouseOver = false;
OnMouseLeave(GetDlgCtrlID());
}
return 0;
}
LRESULT OnMouseMove_System(UINT, WPARAM, LPARAM, BOOL&) throw()
{
ATLASSERT:IsWindow(m_hWnd));
if (!m_bIsMouseOver)
{
TRACKMOUSEEVENT evntTrack;
evntTrack.cbSize = sizeof(TRACKMOUSEEVENT);
evntTrack.hwndTrack = m_hWnd;
evntTrack.dwHoverTime = HOVER_DEFAULT;
evntTrack.dwFlags = TME_LEAVE | TME_HOVER;
if (TrackMouseEvent(&evntTrack) == TRUE)
m_bIsMouseOver = true;
}
//must return zero
return FALSE;
}
};