無標題視窗拖動

來源:互聯網
上載者:User
這代碼的確很老,網上也沒別的了。。。。
LRESULT CbarDlg::OnNcHitTest(CPoint point){// TODO: 在此添加訊息處理常式代碼和/或調用預設值const int borderwidth = 7;CRect rect;GetClientRect(rect);ScreenToClient(&point);if (point.y < borderwidth){return HTTOP;}if (point.x < borderwidth){return HTLEFT;}if(point.y > rect.bottom - rect.top - borderwidth && point.x > rect.right - rect.left - borderwidth)return HTBOTTOMRIGHT;if (point.y > rect.bottom - rect.top - borderwidth){return HTBOTTOM;}if (point.x > rect.right - rect.left - borderwidth){return HTRIGHT;}return HTCAPTION;//return CDialog::OnNcHitTest(point);}void CbarDlg::OnNcLButtonDown(UINT nHitTest, CPoint point){// TODO: 在此添加訊息處理常式代碼和/或調用預設值// 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));}

另一種

LRESULT CSocketPhoneDlg::OnNcHitTest(CPoint point){// TODO: 在此添加訊息處理常式代碼和/或調用預設值static int m_TitleHeight = 5 , m_BorderLeftWidth = 5 ,m_BorderRightWidth=5, m_BorderBottomHeight = 5;CWnd *pWnd = CWnd::FromHandle(m_hWnd);CRect wr;pWnd->GetWindowRect(wr);point.x -= wr.left;point.y -= wr.top;CRect rc;int cx = GetSystemMetrics(SM_CXSMICON);int cy = GetSystemMetrics(SM_CYSMICON);rc = CRect( 0, 0, m_BorderLeftWidth, m_TitleHeight );if ( PtInRect( rc, point ))  //!IsZoomed(m_hWnd) )return HTTOPLEFT;rc = CRect( wr.Width() - m_BorderLeftWidth, 0,  wr.Width(), m_TitleHeight  );if ( PtInRect( rc, point ) )  //!IsZoomed(m_hWnd) )return HTTOPRIGHT;rc = CRect( 0, wr.Height() - m_BorderBottomHeight, m_BorderLeftWidth, wr.Height() );if ( PtInRect( rc, point ) )  //!IsZoomed(m_hWnd) )return HTBOTTOMLEFT;rc = CRect( wr.Width()-m_BorderRightWidth, wr.Height() - m_BorderBottomHeight,  wr.Width(), wr.Height() );if ( PtInRect( rc, point ))  //!IsZoomed(m_hWnd) )return HTBOTTOMRIGHT;rc = CRect( 0, m_TitleHeight,  m_BorderLeftWidth, wr.Height() - m_BorderBottomHeight  );if ( PtInRect( rc, point ))  //!IsZoomed(m_hWnd) )return HTLEFT;rc = CRect( wr.Width()-m_BorderRightWidth, m_TitleHeight,  wr.Width(), wr.Height() - m_BorderBottomHeight  );if ( PtInRect( rc, point ) )  //!IsZoomed(m_hWnd) )return HTRIGHT;rc = CRect( m_BorderLeftWidth, wr.Height() - m_BorderBottomHeight,  wr.Width()-m_BorderRightWidth, wr.Height() );if ( PtInRect( rc, point ) )  //!IsZoomed(m_hWnd) )return HTBOTTOM;rc = CRect( m_BorderLeftWidth, 0,  wr.Width()-m_BorderRightWidth, m_BorderBottomHeight );if ( PtInRect( rc, point ))  //!IsZoomed(m_hWnd) )return HTTOP;return HTCLIENT;return CDialogEx::OnNcHitTest(point);}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.