Visual C++ 时尚编程百例008(鼠标形状)

打开资源,右击添加->选择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);
}
posted @ 2011-03-08 10:43  大气象  阅读(707)  评论(0编辑  收藏  举报
http://www.tianqiweiqi.com