文章目录
1.CDialogBuilder对象Create函数
- 1.CDialogBuilder对象Create函数
- 2.作者答疑
上一部分有对窗口创建过程有一个大概的了解,这一部分主要讲述duilib对xml文件的加载及创建对应的子控件对象。从上一部分可知,这部分隐藏在Create函数中,源代码如下:
CControlUI* CDialogBuilder::Create(STRINGorID xml, LPCTSTR type, IDialogBuilderCallback* pCallback,
CPaintManagerUI* pManager, CControlUI* pParent)
{
//资源ID为0-65535,两个字节;字符串指针为4个字节
//字符串以SetDefaultFont(pFontName, pManager->GetDPIObj()->Scale(size), bold, underline, italic, shared);
}
}
else if( _tcsicmp(pstrClass, _T("Default")) == 0 ) {//其它的默认参数
nAttributes = node.GetAttributeCount();
LPCTSTR pControlName = NULL;
LPCTSTR pControlValue = NULL;
bool shared = false;
for( int i = 0; i AddDefaultAttributeList(pControlName, pControlValue, shared);
}
}
else if( _tcsicmp(pstrClass, _T("Style")) == 0 ) {//风格对象
nAttributes = node.GetAttributeCount();
LPCTSTR pName = NULL;
LPCTSTR pStyle = NULL;
bool shared = false;
for( int i = 0; i AddStyle(pName, pStyle, shared);
}
}
else if (_tcsicmp(pstrClass, _T("Import")) == 0) {
nAttributes = node.GetAttributeCount();
LPCTSTR pstrPath = NULL;
for (int i = 0; i AddFontArray(pstrPath);
}
}
}
pstrClass = root.GetName();
if( _tcsicmp(pstrClass, _T("Window")) == 0 ) {//窗口对象构建参数
if( pManager->GetPaintWindow() ) {
int nAttributes = root.GetAttributeCount();
for( int i = 0; i SetInitSize(pManager->GetDPIObj()->Scale(cx), pManager->GetDPIObj()->Scale(cy));
}
else if( _tcsicmp(pstrName, _T("sizebox")) == 0 ) {
RECT rcSizeBox = { 0 };
LPTSTR pstr = NULL;
rcSizeBox.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
rcSizeBox.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
rcSizeBox.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
rcSizeBox.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
pManager->SetSizeBox(rcSizeBox);
}
else if( _tcsicmp(pstrName, _T("caption")) == 0 ) {
RECT rcCaption = { 0 };
LPTSTR pstr = NULL;
rcCaption.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
rcCaption.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
rcCaption.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
rcCaption.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
pManager->SetCaptionRect(rcCaption);
}
else if( _tcsicmp(pstrName, _T("roundcorner")) == 0 ) {
LPTSTR pstr = NULL;
int cx = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
int cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
pManager->SetRoundCorner(cx, cy);
}
else if( _tcsicmp(pstrName, _T("mininfo")) == 0 ) {
LPTSTR pstr = NULL;
int cx = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
int cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
pManager->SetMinInfo(cx, cy);
}
else if( _tcsicmp(pstrName, _T("maxinfo")) == 0 ) {
LPTSTR pstr = NULL;
int cx = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
int cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
pManager->SetMaxInfo(cx, cy);
}
else if( _tcsicmp(pstrName, _T("showdirty")) == 0 ) {
pManager->SetShowUpdateRect(_tcsicmp(pstrValue, _T("true")) == 0);
}
else if( _tcsicmp(pstrName, _T("opacity")) == 0 || _tcsicmp(pstrName, _T("alpha")) == 0 ) {
pManager->SetOpacity(_ttoi(pstrValue));
}
else if( _tcscmp(pstrName, _T("layeredopacity")) == 0 ) {
pManager->SetLayeredOpacity(_ttoi(pstrValue));
}
else if( _tcscmp(pstrName, _T("layered")) == 0 || _tcscmp(pstrName, _T("bktrans")) == 0) {
pManager->SetLayered(_tcsicmp(pstrValue, _T("true")) == 0);
}
else if( _tcscmp(pstrName, _T("layeredimage")) == 0 ) {
pManager->SetLayered(true);
pManager->SetLayeredImage(pstrValue);
}
else if( _tcscmp(pstrName, _T("noactivate")) == 0 ) {
pManager->SetNoActivate(_tcsicmp(pstrValue, _T("true")) == 0);
}
else if( _tcsicmp(pstrName, _T("disabledfontcolor")) == 0 ) {
if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
LPTSTR pstr = NULL;
DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
pManager->SetDefaultDisabledColor(clrColor);
}
else if( _tcsicmp(pstrName, _T("defaultfontcolor")) == 0 ) {
if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
LPTSTR pstr = NULL;
DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
pManager->SetDefaultFontColor(clrColor);
}
else if( _tcsicmp(pstrName, _T("linkfontcolor")) == 0 ) {
if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
LPTSTR pstr = NULL;
DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
pManager->SetDefaultLinkFontColor(clrColor);
}
else if( _tcsicmp(pstrName, _T("linkhoverfontcolor")) == 0 ) {
if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
LPTSTR pstr = NULL;
DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
pManager->SetDefaultLinkHoverFontColor(clrColor);
}
else if( _tcsicmp(pstrName, _T("selectedcolor")) == 0 ) {
if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
LPTSTR pstr = NULL;
DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
pManager->SetDefaultSelectedBkColor(clrColor);
}
else if( _tcsicmp(pstrName, _T("shadowsize")) == 0 ) {
pManager->GetShadow()->SetSize(_ttoi(pstrValue));
}
else if( _tcsicmp(pstrName, _T("shadowsharpness")) == 0 ) {
pManager->GetShadow()->SetSharpness(_ttoi(pstrValue));
}
else if( _tcsicmp(pstrName, _T("shadowdarkness")) == 0 ) {
pManager->GetShadow()->SetDarkness(_ttoi(pstrValue));
}
else if( _tcsicmp(pstrName, _T("shadowposition")) == 0 ) {
LPTSTR pstr = NULL;
int cx = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
int cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
pManager->GetShadow()->SetPosition(cx, cy);
}
else if( _tcsicmp(pstrName, _T("shadowcolor")) == 0 ) {
if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
LPTSTR pstr = NULL;
DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
pManager->GetShadow()->SetColor(clrColor);
}
else if( _tcsicmp(pstrName, _T("shadowcorner")) == 0 ) {
RECT rcCorner = { 0 };
LPTSTR pstr = NULL;
rcCorner.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
rcCorner.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
rcCorner.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
rcCorner.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
pManager->GetShadow()->SetShadowCorner(rcCorner);
}
else if( _tcsicmp(pstrName, _T("shadowimage")) == 0 ) {
pManager->GetShadow()->SetImage(pstrValue);
}
else if( _tcsicmp(pstrName, _T("showshadow")) == 0 ) {
pManager->GetShadow()->ShowShadow(_tcsicmp(pstrValue, _T("true")) == 0);
}
else if( _tcsicmp(pstrName, _T("gdiplustext")) == 0 ) {
pManager->SetUseGdiplusText(_tcsicmp(pstrValue, _T("true")) == 0);
}
else if( _tcsicmp(pstrName, _T("textrenderinghint")) == 0 ) {
pManager->SetGdiplusTextRenderingHint(_ttoi(pstrValue));
}
else if( _tcsicmp(pstrName, _T("tooltiphovertime")) == 0 ) {
pManager->SetHoverTime(_ttoi(pstrValue));
}
}
}
}
}
return _Parse(&root, pParent, pManager);
}
以上代码就是根据xml根节点的第一层子节点(Font ,Default )属性值,设置CPaintManagerUI对象的参数,同时加载根节点(Window )窗口对象的属性设置窗口属性。xml例子如下所示:
最后的_Parse(&root, pParent, pManager)函数里,再根据xml子节点内容动态构建子控件树。放在下一部分讲解。
2.作者答疑如有疑问,请留言。