• 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);
    }
  • 相关阅读:
    VBA.replace替换单引号或双引号
    读取文件
    UPDATE
    alter update
    SQL日期格式
    python map的用法
    python os模块用法
    python re.I compile search
    python 正则匹配
    通过list中值得名称查询索引号
  • 原文地址:https://www.cnblogs.com/aoyihuashao/p/1623710.html
Copyright © 2020-2023  润新知