标签:
http://www.cnblogs.com/Alberl/p/3352696.html
// TODO: 在此添加额外的初始化代码 CPaintManagerUI::SetInstance(AfxGetInstanceHandle()); // 指定duilib的实例 CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath()); // 指定duilib资源的路径,这里指定为和exe同目录 ::CoInitialize(NULL); // 记得释放::CoUninitialize(); m_duiFrame.Create(*this, _T("DUIWnd"), UI_WNDSTYLE_CHILD, 0, 0, 0, 800, 600); m_duiFrame.ShowWindow(TRUE); return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
// 将带句柄HWND的控件显示到CControlUI上面 class CWndUI: public CControlUI { public: CWndUI(): m_hWnd(NULL){} virtual void SetInternVisible(bool bVisible = true) { __super::SetInternVisible(bVisible); ::ShowWindow(m_hWnd, bVisible); } virtual void SetPos(RECT rc) { __super::SetPos(rc); ::SetWindowPos(m_hWnd, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER | SWP_NOACTIVATE); } BOOL Attach(HWND hWndNew) { if (! ::IsWindow(hWndNew)) { return FALSE; } m_hWnd = hWndNew; return TRUE; } HWND Detach() { HWND hWnd = m_hWnd; m_hWnd = NULL; return hWnd; } protected: HWND m_hWnd; };
2、将XML中Slider节点换成Wnd,并且只保留位置信息,XML如下:
<Wnd float="true" pos="30,77,0,0" width="139" height="18" />
3、创建Wnd控件:由于Slider是duilib内置的控件,所以duilib会根据XML信息自动创建Slider控件,而CWndUI是我们自定义的控件,所以需要自己创建,只需要响应CreateControl函数(如果duilib发现自定义控件,会自动调用此函数来获取控件),在CDuiFrameWnd加上如下函数:
virtual CControlUI* CreateControl(LPCTSTR pstrClassName) { if (_tcsicmp(pstrClassName, _T("Wnd")) == 0) { CWndUI *pUI = new CWndUI; HWND hWnd = CreateWindow(_T("BUTTON"), _T("win32"), WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 0, 0, 0, 0, m_PaintManager.GetPaintWindow(), NULL, NULL, NULL); pUI->Attach(hWnd); //// 上面用的是win32的按钮,下面这段用MFC的按钮 //CButton *pBtn = new CButton; // 记得释放内存 //pBtn->Create(_T("MFC"), WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, CRect(0, 0, 0, 0), CWnd::FromHandle(m_PaintManager.GetPaintWindow()), 0); //pUI->Attach(*pBtn); return pUI; } return NULL; }
上面的代码用了win32的按钮,其中注释部分是MFC按钮,亲们可以都试下效果:
2013 duilib入门简明教程 -- 结合win32和MFC (16)
标签:
原文地址:http://www.cnblogs.com/dps001/p/4479160.html