Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

setting the cursor as a hand

160 views
Skip to first unread message

GT

unread,
Jan 29, 2007, 10:46:55 AM1/29/07
to
I have overridden the CStatic class and created my own CStaticHover class. I
want to make the mouse cursor to change to a hand and I would like the text
to turn bold when the mouse hovers over any instance of my CStaticHover
class. I can get the text to go bold when the mouse hovers, but can't get
the cursor to change...

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?


David Lowndes

unread,
Jan 29, 2007, 11:03:53 AM1/29/07
to
>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.

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

GT

unread,
Jan 29, 2007, 11:15:25 AM1/29/07
to
"David Lowndes" <Dav...@example.invalid> wrote in message
news:mk6sr2p9cc3ue23n6...@4ax.com...

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;
}


AliR (VC++ MVP)

unread,
Jan 29, 2007, 12:54:13 PM1/29/07
to
Try this

> 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...

AliR (VC++ MVP)

unread,
Jan 29, 2007, 1:02:32 PM1/29/07
to
Forgot to mention this, if you are deriving from a CStatic then you need to
call ::SetCursor

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...

GT

unread,
Jan 30, 2007, 5:10:42 AM1/30/07
to
"AliR (VC++ MVP)" <Al...@online.nospam> wrote in message
news:vHqvh.1872$4H1...@newssvr17.news.prodigy.net...

> Forgot to mention this, if you are deriving from a CStatic then you need
> to call ::SetCursor

Ahhh - that's got it. Thanks


0 new messages