为什么改变光标形状的代码在PreTranslateMessage可以,在OnMouseMove中不行?当按下鼠标左键并移动到不同按钮上时,应显示不同光标形状。代码如下:BOOL CCursorDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if((pMsg->message ==WM_MOUSEMOVE)&&(pMsg->wParam==MK_LBUTTON))
{
HCURSOR hcur;
POINT pt=pMsg->pt;
ScreenToClient(&pt); CWnd *pwnd=ChildWindowFromPoint(pt);
int nid=pwnd->GetDlgCtrlID();
switch(nid)
{
case IDC_BTNWAIT:
hcur=AfxGetApp()->LoadStandardCursor(IDC_WAIT);
::SetCursor(hcur);
break;
case IDC_BTNCROSS:
hcur=AfxGetApp()->LoadStandardCursor(IDC_CROSS );
::SetCursor(hcur);
break;
default:
break;
} }
return CDialog::PreTranslateMessage(pMsg);
}
void CCursorDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(nFlags==MK_LBUTTON)
{
HCURSOR hcur;
CPoint pt=point;
ScreenToClient(&pt); CWnd *pwnd=ChildWindowFromPoint(pt);
ASSERT(pwnd);
if(pwnd!=(CWnd*)this)
{
int nid=pwnd->GetDlgCtrlID();
switch(nid)
{
case IDC_BTNWAIT:
hcur=AfxGetApp()->LoadStandardCursor(IDC_WAIT);
::SetCursor(hcur);
break;
case IDC_BTNCROSS:
hcur=AfxGetApp()->LoadStandardCursor(IDC_CROSS );
::SetCursor(hcur);
break;
default:
break;
}
}
}
CDialog::OnMouseMove(nFlags, point);
}
{
// TODO: Add your specialized code here and/or call the base class
if((pMsg->message ==WM_MOUSEMOVE)&&(pMsg->wParam==MK_LBUTTON))
{
HCURSOR hcur;
POINT pt=pMsg->pt;
ScreenToClient(&pt); CWnd *pwnd=ChildWindowFromPoint(pt);
int nid=pwnd->GetDlgCtrlID();
switch(nid)
{
case IDC_BTNWAIT:
hcur=AfxGetApp()->LoadStandardCursor(IDC_WAIT);
::SetCursor(hcur);
break;
case IDC_BTNCROSS:
hcur=AfxGetApp()->LoadStandardCursor(IDC_CROSS );
::SetCursor(hcur);
break;
default:
break;
} }
return CDialog::PreTranslateMessage(pMsg);
}
void CCursorDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(nFlags==MK_LBUTTON)
{
HCURSOR hcur;
CPoint pt=point;
ScreenToClient(&pt); CWnd *pwnd=ChildWindowFromPoint(pt);
ASSERT(pwnd);
if(pwnd!=(CWnd*)this)
{
int nid=pwnd->GetDlgCtrlID();
switch(nid)
{
case IDC_BTNWAIT:
hcur=AfxGetApp()->LoadStandardCursor(IDC_WAIT);
::SetCursor(hcur);
break;
case IDC_BTNCROSS:
hcur=AfxGetApp()->LoadStandardCursor(IDC_CROSS );
::SetCursor(hcur);
break;
default:
break;
}
}
}
CDialog::OnMouseMove(nFlags, point);
}
直接用SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));就行了。呵呵
如果有问题因改是你的switch语句有问题。
HCURSOR hCursor = ::AfxGetApp()->LoadCursor(IDC_WAIT);
m_hOldCursor = ::SetCursor(hCursor);
另外请不要那么激动,大家都是互相帮忙的。你认为自己写的很清楚但别人就不一定这么认为了。
如果你是为了在左键点击时响应操作的话,不妨放在响应MK_LBUTTON消息的函数OnLButtonDown(UINT nFlags, CPoint point) 里试试,no problem~~~
if(nFlags==MK_LBUTTON)是判断在移动鼠标时左键是否按下
to 各位大虾:
谢谢各位的建议,我并不是没有实现这个功能,只是想问问在OnMouseMove中为何不灵?还请大家再看一下题
再则,鼠标移到按钮上时,获得OnMouseMove消息的将是按钮控件而不是对话框。
--------------------------------->
if((pMsg->message ==WM_MOUSEMOVE)||(pMsg->wParam==MK_LBUTTON))