We help IT Professionals succeed at work.
Get Started

Unable to load cursor in MFC CView class

dcoggin1
dcoggin1 asked
on
947 Views
Last Modified: 2013-11-20
I am trying to change the cursor when panning.  I have created member variables for the cursors:

                     HCURSOR                  m_hArrowCursor;
                     HCURSOR                  m_hPanCursor;

I initialize the variables in PreCreateWindow:

      m_hArrowCursor = AfxGetApp()->LoadCursor(IDC_ARROW);
      m_hPanCursor = AfxGetApp()->LoadCursor(IDC_SIZEALL);

When I need to change the cursor I set a bit in a unsigned int variable m_iCursorState
I have overridden the OnSetCursor function:

BOOL CMyView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
      if (m_iCursorState & PAN_CURSOR)
      {
            ::SetCursor(m_hPanCursor);
            return true;
      }
      else if (m_iCursorState & ARROW_CURSOR)
      {
            ::SetCursor(m_hArrowCursor);
            return true;
      }

      return CView::OnSetCursor(pWnd, nHitTest, message);
}

The code compiles fine but I get no cursor when the mouse is in the client area.  If I check the value of the cursor handle variables, they are all zeros.  Is there something special required to get access to the standard cursors?

Thanks for your help,
David
Comment
Watch Question
Freelance programmer / Consultant
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE