duilib的一些bug

duilib是一个开源界面库,作者在使用过程中发现其界面编辑器存在崩溃的bug。由于duilib用户不多,该问题未得到广泛解决。作者自行修复了此问题,并计划提交代码,但由于无法加入duilib社区而作罢。这里分享了修复bug的经验,可供遇到同样问题的开发者参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

duilib是一个开源的界面库,我的一个软件--小妞会装机就是用它做界面库。小妞会装机这个软件界面比较简单,就用到了一些基本控件,所以用duilib是挺合适的。但是有个问题真是让人郁闷,那就是它的界面编辑器总是崩溃。看来duilib用的人还是很少,要不不会有这么多问题。我自己是不能忍受了,就把这个bug改了一下。本想将修复代码提交给duilib,但是申请加入duilib群没有成功。算了,贴在这儿吧。如果有人正遇到这个问题倒是可以做一个参考。

出问题的地方:

void CLayoutManager::TestForm(LPCTSTR pstrFile)
{
	CFormTestWnd* pFrame=new CFormTestWnd();
	CPaintManagerUI* pManager=new CPaintManagerUI();
	SIZE size=m_Manager.GetInitSize();
	pManager->SetInitSize(size.cx,size.cy);
	pManager->SetSizeBox(m_Manager.GetSizeBox());
	RECT rect=m_Manager.GetCaptionRect();
	if (rect.bottom==0)
	{
		rect.bottom=30;
	}
	pManager->SetCaptionRect(rect);
	size=m_Manager.GetRoundCorner();
	pManager->SetRoundCorner(size.cx,size.cy);
	size=m_Manager.GetMinInfo();
	pManager->SetMinInfo(size.cx,size.cy);
	size=m_Manager.GetMaxInfo();
	pManager->SetMaxInfo(size.cx,size.cy);
	pManager->SetShowUpdateRect(m_Manager.IsShowUpdateRect());

	if( pFrame == NULL )
		return;

	g_HookAPI.EnableInvalidate(false);

	pFrame->SetManager(pManager);
	HWND h_wnd =pFrame->Create(m_Manager.GetPaintWindow(),_T("FormTest"),UI_WNDSTYLE_FRAME,0,0,0,size.cx,size.cy);

	// CControlUI* pRoot=CloneControls(GetForm()->GetItemAt(0));
	// 使用新建的XML树来预览,不会挂掉
	pManager->Init(h_wnd);
	CDialogBuilder builder;
	CContainerUI* pRoot=static_cast<CContainerUI*>(builder.Create(pstrFile,(UINT)0,NULL,pManager));
	if(pRoot==NULL)
		return;

	//pRoot->SetManager(NULL,NULL);
	pFrame->SetRoot(pRoot);
	pFrame->Init();


	pFrame->CenterWindow();

	HWND m_hWnd=pFrame->GetHWND();
	MSG msg = { 0 };
	while( ::IsWindow(m_hWnd) && ::GetMessage(&msg, NULL, 0, 0) ) {
		if( msg.hwnd != m_hWnd ) {
			if( (msg.message >= WM_MOUSEFIRST && msg.message <= WM_MOUSELAST) )
				continue;
			if( msg.message >= WM_KEYFIRST && msg.message <= WM_KEYLAST ) 
				continue;
			if( msg.message == WM_SETCURSOR )
				continue;
		}
		if( !CPaintManagerUI::TranslateMessage(&msg) ) {
			::TranslateMessage(&msg);
			::DispatchMessage(&msg);
		}
		if( msg.message == WM_QUIT ) break;
	}
	if( msg.message == WM_QUIT ) ::PostQuitMessage(msg.wParam);

	g_HookAPI.EnableInvalidate(true);

	DeleteFile(pstrFile);
}

改为

void CLayoutManager::TestForm(LPCTSTR pstrFile)
{
	CFormTestWnd* pFrame=new CFormTestWnd();
	CPaintManagerUI* pManager=new CPaintManagerUI();
	SIZE size=m_Manager.GetInitSize();
	pManager->SetInitSize(size.cx,size.cy);
	pManager->SetSizeBox(m_Manager.GetSizeBox());
	RECT rect=m_Manager.GetCaptionRect();
	if (rect.bottom==0)
	{
		rect.bottom=30;
	}
	pManager->SetCaptionRect(rect);
	size=m_Manager.GetRoundCorner();
	pManager->SetRoundCorner(size.cx,size.cy);
	size=m_Manager.GetMinInfo();
	pManager->SetMinInfo(size.cx,size.cy);
	size=m_Manager.GetMaxInfo();
	pManager->SetMaxInfo(size.cx,size.cy);
	pManager->SetShowUpdateRect(m_Manager.IsShowUpdateRect());

	if( pFrame == NULL )
		return;

	g_HookAPI.EnableInvalidate(false);

	pFrame->SetManager(pManager);
	HWND h_wnd =pFrame->Create(m_Manager.GetPaintWindow(),_T("FormTest"),UI_WNDSTYLE_FRAME,0,0,0,size.cx,size.cy);

	// CControlUI* pRoot=CloneControls(GetForm()->GetItemAt(0));
	// 使用新建的XML树来预览,不会挂掉
	pManager->Init(h_wnd);
	CDialogBuilder builder;
	CContainerUI* pRoot=static_cast<CContainerUI*>(builder.Create(pstrFile,(UINT)0,NULL,pManager));
	if(pRoot==NULL)
		return;

	//pRoot->SetManager(NULL,NULL);
	pFrame->SetRoot(pRoot);
	pFrame->Init();


	pFrame->CenterWindow();
	// 修正win7下TestForm一开始没有反应,必须先激活其它程序在切换到TestFrom才有反应的bug
	pFrame->ShowModal();

	//HWND m_hWnd=pFrame->GetHWND();
	//MSG msg = { 0 };
	//while( ::IsWindow(m_hWnd) && ::GetMessage(&msg, NULL, 0, 0) ) {
	//	if( msg.hwnd != m_hWnd ) {
	//		if( (msg.message >= WM_MOUSEFIRST && msg.message <= WM_MOUSELAST) )
	//			continue;
	//		if( msg.message >= WM_KEYFIRST && msg.message <= WM_KEYLAST ) 
	//			continue;
	//		if( msg.message == WM_SETCURSOR )
	//			continue;
	//	}
	//	if( !CPaintManagerUI::TranslateMessage(&msg) ) {
	//		::TranslateMessage(&msg);
	//		::DispatchMessage(&msg);
	//	}
	//	if( msg.message == WM_QUIT ) break;
	//}
	//if( msg.message == WM_QUIT ) ::PostQuitMessage(msg.wParam);

	g_HookAPI.EnableInvalidate(true);

	DeleteFile(pstrFile);
}

就好了
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值