简体   繁体   English

可通过位图拖动的C ++窗口

[英]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: 我没有尝试过,但是类似的方法应该起作用:

  1. Declare a Boolean value called eg isDragging and set it to false. 声明一个布尔值,例如isDragging并将其设置为false。
  2. In the handler of 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. 保存光标相对于窗口左上角的位置。
  3. In the handler of 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,则移动窗口(调用MoveWindowSetWindowPos )以恢复其相对于光标的位置。
  4. In the handler of 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM