我写了个程序 判断点击屏幕移动的方向 并且移动void CScreenDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnMouseMove(nFlags, point);
if(point.x - StartX >= 0)
{
//AfxMessageBox(_T("右移动!"));
MoveWindow(point.x - StartX,0,550,550,true);//StartX,EndY是保存上一点的坐标
}
else if(point.x - StartX < 0)
{
//AfxMessageBox(_T("左移动!"));
MoveWindow(point.x - StartX,0,550,550,true);
}
if(point.y - EndY >= 0)
{
//AfxMessageBox(_T("下移动!"));
MoveWindow(0,point.y - EndY,550,550,true);
}
else if(point.y - EndY < 0)
{
//AfxMessageBox(_T("上移动!"));
MoveWindow(0,point.y - EndY,550,550,true);
}
}
但是为什么只能运行上 和 下 移动的方向,左右无法执行,我判断可能得用线程解决,但是线程就不懂了,该怎样改,既能识别上下又能识别左右,谢谢!
{
// TODO: Add your message handler code here and/or call default
CDialog::OnMouseMove(nFlags, point);
if(point.x - StartX >= 0)
{
//AfxMessageBox(_T("右移动!"));
MoveWindow(point.x - StartX,0,550,550,true);//StartX,EndY是保存上一点的坐标
}
else if(point.x - StartX < 0)
{
//AfxMessageBox(_T("左移动!"));
MoveWindow(point.x - StartX,0,550,550,true);
}
if(point.y - EndY >= 0)
{
//AfxMessageBox(_T("下移动!"));
MoveWindow(0,point.y - EndY,550,550,true);
}
else if(point.y - EndY < 0)
{
//AfxMessageBox(_T("上移动!"));
MoveWindow(0,point.y - EndY,550,550,true);
}
}
但是为什么只能运行上 和 下 移动的方向,左右无法执行,我判断可能得用线程解决,但是线程就不懂了,该怎样改,既能识别上下又能识别左右,谢谢!
CRect rect;
GetWindowRect(&rect); if(point.x - StartX >= 0)
{
//AfxMessageBox("右移动!"));
MoveWindow(rect.left+point.x - StartX,0,550,550,true);//StartX丆EndY惀曐懚忋堦揰揑嵖?
}
else if(point.x - StartX < 0)
{
//AfxMessageBox(_T("左移动!"));
MoveWindow(rect.left+point.x - StartX,0,550,550,true);
}
if(point.y - EndY >= 0)
{
//AfxMessageBox(_T("下移动!"));
MoveWindow(0,rect.top+point.y - EndY,550,550,true);
}
else if(point.y - EndY < 0)
{
//AfxMessageBox(_T("上移动!"));
MoveWindow(0,rect.top+point.y - EndY,550,550,true);
}
是为了获取原来坐标的
1.定义一个全局变量int lbuttondown=false;来标示鼠标是否按下;
2.在OnLButtonDown(UINT nFlags, CPoint point) 中添加如下代码:
// TODO: Add your message handler code here and/or call default
StartX=point.x;
EndY=point.y;
lbuttondown=true;
CDialog::OnLButtonDown(nFlags, point);
3.在OnLButtonUp(UINT nFlags, CPoint point) 中添加如下代码:
// TODO: Add your message handler code here and/or call default
lbuttondown=false;
CDialog::OnLButtonUp(nFlags, point);
4.在OnMouseMove(UINT nFlags, CPoint point) 中添加如下代码:
// TODO: Add your message handler code here and/or call default
CRect rect;
GetWindowRect(&rect); if(true==lbuttondown)
{
MoveWindow(rect.left+(point.x-StartX),rect.top+(point.y-EndY),rect.Width(),rect.Height(),true);
} CDialog::OnMouseMove(nFlags, point);
试试看,在VC6.0下,可以实现你所想要的效果,但在PDA中我不太清楚。