响应WM_LMOUSEDOWN消息,设置标志
响应WM_MOUSEMOVE消息,如标志为真则根据鼠标位置移动窗口
我做过,很简单

解决方案 »

  1.   

    我做了一个基于对话框的工程Winamp
    在类 CWinampDlg 中新增3个成员变量
    int MoveFlag;
    int xx,yy;BOOL CWinampDlg::OnInitDialog()
    {
    // TODO: Add extra initialization here
    MoveFlag = FALSE;
    xx = 0;
    yy = 0;
    }void CWinampDlg::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    MoveFlag = TRUE;
    RECT Rect;
    POINT Point;
    GetWindowRect(&Rect);
    GetCursorPos(&Point);
    xx = Point.x - Rect.left;
    yy = Point.y - Rect.top;
    SetCapture();
    }void CWinampDlg::OnLButtonUp(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    MoveFlag = FALSE;
    ReleaseCapture();
    }void CWinampDlg::OnMouseMove(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    if(MoveFlag != TRUE)
    return;
    POINT Point;
    GetCursorPos(&Point);
    SetWindowPos(&wndTop,Point.x-xx,Point.y-yy,0,0,SWP_NOSIZE);
    }