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);
}
头文件添加
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);
}
我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。
有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。