CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Changing cursor

  1. #1
    Join Date
    Jun 2002
    Posts
    58

    Changing cursor

    Hi,

    I am interested in changing the cursor from the standard arrow pointer to something else (like the rotation symbol used in word). Any ideas on how to do this would be appreciated.

    P.S. I tried LoadCursor(...) but can not get it to change for some reason.

    Thanks

  2. #2
    Join Date
    Mar 2004
    Posts
    382
    This is from Jeff Prosise "Programming Windows with MFC".

    In one of his sample codes, he loads a cross-hair cursor using the following code:
    Code:
    CSketchView::CSketchView()
    {
    	m_hCursor = AfxGetApp ()->LoadStandardCursor (IDC_CROSS);
    }
    where m_hCursor is a member of CSketchView of type HCURSOR. CSketchView is the view object. Hope this helps.

  3. #3
    Join Date
    Jan 2004
    Location
    Earth
    Posts
    567

    RE: Cursoresis

    Originally Quoted by StuckHere80
    I am interested in changing the cursor from the standard arrow pointer to something else (like the rotation symbol used in word). Any ideas on how to do this would be appreciated.
    One method might be to process the WM_SETCURSOR message (OnSetCursor )if you want to change the cursor according to events in the program:

    Code:
    BOOL CGraphWnd::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
    {  
       //When the context menu is called keep the arrow cursor on the context menu.
       if(message !=0)
       {
          if(m_CursorOn)
          {
                SetCursor(AfxGetApp()->LoadCursor(CUR_CURSOR));
                return TRUE;
          }
        }	
       return CWnd::OnSetCursor(pWnd, nHitTest, message);
    }
    Or, an additional method would be to Override the PreCreateWindow function if you want the cursor to always have the same cursor for the window(or View)(except when it is changed by OnSetCursor) :

    Code:
    BOOL CGraphWnd::PreCreateWindow(CREATESTRUCT& cs) 
    {
          if (!CWnd::PreCreateWindow(cs))
               return FALSE;
    
          cs.dwExStyle |=WS_EX_ACCEPTFILES | WS_EX_CLIENTEDGE;
          cs.style &= ~WS_BORDER;
         cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, 
    		AfxGetApp()->LoadCursor(CUR_CURSOR), HBRUSH(COLOR_WINDOW+1), NULL);
          return TRUE;
    }
    The LoadCursor function is for cursors from the resource file. To load a standard system cursor use LoadStandardCursor instead.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured