zoukankan      html  css  js  c++  java
  • VC实现自定义按钮响应拖动

    代码
    void CMoveableButton::OnLButtonDown(UINT nFlags, CPoint point)
    {
    // TODO: Add your message handler code here and/or call default
    m_bStartMove = TRUE;
    CButton::OnLButtonDown(nFlags, point);
    }

    void CMoveableButton::OnLButtonUp(UINT nFlags, CPoint point)
    {
    // TODO: Add your message handler code here and/or call default
    m_bStartMove = FALSE;
    CButton::OnLButtonUp(nFlags, point);
    }

    void CMoveableButton::OnMouseMove(UINT nFlags, CPoint point)
    {
    // TODO: Add your message handler code here and/or call default
    if (m_bStartMove)
    {
    ReleaseCapture();
    SendMessage(WM_NCLBUTTONDOWN, (WPARAM)HTCAPTION,
    0);
    }
    CButton::OnMouseMove(nFlags, point);
    }

    ==========================

    OnMouseMove的另一种写法:

    void CMoveableButton::OnMouseMove(UINT nFlags, CPoint point)
    {
    // TODO: Add your message handler code here and/or call default
    if (m_bStartMove)
    {
    CRect rect;

    ClientToScreen(
    &point);
    this->GetParent()->ScreenToClient(&point);

    GetClientRect(
    &rect);
    point.Offset(
    -rect.Width()/2, -rect.Height()/2);
    //        这里可能需要控制按钮的移动范围,使其不移动到界面外,方法:CWnd::SetWindowPlacement
    //   也可以自己实现

    SetWindowPos(NULL, point.x , point.y , 0, 0, SWP_NOZORDER|SWP_NOSIZE);
    // afxDump<<point.x<<","<<point.y<<"\n";
    Invalidate();
    }
    CButton::OnMouseMove(nFlags, point);
    }
  • 相关阅读:
    vim字体设置
    windows下eclipse打不开
    ubuntu的无线网无法连上
    将ubuntu系统录到u盘上
    使用UltraISO刻录系统到U盘可能会出现打不开的情况
    windows安装程序制作
    安装ubuntu双系统
    数据库插入数据时间比较
    LeetCode 189. Rotate Array
    LeetCode 228. Summary Ranges
  • 原文地址:https://www.cnblogs.com/aoyihuashao/p/1623710.html
Copyright © 2011-2022 走看看