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);
    }
  • 相关阅读:
    扩展LVM 逻辑卷存储空间
    Linux Shell远程执行命令(命令行与脚本方式)
    vsftpd FTP服务器配置
    初识小米Minos
    使用Libpng库实现Tiny6410显示PNG图片
    uCos-II内存管理
    应用程序调用tslib出现segmentation fault
    Linux-2.6.39在Tiny6410上的移植
    Linux-2.6.39在Tiny6410上的移植
    Tiny6410移植tslib
  • 原文地址:https://www.cnblogs.com/aoyihuashao/p/1623710.html
Copyright © 2011-2022 走看看