程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> 無標題窗口拖動

無標題窗口拖動

編輯:C++入門知識

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));
}

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved