I have captured the OnMouseMove and OnMouseLeave events and can successfully
make the text bold when the mouse hovers over my object, (using
_TrackMouseEvent), but I can't get the mouse cursor to change. I have tried
doing a SetCursor at the same time as changing the Font, but it doesn't do
anything. I have trapped the WM_SETCURSOR event and tried to SetCursor in
there, but it doesn't do anything either. How can I make the mouse cursor
into a hand when the mouse hovers over my object?
If you debug your application, are you getting WM_SETCURSOR messages?
If you are, that should be the right place to change the cursor - so
is your code correct?
Dave
This is my OnSetCursor method. It gets hit as soon as the mouse land over
one of my objects:
BOOL CStaticHover::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
bool returnVal = CStatic::OnSetCursor(pWnd, nHitTest, message);
SetCursor(AfxGetApp()->LoadCursor(IDC_HANDCUR));
return returnVal;
}
I have tried calling the CStatic::OnSetCursor method before my call and
after my call, but no change - I don't understand, but the SetCursor doesn't
seem to work, perhaps it is being overwritten later by some other event:
The only other 2 methods in my class are OnMouseMove and OnMouseLeave, as
follows:
BEGIN_MESSAGE_MAP(CStaticHover, CStatic)
ON_WM_MOUSEMOVE()
ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)
ON_WM_SETCURSOR()
END_MESSAGE_MAP()
void CStaticHover::OnMouseMove(UINT nFlags, CPoint point)
{
if (!m_bHovering)
{
SetFont(&m_fHighLightFont, TRUE);
TRACKMOUSEEVENT thing;
thing.cbSize = sizeof(thing);
thing.dwFlags = TME_LEAVE | TME_HOVER;
thing.dwHoverTime = 0;
thing.hwndTrack = GetSafeHwnd();
m_bHovering = (_TrackMouseEvent(&thing) == TRUE);
}
CStatic::OnMouseMove(nFlags, point);
}
LRESULT CStaticHover::OnMouseLeave(WPARAM, LPARAM)
{
if (m_bHovering)
{
m_bHovering = false;
SetFont(&m_fNormalFont, TRUE);
}
return 0;
}
> BOOL CStaticHover::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
> {
> SetCursor(AfxGetApp()->LoadCursor(IDC_HANDCUR));
> return TRUE;
> }
AliR.
"GT" <ContactG...@hotmail.com> wrote in message
news:45be1d83$0$8217$c3e...@news.astraweb.com...
BOOL CStaticHover::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
::SetCursor(AfxGetApp()->LoadCursor(IDC_HANDCUR));
return TRUE;
}
One more thing while I'm at it, I would call LoadCursor once, hang on to the
cursor handle then simply set it in the OnSetCursor method.
BOOL CStaticHover::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if (m_hCursor)
{
::SetCursor(m_hCursor);
return TRUE;
}
return CStatic::OnSetCursor(pWnd,nHitTest,message);
}
AliR.
"AliR (VC++ MVP)" <Al...@online.nospam> wrote in message
news:Jzqvh.1871$4H1...@newssvr17.news.prodigy.net...
Ahhh - that's got it. Thanks