There are two different scenarios in which you can add a custom control:
1. Add a custom control to the Duilib library.
2. We have rewritten a control in our application.
Here's how to support configuring controls in XML files in different scenarios:
1, the situation in the library
If the custom control is the Cgifui class.
The case in the library is relatively simple, just create the control when parsing the XML file, so the function I found is ccontrolui*cdialogbuilder:: _parse ( Cmarkupnode*proot, ccontrolui*pparent, cpaintmanagerui*Pmanager ). Add the following code to this function:
size_t cchlen = _tcslen(pstrclass);
Switch (Cchlen) {
Case 3:
if (_tcscmp(pstrclass,dui_ctr_gif) = = 0) Pcontrol = new Cgifui;
// The following macro definition is XML The configuration items that are configured in
#define Dui_ctr_gif (_t("Gif"))
2. Outside of the library
If the custom control is a ctransporttasklayout class
Outside the library, it may be a bit of a hassle. First, we'll call the following function when we load the XML file:
Ccontrolui* Create (stringorid XML,
lpctstr type = NULL,
idialogbuildercallback* pcallback =NULL,
Cpaintmanagerui* pmanager =NULL,
Ccontrolui* pparent = NULL);
The parameters associated with this function are idialogbuildercallback* pcallback.
The first thing to make clear is that this control is not accepted in the duilib, so it can only be kept in the outer dwelling. As for how to keep let me give you the following carefully said. Although the home is not acceptable, but we must accept this fact, so we must find a way to solve this problem, it will start from the above parameters, I see ccontrolui*cdialogbuilder:: _ The parse function knows that if this type of control is not accepted in the original Duilib library, it will be called Pcontrol = M_pcallback->createcontrol (pstrclass) after the function.
, this gives us the opportunity to become a positive, so we can rewrite a idialogbuildercallback class, and then rewrite the CreateControl function in the class to create our own new control. The code that is used in the project is given below:
class ctransporttaskbuildercallback : public idialogbuildercallback
{
Public:
Ctransporttaskbuildercallback () {};
Virtual Ccontrolui* CreateControl (lpctstrpstrclass)
{
if (_tcscmp(pstrclass,_t("Transporttasklayout")) = = 0)
{
Ctransporttasklayout * playout = (ctransporttasklayout*) g_transportlistuicenter-> Createlayoutinstance (_t("Transporttasklayout"));
return playout;
}
return NULL;
}
};
The above class would create an object of the Ctransporttasklayout class if the "Transporttasklayout" string was found in the XML file .
The outside house has been regularized. There is no such thing as beauty in real life, it is deadly to turn.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
How can I configure the use of a custom control in an XML file after adding a duilib