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. [SOLVED] How to set cursor IDC_HAND when hover in CMyButton? [SOLVED] [modified]

[SOLVED] How to set cursor IDC_HAND when hover in CMyButton? [SOLVED] [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
4 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.
  • F Offline
    F Offline
    fantasy1215
    wrote on last edited by
    #1

    I wanna make cursor IDC_HAND when mouse hover in my CMyButton(derived from CButton). In CMyButton I deal with ON_WM_MOUSEMOVE message, see code below:

    void CMyButton::OnMouseMove(UINT nFlags, CPoint point)
    {
    // TODO: Add your message handler code here and/or call default

    ASSERT(m\_hWnd);
    TRACKMOUSEEVENT tevent;
    tevent.cbSize = sizeof(tevent);
    tevent.dwHoverTime = 0;
    tevent.hwndTrack = m\_hWnd;
    tevent.dwFlags = TME\_LEAVE;
    \_TrackMouseEvent(&tevent);
    
    SetCursor(LoadCursor(NULL, IDC\_HAND));//I set cursor to IDC\_HAND here, but not work.
    CButton::OnMouseMove(nFlags, point);
    if (FALSE == m\_bHovered)
    {
    	m\_bHovered = TRUE;
    	this->Invalidate(TRUE);
    }
    

    }

    Hope I state my problem clearly!

    modified on Tuesday, December 2, 2008 1:43 AM

    B 2 Replies Last reply
    0
    • F fantasy1215

      I wanna make cursor IDC_HAND when mouse hover in my CMyButton(derived from CButton). In CMyButton I deal with ON_WM_MOUSEMOVE message, see code below:

      void CMyButton::OnMouseMove(UINT nFlags, CPoint point)
      {
      // TODO: Add your message handler code here and/or call default

      ASSERT(m\_hWnd);
      TRACKMOUSEEVENT tevent;
      tevent.cbSize = sizeof(tevent);
      tevent.dwHoverTime = 0;
      tevent.hwndTrack = m\_hWnd;
      tevent.dwFlags = TME\_LEAVE;
      \_TrackMouseEvent(&tevent);
      
      SetCursor(LoadCursor(NULL, IDC\_HAND));//I set cursor to IDC\_HAND here, but not work.
      CButton::OnMouseMove(nFlags, point);
      if (FALSE == m\_bHovered)
      {
      	m\_bHovered = TRUE;
      	this->Invalidate(TRUE);
      }
      

      }

      Hope I state my problem clearly!

      modified on Tuesday, December 2, 2008 1:43 AM

      B Offline
      B Offline
      bob16972
      wrote on last edited by
      #2

      Did you try handling WM_SETCURSOR? This is much easier than trying to deal with mouse messages.

      F 1 Reply Last reply
      0
      • F fantasy1215

        I wanna make cursor IDC_HAND when mouse hover in my CMyButton(derived from CButton). In CMyButton I deal with ON_WM_MOUSEMOVE message, see code below:

        void CMyButton::OnMouseMove(UINT nFlags, CPoint point)
        {
        // TODO: Add your message handler code here and/or call default

        ASSERT(m\_hWnd);
        TRACKMOUSEEVENT tevent;
        tevent.cbSize = sizeof(tevent);
        tevent.dwHoverTime = 0;
        tevent.hwndTrack = m\_hWnd;
        tevent.dwFlags = TME\_LEAVE;
        \_TrackMouseEvent(&tevent);
        
        SetCursor(LoadCursor(NULL, IDC\_HAND));//I set cursor to IDC\_HAND here, but not work.
        CButton::OnMouseMove(nFlags, point);
        if (FALSE == m\_bHovered)
        {
        	m\_bHovered = TRUE;
        	this->Invalidate(TRUE);
        }
        

        }

        Hope I state my problem clearly!

        modified on Tuesday, December 2, 2008 1:43 AM

        B Offline
        B Offline
        bob16972
        wrote on last edited by
        #3

        Also, I think you need WINVER to be greater than or equal to 0x0500 to use IDC_HAND

        1 Reply Last reply
        0
        • B bob16972

          Did you try handling WM_SETCURSOR? This is much easier than trying to deal with mouse messages.

          F Offline
          F Offline
          fantasy1215
          wrote on last edited by
          #4

          Thanks. It worked! I vote you 5!^_^

          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