Showing custom cursor when mouse is over a Win32 static control
-
I have a static text label in a straight-Win32 app I'm working on, and I'm wanting the cursor to change to a hand icon when the mouse moves over it (and back to normal when the mouse moves away). What's the best way to do that? It appears that it's possible using RegisterWndEx, but then I have to code a text control myself; there has to be a simpler way.
-
I have a static text label in a straight-Win32 app I'm working on, and I'm wanting the cursor to change to a hand icon when the mouse moves over it (and back to normal when the mouse moves away). What's the best way to do that? It appears that it's possible using RegisterWndEx, but then I have to code a text control myself; there has to be a simpler way.
I don't know if this would be simple enough for you, but the standard way of creating 'hyperlinking' controls is : define your own
CMyStatic : public CStatic
. Now overrideOnNcHitTest
and returnHTCLIENT
, this will cause windows to ask you for a cursor, otherwise it won't, e.g.:UINT CMyStatic::OnNcHitTest(CPoint point) { // otherwise return HTCLIENT; }
Now overrideOnSetCursor
and set your hand icon within it, e.g.:BOOL CMyStatic::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) { ::SetCursor(LoadCursor(NULL, IDC_HAND)); return TRUE; }
That's it. -
I don't know if this would be simple enough for you, but the standard way of creating 'hyperlinking' controls is : define your own
CMyStatic : public CStatic
. Now overrideOnNcHitTest
and returnHTCLIENT
, this will cause windows to ask you for a cursor, otherwise it won't, e.g.:UINT CMyStatic::OnNcHitTest(CPoint point) { // otherwise return HTCLIENT; }
Now overrideOnSetCursor
and set your hand icon within it, e.g.:BOOL CMyStatic::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) { ::SetCursor(LoadCursor(NULL, IDC_HAND)); return TRUE; }
That's it.