zoukankan      html  css  js  c++  java
  • 无边框窗口实现拖拉效果

     实现效果需要处理以下这三个消息:

    WM_NCHITTEST  WM_SETCURSOR  WM_NCLBUTTONDOWN 

    UINT CXXXDlg::OnNcHitTest(UINT nHitTest, CPoint point)
    ...{
     // TODO: 在此添加消息处理程序代码和/或调用默认值
     CRect rect;
     CRect rect1;
     GetWindowRect(&rect);
     rect1 = rect;
     rect1.DeflateRect(10, 10, -10, -10);
     rect1.NormalizeRect();

     if(point.x <= rect.left+3)
      return HTLEFT;
     else if(point.x >= rect.right-3)
      return HTRIGHT;
     else if(point.y <= rect.top+3)
      return HTTOP;
     else if(point.y >= rect.bottom-3)
      return HTBOTTOM;
     else if(point.x <= rect.left+10 && point.y <= rect.top+10)
      return HTTOPLEFT;
     else if(point.x >= rect.right-10 && point.y <= rect.top+10)
      return HTTOPRIGHT;
     else if(point.x <= rect.left+10 && point.y >= rect.bottom-10)
      return HTBOTTOMLEFT;
     else if(point.x >= rect.right-10 && point.y >= rect.bottom-10)
      return HTBOTTOMRIGHT;
     else if(!rect.IsRectEmpty())
     {
      LRESULT uRet = CWnd::OnNcHitTest(point);
      uRet = (uRet == HTCLIENT) ? HTCAPTION : uRet;
      return uRet;
     }
     else
     {
      return CWnd::OnNcHitTest(point);
     }
        return 0;
    // return CWnd::OnNcHitTest(point);
    }


    BOOL CXXXDlg::OnSetCursor(HWND hWnd, UINT nHitTest, UINT message)
    ...{
        if(nHitTest == HTCAPTION || nHitTest == HTSYSMENU ||
           nHitTest == HTMENU || nHitTest == HTCLIENT)
       ...{
           SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)));
       }
       else if(nHitTest == HTTOP || nHitTest == HTBOTTOM)
       ...{
           SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENS)));
       }
       else if(nHitTest == HTLEFT || nHitTest == HTRIGHT)
       ...{
           SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZEWE)));
       }
       else if(nHitTest == HTTOPLEFT || nHitTest == HTBOTTOMRIGHT)
       ...{
           SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENWSE)));
       }
       else if(nHitTest == HTTOPRIGHT || nHitTest == HTBOTTOMLEFT)
       ...{
           SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENESW)));
       }
       else
       ...{
           SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)));
        }
    }



    void CEditWnd::OnNcLButtonDown(UINT nHitTest, CPoint point)
    {
     // TODO: 在此添加消息处理程序代码和/或调用默认值
       if(nHitTest == HTTOP)
           SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOP, MAKELPARAM(point.x, point.y));
       else if(nHitTest == HTBOTTOM)
           SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOM, MAKELPARAM(point.x, point.y));
       else if(nHitTest == HTLEFT)
           SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_LEFT, MAKELPARAM(point.x, point.y));
       else if(nHitTest == HTRIGHT)
           SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_RIGHT, MAKELPARAM(point.x, point.y));
       else if(nHitTest == HTTOPLEFT)
           SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOPLEFT, MAKELPARAM(point.x, point.y));
       else if(nHitTest == HTTOPRIGHT)
           SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOPRIGHT, MAKELPARAM(point.x, point.y));
       else if(nHitTest == HTBOTTOMLEFT)
           SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOMLEFT, MAKELPARAM(point.x, point.y));
       else if(nHitTest == HTBOTTOMRIGHT)
           SendMessage(WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOMRIGHT, MAKELPARAM(point.x, point.y));
       else if(nHitTest==HTCAPTION)
      SendMessage(WM_SYSCOMMAND, SC_MOVE | 4, MAKELPARAM(point.x, point.y));
     //CWnd::OnNcLButtonDown(nHitTest, point);
    }


    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/mynamelj/archive/2006/12/16/1445567.aspx

  • 相关阅读:
    感到工作效率低?是因为你缺少这套“外贸企业邮箱”办公软件
    用企业邮箱的好处,企业邮箱手机微信使用
    公司企业邮箱注册,公司为什么用企业邮箱?
    中小企业公司邮箱一般用哪个?申请企业邮箱的流程
    公司企业邮箱注册,企业邮箱怎么办理
    array_replace — 使用传递的数组替换第一个数组的元素
    array_replace_recursive — 使用传递的数组递归替换第一个数组的元素
    array_reduce — 用回调函数迭代地将数组简化为单一的值
    array_rand — 从数组中随机取出一个或多个单元
    array_push — 将一个或多个单元压入数组的末尾(入栈)
  • 原文地址:https://www.cnblogs.com/carl2380/p/1924647.html
Copyright © 2011-2022 走看看