共享demo中MFCDemo标题栏范围内button按钮,edit等不能响应鼠标点击的问题

源码下载地址为:Duilib源码

写在前面:解决办法是:OnNcHitTest函数中控件名称为Button,Text等,对于其他无法编辑的控件按照button格式添加上就可以啦。

使用VS2019,新建空白文档,将共享demo中MFCDemo中程序和Duilib文件夹添加进来,编译后发现几个问题:
1.需要修改编译路径
2,需要修改XML中textpadding 的位置,否则会造成字体在框体内部,见链接caption问题

textpadding="0,40,0,2" 

3.标题栏上按钮没有响应,edit控件无法编辑的问题:。
现在鼠标在右上角 关 按钮上,没有反应
在这里插入图片描述
更改方法为
【方法一】

LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)//窗口拖动

重写这个函数时,控件名称为 _T(“Button” 而不是 _T(“ButtonUI”
修改代码为:

RECT rcCaption = m_pm.GetCaptionRect();
		if( pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right 
			&& pt.y >= rcCaption.top && pt.y < rcCaption.bottom ) 
		{
				CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(pt));

				CString str = pControl->GetClass();//str = "HorizontalLayout"
				CString str2 = str.MakeLower();
				//_tcscmp 比较字符串是否一样,包括大小写  ,两个字符串相同的话,返回零        str2 = "horizontallayout"
				if( pControl && _tcscmp(pControl->GetClass(), _T("Button")) != 0 && 
					_tcscmp(pControl->GetClass(), _T("Option")) != 0 &&
					_tcscmp(pControl->GetClass(), _T("Text")) != 0 )
				{
					return HTCAPTION;
				}

				
		}

可以对比360safedemo中程序,控件名称也是Button。
而360中代码为:

RECT rcCaption = m_pm.GetCaptionRect();
		if( pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right \
			&& pt.y >= rcCaption.top && pt.y < rcCaption.bottom ) {
				CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(pt));
				if( pControl && _tcscmp(pControl->GetClass(), DUI_CTR_BUTTON) != 0 && 
					_tcscmp(pControl->GetClass(), DUI_CTR_OPTION) != 0 &&
					_tcscmp(pControl->GetClass(), DUI_CTR_TEXT) != 0 )
					return HTCAPTION;
		}

【方法二】
Alberl大神的,duilib进阶教程 – 改进窗口拖动 (12)

**【注意】**如果完全按照上述文章时,标题栏处的按钮和系统按钮是可以响应了,但那个时候,窗体不能拖动。

将上述文章中UI名称更改为下面才对的,名字不带ui两个字,“verticallayout”,可能是版本不一样导致的吧

        vctStaticName.push_back(_T("control"));
		vctStaticName.push_back(_T("text"));
		vctStaticName.push_back(_T("label"));
		vctStaticName.push_back(_T("container"));
		vctStaticName.push_back(_T("horizontallayout"));
		vctStaticName.push_back(_T("verticallayout"));
		vctStaticName.push_back(_T("tablayout"));
		vctStaticName.push_back(_T("childlayout"));
		vctStaticName.push_back(_T("dialoglayout"));

右上角 系统按钮有反应了:
在这里插入图片描述

标题栏处不能响应edit控件的问题:

把把edit控件放进入就OK啦,就可以编辑了。

if( pControl && _tcscmp(pControl->GetClass(), _T("Button")) != 0 && 
					_tcscmp(pControl->GetClass(), _T("Option")) != 0 &&
					_tcscmp(pControl->GetClass(), _T("Text")) != 0 &&
					_tcscmp(pControl->GetClass(), _T("Edit")) != 0)
				{
					return HTCAPTION;
				}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值