打开资源,右击添加->选择Cursor->IDC_POINTER
头文件添加
public:
HCURSOR CUR;
protected:
void LoadCursorID(UINT Cur);
UINT CurName;
void CapPoint(CPoint MousePos);
源文件中添加
void Cvc1001View::LoadCursorID(UINT Cur)
{
CurName=Cur;
}
void Cvc1001View::CapPoint(CPoint MousePos)
{
CRect r;
GetClientRect(&r);
int Width,Hight;
Width=MousePos.x/(r.right/3);
Hight=MousePos.y/(r.bottom/3);
switch(Width)
{
case 0:
switch(Hight)
{
case 0:LoadCursorID(IDC_POINTER);break;
case 1:LoadCursorID(IDC_NODROP);break;
case 2:LoadCursorID(IDC_POINTER);break;
}break;
case 1:
switch(Hight)
{
case 0:LoadCursorID(IDC_POINTER);break;
case 1:LoadCursorID(IDC_NODROP);break;
case 2:LoadCursorID(IDC_POINTER);break;
}break;
case 2:
switch(Hight)
{
case 0:LoadCursorID(IDC_POINTER);break;
case 1:LoadCursorID(IDC_NODROP);break;
case 2:LoadCursorID(IDC_POINTER);break;
}break;
}
CUR=AfxGetApp()->LoadCursor(CurName);
Invalidate();
}
void Cvc1001View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CapPoint(point);
::SetCursor(CUR);
Invalidate();//刷新窗口
CView::OnMouseMove(nFlags, point);
头文件添加
public:
HCURSOR CUR;
protected:
void LoadCursorID(UINT Cur);
UINT CurName;
void CapPoint(CPoint MousePos);
源文件中添加
void Cvc1001View::LoadCursorID(UINT Cur)
{
CurName=Cur;
}
void Cvc1001View::CapPoint(CPoint MousePos)
{
CRect r;
GetClientRect(&r);
int Width,Hight;
Width=MousePos.x/(r.right/3);
Hight=MousePos.y/(r.bottom/3);
switch(Width)
{
case 0:
switch(Hight)
{
case 0:LoadCursorID(IDC_POINTER);break;
case 1:LoadCursorID(IDC_NODROP);break;
case 2:LoadCursorID(IDC_POINTER);break;
}break;
case 1:
switch(Hight)
{
case 0:LoadCursorID(IDC_POINTER);break;
case 1:LoadCursorID(IDC_NODROP);break;
case 2:LoadCursorID(IDC_POINTER);break;
}break;
case 2:
switch(Hight)
{
case 0:LoadCursorID(IDC_POINTER);break;
case 1:LoadCursorID(IDC_NODROP);break;
case 2:LoadCursorID(IDC_POINTER);break;
}break;
}
CUR=AfxGetApp()->LoadCursor(CurName);
Invalidate();
}
void Cvc1001View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CapPoint(point);
::SetCursor(CUR);
Invalidate();//刷新窗口
CView::OnMouseMove(nFlags, point);
}
本文转自wenglabs博客园博客,原文链接:http://www.cnblogs.com/greatverve/archive/2011/03/08/vc100-8.html,如需转载请自行联系原作者