Http://www.cnblogs.com/Alberl/p/3352696.html
Although Duilib comes with the Duilib demo in MFC, it is only the case that MFC Windows and duilib windows do not overlap. If you want to embed the Duilib control in the MFC window, or embed the MFC control in the Duilib control, there is no demo can see, in fact, Alberl began to do not know how to do, see the next Activexui control, this is the combination of HWND, But because of contact Duilib soon, so temporarily unable to understand Activexui exactly is how to Win32 the HWND, had to ask in the group, thanks to the pencil Group of Troy Great God Guide: At that time after the solution upload code, but still have netizens do not understand, So last night asked Alberl first write duilib combined with MFC tutorial, of course, this tutorial is originally in the Alberl plan, so on the compromise, the previous tutorial only wrote half, and so finish this tutorial to add, if the small partners have other requirements, can also mention Oh, If in Alberl's plan, Alberl will try to meet the requirements of the small partners ~o (∩_∩) o~, using Duilib in MFC only need to specify the Cduiframewnd parent window of the previous tutorial as an MFC window is good, will Cduiframew nd m_duiframe; Defined as the member variable of MFC, in the MFC initialization function OnInitDialog inside create duilib window, the code is as follows:
TODO: Add additional initialization code cpaintmanagerui::setinstance (AfxGetInstanceHandle ()) here; Specifies an instance of Duilib Cpaintmanagerui::setresourcepath (Cpaintmanagerui::getinstancepath ()); Specifies the path to the Duilib resource, specified here as the same directory as EXE :: CoInitialize (NULL); Remember to release:: CoUninitialize (); M_duiframe.create (*this, _t ("Duiwnd"), Ui_wndstyle_child, 0, 0, 0, (+); M_duiframe.showwindow (TRUE); return TRUE; Returns TRUE unless focus is set to the control
This is just to embed duilib into the main MFC window, if you want to embed Duilib into MFC a control, it is very simple, because only need an HWND handle on the line, do not repeat the ~ but you can find the following problems: 1, The bug that activexui before is no longer present. 2. All MFC controls are displayed above the Duilib window, which should be related to the Zord order. 3, in the Duilib window above the "OK" button point did not respond, "Cancel" button can only be clicked on the part of the duilib above will be a reaction. Since Alberl is only studying the interface for the time being, the incident response has not been studied, so the details are not studied. If you have a small partner, you can embed an MFC control on a Duilib control, or put an MFC control in a non-duilib zone, so you can respond. Ii. using MFC controls in Duilib Here's an example where the MFC button is placed in the Duilib slider bar control: 1. Prepare a Duilib control to accommodate the MFC control, as follows:
Display a control with a handle hWnd to Ccontrolui above 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. Replace the slider node in XML with Wnd, and keep only the location information, the XML is as follows:
<wnd float= "true" pos= "30,77,0,0" width= "139" height= "/>"
3. Create a Wnd control: Because the slider is a duilib built-in control, Duilib automatically creates a slider control based on the XML information, and Cwndui is our custom control, so we need to create it ourselves, You only need to respond to the CreateControl function (if Duilib discovers a custom control, this function is automatically called to get the control), and in Cduiframewnd the following function is added:
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); Above with the Win32 button, the following paragraph with the MFC button //cbutton *pbtn = new CButton; Remember to release memory //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;
The above code uses the Win32 button, where the comment part is the MFC button, the Pro can all try the effect:
So far, we can either add MFC controls to Duilib, or add duilib controls to an existing MFC project without worrying about using the previous controls ~o (∩_∩) o~
From for notes (Wiz)
Category: Duilib Introduction Concise Tutorial Tags: duilib tutorial, Duilib Getting Started, duilib Getting Started tutorial, duilib Getting Started documentation
A concise tutorial on getting started with duilib-combining Win32 and MFC (16)