鼠标光标更改总结

参考:http://blog.csdn.net/duxiuxing/article/details/1599771

1.从文件加载光标图标

HCURSOR  hcur = ::LoadCursorFromFile(_T("Excalibur.cur"));//加载光标  
	::SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)hcur);
	return true;


2.从资源加载光标

HCURSOR hCur = LoadCursor(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDC_CURSOR_MOVE));
	::SetCursor(hCur);
//或者SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR_LINK));
	return true;



3.通过类名,按钮控件改变光标

CString sClassName;
	::GetClassName(pWnd->GetSafeHwnd(), sClassName.GetBuffer(80), 80);
	if (sClassName == "Button")
	{
		HCURSOR hCur = LoadCursor(AfxGetInstanceHandle(),
			MAKEINTRESOURCE(IDC_CURSOR_BT));
		//MAKEINTRESOURCE(IDC_CURSOR1));
		SetCursor(hCur);


	}


4.通过控件ID,按钮控件可以,静态框不行

	/*不可用 CStaic控件的属性Notify 必须要设置为TRUE 才能使得 当鼠标在 CStatic上时改变形状
	if (pWnd->GetDlgCtrlID() == IDC_STATIC_HOME)
	{
		//SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR_LINK));
		HCURSOR hCur = LoadCursor(AfxGetInstanceHandle(),
			MAKEINTRESOURCE(IDC_CURSOR_LINK));
		SetCursor(hCur);
	}
	*/


5.通过鼠标位置

pt坐标在OnMouseMove获取

void CControlDlg::OnMouseMove(UINT nFlags, CPoint point)
{
	 
	pt= point;


	CControlDlg::OnMouseMove(nFlags, point);
}


BOOL CControlDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
	CRect rect;	
	GetDlgItem(IDC_STATIC_HOME)->GetWindowRect(&rect);
	ScreenToClient(&rect);
	if(HTCLIENT == nHitTest&&rect.PtInRect(pt))	
	{
		//SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR_LINK));
		HCURSOR hCur = LoadCursor(AfxGetInstanceHandle(),
			MAKEINTRESOURCE(IDC_CURSOR_LINK));
		SetCursor(hCur);
	}


	return TRUE;
	// */
	//return CDialogEx::OnSetCursor(pWnd, nHitTest, message);
}


6.从系统加载

SetCursor(AfxGetApp()->LoadStandardCursor(IDC_HAND));
/*
 * Standard Cursor IDs
 */
#define IDC_ARROW           MAKEINTRESOURCE(32512)
#define IDC_IBEAM           MAKEINTRESOURCE(32513)
#define IDC_WAIT            MAKEINTRESOURCE(32514)
#define IDC_CROSS           MAKEINTRESOURCE(32515)
#define IDC_UPARROW         MAKEINTRESOURCE(32516)
#define IDC_SIZE            MAKEINTRESOURCE(32640)  /* OBSOLETE: use IDC_SIZEALL */
#define IDC_ICON            MAKEINTRESOURCE(32641)  /* OBSOLETE: use IDC_ARROW */
#define IDC_SIZENWSE        MAKEINTRESOURCE(32642)
#define IDC_SIZENESW        MAKEINTRESOURCE(32643)
#define IDC_SIZEWE          MAKEINTRESOURCE(32644)
#define IDC_SIZENS          MAKEINTRESOURCE(32645)
#define IDC_SIZEALL         MAKEINTRESOURCE(32646)
#define IDC_NO              MAKEINTRESOURCE(32648) /*not in win3.1 */
#if(WINVER >= 0x0500)
#define IDC_HAND            MAKEINTRESOURCE(32649)
#endif /* WINVER >= 0x0500 */
#define IDC_APPSTARTING     MAKEINTRESOURCE(32650) /*not in win3.1 */
#if(WINVER >= 0x0400)
#define IDC_HELP            MAKEINTRESOURCE(32651)
#endif /* WINVER >= 0x0400 */


你可能感兴趣的:(MFC/C++)