Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Showing custom cursor when mouse is over a Win32 static control

Showing custom cursor when mouse is over a Win32 static control

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    IGx89
    wrote on last edited by
    #1

    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.

    O 1 Reply Last reply
    0
    • I IGx89

      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.

      O Offline
      O Offline
      ohadp
      wrote on last edited by
      #2

      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 override OnNcHitTest and return HTCLIENT, 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 override OnSetCursor 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 1 Reply Last reply
      0
      • O ohadp

        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 override OnNcHitTest and return HTCLIENT, 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 override OnSetCursor 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 Offline
        I Offline
        IGx89
        wrote on last edited by
        #3

        Thanks, that worked; I didn't even need to implement the NCHITTEST message in my WndMainProc :).

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups