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);
    }
  • 相关阅读:
    IOS基础之 (二) 面向对象思想
    Android学习笔记02-Mac下编译java代码
    常用数据库 JDBC URL 格式
    MySQL学习笔记04 插入中文时出现ERROR 1366 (HY000)
    bootstrap学习总结-06 按钮
    H2嵌入式数据库
    02 C语言指针
    页面技巧
    RequireJS进阶(二)
    RequireJS进阶(一)
  • 原文地址:https://www.cnblogs.com/aoyihuashao/p/1623710.html
Copyright © 2011-2022 走看看