Link to home
Start Free TrialLog in
Avatar of dcoggin1
dcoggin1Flag for United States of America

asked on

Unable to load cursor in MFC CView class

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
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dcoggin1

ASKER

Thanks, that's what I needed.