我写了个程序 判断点击屏幕移动的方向 并且移动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);
}
}
但是为什么只能运行上 和 下 移动的方向,左右无法执行,我判断可能得用线程解决,但是线程就不懂了,该怎样改,既能识别上下又能识别左右,谢谢!

解决方案 »

  1.   

    改成下面的试试:
    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); 
      

  2.   

    是拖动整个Dialog 任意位置移动就像手机里移动某个桌面 可以左右移动的  我是在PDA里运行的
      

  3.   

    可不可以添加鼠标点击事件的处理函数?如:OnLButtonDown(UINT nFlags, CPoint point) 等?
      

  4.   

    我添加OnLButtonDown(UINT nFlags, CPoint point)
    是为了获取原来坐标的
      

  5.   

    没搞过PDA,我是在VC6.0下做的,如下,你可以试试。
    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中我不太清楚。
      

  6.   

    不过我觉得加那个鼠标按下标志没什么意义 去掉了关键点 就是写一个MoveWindow函数