我的工程是:单文档单视图的。我在视图类中改变了鼠标光标,当我又启动了视图的Timer事件后,该鼠标不停的闪。请大家指点一下,谢谢了。
BOOL CMenuExView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
// TODO: Add your message handler code here and/or call default
if(!m_oldCM.isEmpty())
{
::SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR1));
return TRUE;
}
return CView::OnSetCursor(pWnd, nHitTest, message);
}
void CMenuExView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent == 10)
{
CClientDC dc(this);
if(dc.GetSafeHdc() == NULL)
{
CView::OnTimer(nIDEvent);
return;
}
//画了几条线
}
CView::OnTimer(nIDEvent);
}
BOOL CMenuExView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
// TODO: Add your message handler code here and/or call default
if(!m_oldCM.isEmpty())
{
::SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR1));
return TRUE;
}
return CView::OnSetCursor(pWnd, nHitTest, message);
}
void CMenuExView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent == 10)
{
CClientDC dc(this);
if(dc.GetSafeHdc() == NULL)
{
CView::OnTimer(nIDEvent);
return;
}
//画了几条线
}
CView::OnTimer(nIDEvent);
}
一般在OnCreate()中
{
HCURSOR hCursor=::LoadCursor(::GetModuleHandler(), IDC_YOURCURSOR);
::SetClassLong(m_hWnd,GCL_HCURSOR, (LONG)hCursor);
...
return TRUE;
}
CMenuExView在mfc默认注册的时候用的是::LoadCursor(IDC_ARROW),所以你要改变它或者设为空NULL就可以chehw(chehw说得没错)
解决办法:
1
在PreCreateWindow()函数里面自己注册一个窗口类(他的hCursor=NULL)将类名传给cs.lpszClassName或者在OnCreate里面
{
::SetClassLong(m_hWnd,GCL_HCURSOR, (LONG)NULL);
SetCursor(::LoadCursor(::GetModuleHandler(), IDC_YOURCURSOR))//这样就不闪了
}