改变光标的时机和WM_SETCURSOR消息的原理??

wangyangcheng 2005-02-03 01:51:55
改变光标:
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"?

谢谢!

...全文
1462 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
modena 2005-02-16
  • 打赏
  • 举报
回复
1.注册窗口类前设置鼠标
2.
1)m_hCursor = AfxGetApp() ->LoadCursor( IDI_DiamondCursor );这句话应该在CMyView的构造函数中执行
2)不建议使用判断条件"当前光标在客户区",建议使用nHitTest判断
3)自已设置光标如果不返回true,那么在执行你的设置光标后,后面的那句CView::OnSetCursor(pWnd, nHitTest, message);将使用父类CView的默认处理设置系统提供的默认光标
3.WM_SETCURSOR消息会在两种情况下被触发:
1)鼠标移动会引起窗口内光标位置变化;
2)当窗口失去鼠标捕获(如鼠标移出窗口)
4.SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)NULL);
wangyangcheng 2005-02-10
  • 打赏
  • 举报
回复
恭贺新喜,再顶!
wangyangcheng 2005-02-03
  • 打赏
  • 举报
回复
只有一个人?
fanqing 2005-02-03
  • 打赏
  • 举报
回复
1.我不知到哪里去把谁"set to NULL"?SetClassLong
2.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
class如果设置了光标,一般你设置的光标是局部的,跳出范围就无效了,恢复class设置的.
wangyangcheng 2005-02-03
  • 打赏
  • 举报
回复
又有人如是说:

SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)m_nCursor);
加在OnCreate

不得其解?

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧