duilib 无标题窗口拖动


这里无标题 指的是: Window 标签属性 caption="0,0,0,0"


方法1:

LRESULT Mydlg::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
{
	if (uMsg == WM_LBUTTONDOWN)
	{
		POINT point = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
		ReleaseCapture();
		SendMessage(WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
	}
}


方法二:

在使用过程中有特需需求添加移动功能. 具体代码:


bool m_bStartMove = false;
POINT m_StartPt;
LRESULT CTestDialog::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
{
   if (uMsg == WM_MOUSEMOVE) {
		if (::GetAsyncKeyState(VK_LBUTTON) != 0 && m_bStartMove)
		{

                       if (!IsDragRect(pt)) return 0;
			POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
			int dx = pt.x - m_StartPt.x;
			int dy = pt.y - m_StartPt.y;
			RECT curRect;
			::GetWindowRect(m_hWnd, &curRect);

			int cx = curRect.left + dx;
			int cy = curRect.top + dy;

			int  w = curRect.right - curRect.left;
			int  h = curRect.bottom - curRect.top;

			SetWindowPos(m_hWnd, NULL, cx, cy, w, h, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
		}

	} else if (uMsg == WM_LBUTTONDOWN){
		POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
		m_bStartMove = TRUE;
		m_StartPt = pt;
	}else if (uMsg == WM_LBUTTONUP)
	{
		m_bStartMove = FALSE;
	}

	return FALSE;
}

// 这里实现类似标题栏的功能. 只有在 特定高度操作才生效:

bool CTestDialog::IsDragRect(POINT pt)
{
	RECT rcWnd;
	BOOL ret = ::GetWindowRect(m_hWnd, &rcWnd);
	int captionHeight = 60; //caption heigth.

	if (pt.y < captionHeight) {
		return true;
	}
	return false;
}



  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值