3

我正在设计一个自定义窗口边框,并在顶部放置一个位图作为拖动条。这可行,但是当我尝试拖动窗口时,它会将自身置于两个不同的区域并在两者之间闪烁。这是一个视频:

http://dl.dropbox.com/u/85700751/capture-1.avi

当窗口闪烁时,我正在尝试拖动它(由于某种原因它没有显示我的光标)。这是我的拖动代码:

case WM_LBUTTONDOWN: {
    int posX = LOWORD(lParam);
    int posY = HIWORD(lParam);
    if((isDragging==false)&&(posX>4)&&(posX<470)&&(posY>4)&&(posY<24))
        {
            isDragging = true;
            ClipCursor(rect);
            oldCursorX = posX;
            oldCursorY = posY;
        }
    }
    break;
case WM_LBUTTONUP: {
    isDragging = false;
    ClipCursor(NULL);
    }
    break;
case WM_MOUSEMOVE: {
        if(isDragging)  {
            SetWindowPos(hWnd, NULL, LOWORD(lParam)-oldCursorX, HIWORD(lParam)-oldCursorY, 500, 500, NULL);
        }
    }
    break;
4

2 回答 2

5

It's generally easiest to simply resond to WM_NCHITTEST. For that message, the LPARAM will have the mouse hit X and Y coordinates (same as WM_LBUTTONDOWN). If they're within your draggable area just return HTCAPTION. The system will then automatically handle all the drag logic for you.

于 2012-11-20T18:44:55.047 回答
0

传递给 WM_MOUSEMOVE 的光标坐标是相对于窗口位置的。但是每次收到 WM_MOUSEMOVE 时,您都会不断更改窗口位置。

使用 ::ClientToScreen() 将坐标转换为屏幕坐标。

于 2012-11-20T07:31:05.650 回答