[英]C++ Window draggable by a bitmap
I'm developing a custom window border in c++, well i guess that's what it is. 我正在用C ++开发自定义窗口边框,我想就是这样。 I don't know if i'm doing this the correct way or not, but i would appreciate knowing how to make a draggable window by a bitmap.
我不知道我是否以正确的方式进行操作,但是我很高兴知道如何通过位图制作可拖动的窗口。
there is a bitmap bar i made in photoshop and added to the client area, and i want to be able to drag it just by the bitmap. 我在photoshop中制作了一个位图栏,并将其添加到工作区中,我希望能够仅通过位图将其拖动。 Currently you can drag it by anywhere in the client area using this code:
当前,您可以使用以下代码将其拖到客户区中的任何位置:
case WM_NCHITTEST: {
LRESULT hit = DefWindowProc(hWnd, message, wParam, lParam);
if(hit == HTCLIENT) hit = HTCAPTION;
return hit;
}
break;
and I drew the bitmap using this code in the paint section: 我在绘制部分使用以下代码绘制了位图:
DrawBitmap(hdc,"header-bar-1.bmp", 2, 4);
and it looks like so: 它看起来像这样:
You can see the bar at the top, which is what i want to be able to drag it by. 您可以在顶部看到栏,这是我希望能够拖动的栏。
I haven't tried this, but something similar should work: 我没有尝试过,但是类似的方法应该起作用:
isDragging
and set it to false. isDragging
并将其设置为false。 WM_LBUTTONDOWN
, if isDragging
is false and the mouse is over the bitmap bar (use PtInRect
), set isDragging
to true, and confine the cursor into the rectangle of the bitmap by calling ClipCursor
. WM_LBUTTONDOWN
的处理程序中,如果isDragging
为false并且鼠标悬停PtInRect
图栏上(使用PtInRect
),请将isDragging
设置为true,然后通过调用ClipCursor
将光标限制ClipCursor
图的矩形内。 Save the position of the cursor relative to the window upper-left corner. WM_MOUSEMOVE
, if isDragging
is true, move the window (call MoveWindow
or SetWindowPos
) in order to restore its position relative to the cursor. WM_MOUSEMOVE
的处理程序中,如果isDragging
为true,则移动窗口(调用MoveWindow
或SetWindowPos
)以恢复其相对于光标的位置。 WM_LBUTTONUP
, if isDragging
is true, set it to false, and release the cursor by calling ClipCursor
appropriately. WM_LBUTTONUP
的处理程序中,如果isDragging
为true,则将其设置为false,然后通过适当调用ClipCursor
释放光标。 (Always take the difference between client coordinates and screen coordinates into account.) (始终考虑客户端坐标和屏幕坐标之间的差异。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.