Duilib 弹出子对话框

来源:互联网 发布:prim算法的时间复杂度 编辑:程序博客网 时间:2024/04/19 20:10

要在Duilib中弹出子对话框,首先定义一个需要弹出的自对话框的类,例子如下:

class CInstall : public CWindowWnd, public INotifyUI, public IMessageFilterUI{public:CInstall(){};virtual ~CInstall(){DestroyWindow(GetParent(this->GetHWND()));};LPCTSTR GetWindowClassName() const { return _T("UILoginFrame"); };UINT GetClassStyle() const { return UI_CLASSSTYLE_DIALOG; };void OnFinalMessage(HWND /*hWnd*/){m_pm.RemovePreMessageFilter(this);delete this;};void Init() {CComboUI* pAccountCombo = static_cast<CComboUI*>(m_pm.FindControl(_T("accountcombo")));CEditUI* pAccountEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("accountedit")));// 初始化CProgressUI控件CProgressUI* pProgress = static_cast<CProgressUI*>(m_pm.FindControl(_T("ProgressDemo1")));pProgress->SetValue(80);if (pAccountCombo && pAccountEdit) pAccountEdit->SetText(pAccountCombo->GetText());pAccountEdit->SetFocus();}void Notify(TNotifyUI& msg){}LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled){LONG styleValue = ::GetWindowLong(*this, GWL_STYLE);styleValue &= ~WS_CAPTION;::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);m_pm.Init(m_hWnd);m_pm.AddPreMessageFilter(this);CDialogBuilder builder;//CDialogBuilderCallbackEx cb;CControlUI* pRoot = builder.Create(_T("install.xml"), (UINT)0, NULL, &m_pm);ASSERT(pRoot && "Failed to parse XML");m_pm.AttachDialog(pRoot);m_pm.AddNotifier(this);Init();return 0;}LRESULT OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled){if (::IsIconic(*this)) bHandled = FALSE;return (wParam == 0) ? TRUE : FALSE;}LRESULT OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled){return 0;}LRESULT OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled){return 0;}LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled){POINT pt; pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam);::ScreenToClient(*this, &pt);RECT rcClient;::GetClientRect(*this, &rcClient);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)return HTCAPTION;}return HTCLIENT;}LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled){SIZE szRoundCorner = m_pm.GetRoundCorner();if (!::IsIconic(*this) && (szRoundCorner.cx != 0 || szRoundCorner.cy != 0)) {CDuiRect rcWnd;::GetWindowRect(*this, &rcWnd);rcWnd.Offset(-rcWnd.left, -rcWnd.top);rcWnd.right++; rcWnd.bottom++;HRGN hRgn = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy);::SetWindowRgn(*this, hRgn, TRUE);::DeleteObject(hRgn);}bHandled = FALSE;return 0;}LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam){LRESULT lRes = 0;BOOL bHandled = TRUE;switch (uMsg) {case WM_CREATE:        lRes = OnCreate(uMsg, wParam, lParam, bHandled); break;case WM_NCACTIVATE:    lRes = OnNcActivate(uMsg, wParam, lParam, bHandled); break;case WM_NCCALCSIZE:    lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled); break;case WM_NCPAINT:       lRes = OnNcPaint(uMsg, wParam, lParam, bHandled); break;case WM_NCHITTEST:     lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled); break;case WM_SIZE:          lRes = OnSize(uMsg, wParam, lParam, bHandled); break;default:bHandled = FALSE;}if (bHandled) return lRes;if (m_pm.MessageHandler(uMsg, wParam, lParam, lRes)) return lRes;return CWindowWnd::HandleMessage(uMsg, wParam, lParam);}LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled){if (uMsg == WM_KEYDOWN) {if (wParam == VK_RETURN) {CEditUI* pEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("accountedit")));if (pEdit->GetText().IsEmpty()) pEdit->SetFocus();else {pEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("pwdedit")));if (pEdit->GetText().IsEmpty()) pEdit->SetFocus();else Close();}return true;}else if (wParam == VK_ESCAPE) {PostQuitMessage(0);return true;}}return false;}public:CPaintManagerUI m_pm;};
上面的代码是仿照Duilib实例程序做的

然后下对应的xml文件

<?xml version="1.0" encoding="utf-8" standalone="yes" ?><Window size="600,372" caption="0,0,0,300"><Font name="宋体" size="9" bold="false" italic="false" /><VerticalLayout height="372" width="600" bkimage="installbg.png"><HorizontalLayout height="300" /><HorizontalLayout><Edit name="filepath2" height="23" padding="110,15,0,0" /><Progress name="ProgressDemo1" width="139" height="30" foreimage="progress_fore.png" min="0" max="100" value="50" hor="true" align="center" /><Button name="filebtn2" tooltip="打开文件对话框" normalimage="filebtn.png" hotimage="filebtn.png" pushedimage="filebtn.png" width="18" height="18" padding="10,17,32,0" /><Button name="install2" normalimage="install_1.png" hotimage="install_1.png" pushedimage="install_2.png" selectedimage="use_2.png" width="100" height="28" padding="0,10,20,0" /></HorizontalLayout></VerticalLayout></Window>
然后在对应的纤细

if (strName == _T("install")){auto installDlg = new CInstall();if (installDlg == NULL) { Close(); return; }installDlg->Create(m_hWnd, _T(""), UI_WNDSTYLE_DIALOG, 0, 0, 0, 0, 0, NULL);installDlg->CenterWindow();this->ShowWindow(false);installDlg->SetIcon(IDI_USBSETUP);installDlg->ShowModal();}
这样就可以弹出模态对话框了

0 0
原创粉丝点击