E
Egbert Nierop \(MVP for IIS\)
Hi,
I have a CWindowImpl derived class , see below at ***, that needs to
subclass simple controls like textboxes.
like this...: m_MyControl.SubclassWindow(GetDlgItem(IDC_MyControl).m_hWnd);
==> problem here
m_MyControl.SetMouseHover(
reinterpret_cast<CMouseHover::ONMOUSEHOVER>(&this->myMemberFunction)
);
The VC 8 Compiler will return a casting error.
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;
//signal our delegate
OnMouseHover(nFlags, GetDlgCtrlID(), pt);
}
return FALSE;
}
LRESULT OnMouseLeave_System(UINT, WPARAM, LPARAM, BOOL&)
{
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;
//signal delegate
OnMouseLeave(GetDlgCtrlID());
}
return 0;
}
LRESULT OnMouseMove_System(UINT, WPARAM, LPARAM, BOOL&)
{
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;
}
return FALSE;
}
};
I have a CWindowImpl derived class , see below at ***, that needs to
subclass simple controls like textboxes.
like this...: m_MyControl.SubclassWindow(GetDlgItem(IDC_MyControl).m_hWnd);
==> problem here
m_MyControl.SetMouseHover(
reinterpret_cast<CMouseHover::ONMOUSEHOVER>(&this->myMemberFunction)
);
The VC 8 Compiler will return a casting error.
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;
//signal our delegate
OnMouseHover(nFlags, GetDlgCtrlID(), pt);
}
return FALSE;
}
LRESULT OnMouseLeave_System(UINT, WPARAM, LPARAM, BOOL&)
{
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;
//signal delegate
OnMouseLeave(GetDlgCtrlID());
}
return 0;
}
LRESULT OnMouseMove_System(UINT, WPARAM, LPARAM, BOOL&)
{
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;
}
return FALSE;
}
};