// initialize the cursor array _afxCursors[0] = ::LoadCursor(hInst, MAKEINTRESOURCE(AFX_IDC_TRACKNWSE)); _afxCursors[1] = ::LoadCursor(hInst, MAKEINTRESOURCE(AFX_IDC_TRACKNESW)); _afxCursors[2] = _afxCursors[0]; _afxCursors[3] = _afxCursors[1]; _afxCursors[4] = ::LoadCursor(hInst, MAKEINTRESOURCE(AFX_IDC_TRACKNS)); _afxCursors[5] = ::LoadCursor(hInst, MAKEINTRESOURCE(AFX_IDC_TRACKWE)); _afxCursors[6] = _afxCursors[4]; _afxCursors[7] = _afxCursors[5]; _afxCursors[8] = ::LoadCursor(hInst, MAKEINTRESOURCE(AFX_IDC_TRACK4WAY)); _afxCursors[9] = ::LoadCursor(hInst, MAKEINTRESOURCE(AFX_IDC_MOVE4WAY)); { // trackers should only be in client area if (nHitTest != HTCLIENT) return FALSE; // convert cursor position to client co-ordinates CPoint point; GetCursorPos(&point); pWnd->ScreenToClient(&point); // do hittest and normalize hit int nHandle = HitTestHandles(point); if (nHandle < 0) return FALSE; // need to normalize the hittest such that we get proper cursors nHandle = NormalizeHit(nHandle); // handle special case of hitting area between handles // (logically the same -- handled as a move -- but different cursor) if (nHandle == hitMiddle && !m_rect.PtInRect(point)) { // only for trackers with hatchedBorder (ie. in-place resizing) if (m_nStyle & hatchedBorder) nHandle = (TrackerHit)9; } //ASSERT(nHandle < _countof(_afxCursors)); ::SetCursor(_afxCursors[nHandle]); return TRUE; }
to umbrella1984(雨伞(曾国文)):我想用的是一个动态图标,后缀是.ani,怎么放到资源里呢?资源里不是只能存.bmp和.icon这样的图标么?to lianglp() :我的光标并不动,动的是在视图里使用setpixel画的点,我的意思是把画的点,实时地在显示出来,而光标只不过是随着这个点运动在屏幕上来回移动而已,您看有什么办法没有?
_afxCursors[0] = ::LoadCursor(hInst, MAKEINTRESOURCE(AFX_IDC_TRACKNWSE));
_afxCursors[1] = ::LoadCursor(hInst, MAKEINTRESOURCE(AFX_IDC_TRACKNESW));
_afxCursors[2] = _afxCursors[0];
_afxCursors[3] = _afxCursors[1];
_afxCursors[4] = ::LoadCursor(hInst, MAKEINTRESOURCE(AFX_IDC_TRACKNS));
_afxCursors[5] = ::LoadCursor(hInst, MAKEINTRESOURCE(AFX_IDC_TRACKWE));
_afxCursors[6] = _afxCursors[4];
_afxCursors[7] = _afxCursors[5];
_afxCursors[8] = ::LoadCursor(hInst, MAKEINTRESOURCE(AFX_IDC_TRACK4WAY));
_afxCursors[9] = ::LoadCursor(hInst, MAKEINTRESOURCE(AFX_IDC_MOVE4WAY));
{
// trackers should only be in client area
if (nHitTest != HTCLIENT)
return FALSE; // convert cursor position to client co-ordinates
CPoint point;
GetCursorPos(&point);
pWnd->ScreenToClient(&point); // do hittest and normalize hit
int nHandle = HitTestHandles(point);
if (nHandle < 0)
return FALSE; // need to normalize the hittest such that we get proper cursors
nHandle = NormalizeHit(nHandle); // handle special case of hitting area between handles
// (logically the same -- handled as a move -- but different cursor)
if (nHandle == hitMiddle && !m_rect.PtInRect(point))
{
// only for trackers with hatchedBorder (ie. in-place resizing)
if (m_nStyle & hatchedBorder)
nHandle = (TrackerHit)9;
} //ASSERT(nHandle < _countof(_afxCursors));
::SetCursor(_afxCursors[nHandle]);
return TRUE;
}
怎么实现呢,最好有源码,多少分都无所谓,可以加分。我qq是38866544,email:[email protected],希望能和各位高手交流!
或
LoadCursorFromFile(在文件中)等等。当光标在某一窗口上移动时,系统会发送WM_SETCURSOR消息给目标窗口,
此时就可以调用SetCursor()来进行更换光标了。
HCURSOR mAniCursor;
然后在构造函数中:(_T("Rotate.ani")为您的光标文件路径)
mAniCursor=::LoadCursorFromFile(_T("Rotate.ani"));
在需要用到的地方,(一般在OnSetCursor()中)
SetCursor(mAniCursor);这只是从文件中load动画光标,从资源中load我也没成功。高手如果知道,不妨来指点一二。