改变光标的时机和WM_SETCURSOR消息的原理??
1。改变整个程序的光标:在CMyView::PreCreateWindow()中对cs进行改 造,如:
cs.lpszClass=AfxRegisterWndClass(CS_HREDRAW,AfxGetApp()->LoadStandardCursor(IDC_UPARROW), ::CreateSolidBrush(RGB(255,122,0)));
我有试验成功。
2.重载CMyView::OnSetCursor()
其内容譬如:
BOOL CScribbleView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
// TODO: Add your message handler code here and/or call default
if( 当前光标在客户区 )
{
m_hCursor = AfxGetApp() ->LoadCursor( IDI_DiamondCursor );
::SetCursor(m_hCursor );
return true; //自已设置光标为何这里要返回true?
}
return CView::OnSetCursor(pWnd, nHitTest, message);
}
而且这样之后在光标移出客户区然后 再移进来时就恢复系统默认光标了,Why?是否与我的第4个问题有关?
3. WM_SETCURSOR消息是谁在何时触发?
比如我不在此消息中变更光标,而在OnMouseMove()中变更光标,可否?
但我试验的结果似乎没有效。
有人说:
OnMouseMove中可以实现,不过还需要SetCapture,ReleaseCapture,当进入View窗口时ReleaseCapture,移出时SetCapture
4.MSDN上有这么一段话:
If your application must set the cursor while it is in a window, make sure the class cursor for the specified window's class is set to NULL. If the class cursor is not NULL, the system restores the class cursor each time the mouse is moved.
我不知到哪里去把谁"set to NULL"?
谢谢!
相关推荐
VC++,MFC 改变鼠标形状
VC++,MFC改变鼠标形状的例子,可以试着学习一下,这是例子一 还有个例子二
MFC 鼠标移动改变光标符号
MFC 鼠标移动改变光标符号
mfc设置鼠标光标
在程序中,我们有时候会想要设置自己设计的鼠标光标,那么这个demo讲给你一个很好启发。
显示动画光标(C#源代码编写)显示动画光标,当运行程序时,光标将变成动画光标
显示动画光标(C#源代码编写)显示动画光标,当运行程序时,光标将变成动画光标 VisualStudio2008创建[DllImport("user32")] private static extern IntPtr SetCursor(IntPtr hCursor); [DllImport("user32")] private static extern IntPtr LoadCursorFromFile(string lpFileName); const int WM_SETCURSOR = 0x0020; private void Form1_Load(object sender, EventArgs e) { IntPtr hCursor; hCursor = LoadCursorFromFile("..\\..\\stopwtch.ani"); SetCursor(hCursor); } protected override void WndProc(ref System.Windows.Forms.Message m) { switch (m.Msg) { case WM_SETCURSOR: IntPtr hCursor; hCursor = LoadCursorFromFile("..\\..\\stopwtch.ani"); SetCursor(hCursor); break; default: base.WndProc(ref m); break; }
系统 WM_ 消息列表及说明
系统 WM_ 消息列表及说明


