|
|||||||
|
|
|
|||||
|
|
|||||||
VC++ (MFC) Tips : Mouse and Cursor
1. Add a member variable m_hCursor into the constructor of CMyDrawView object (CMyDraw.h):
protected;
HCURSOR m_hCursor;
2. Add below codes to load a cursor
CMyDrawView::CMyDrawView()
{
// TODO: add construction code here
m_hCursor=AfxGetApp()->LoadStandardCursor(IDC_CROSS);
}
3. Reregister the window class to reset the cursor:
BOOL CMyDrawView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.lpszClass=AfxRegisterWndClass
(CS_HREDRAW|CS_VREDRAW,
m_hCursor,
(HBRUSH)::GetStockObject(WHITE_BRUSH),
0);
return CView::PreCreateWindow(cs);
}
NOTE: In other way, you can use SetCursor() in OnMouseMove() function, instead of using AfxRegisterWndClass() in PreCreateWindow():
void CMyDrawView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
SetCursor(m_hCursor);
CView::OnMouseMove(nFlags, point);
}
Copyright (c) 1999 - 2001, robert han, all rigths are reserved.