// 读取xml配置文件
EXPORTC void UITestXML(int i_dlg)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState()); DWORD time1, time2;
time1 = GetTickCount();
CharsChange strChange;
TiXmlNode* node1 = 0;
TiXmlNode* node2 = 0;
TiXmlNode* childNode2 = NULL;
TiXmlElement* todoElement = 0; // 资源清理
UIDeleteEdits();
theApp.v_edit.clear();
theApp.v_menu.clear();
SetFocus(theApp.gHwnd);
theApp.sc_dlg.push(i_dlg);
node1 = theApp.doc.FirstChild("system");
if (!node1)
return;
if (node2 = node1->FirstChild("dlg"))
{
CString strTemp;
std::string temp;
CString strPicName;
CString str1, str2, str3, str4;
int xpos, ypos, width, height;
do
{
todoElement = node2->ToElement();
todoElement->QueryValueAttribute("id", &temp);
strTemp = strChange.doChange(temp).c_str();
if (_ttoi(strTemp) != i_dlg)
{
continue;
}
//RETAILMSG(DllGUI_DEBUG, (L"DllGUI: cur dlg = %d\r\n", i_dlg));
// dialog matched, setting back image
childNode2 = node2->FirstChild("backfile");
strTemp = strChange.doChange(childNode2->ToElement()->GetText()).c_str();
theApp.strBkImg = strTemp; if(strTemp.Compare(L"black.bmp") != 0)
{
UISetBkImg(strTemp, 1);
}
else
{
//dcex->SetBkImg2();
UIFillSolidRect(NULL, RGB(0, 0, 0));
} // draw image
TiXmlNode* node3;
TiXmlNode* node4;
if (node3 = node2->FirstChild("adjustimg"))
{
// RETAILMSG(DllGUI_DEBUG, (L"DllGUI: draw image......\r\n"));
if (node4 = node3->FirstChild("img"))
{
do
{
// image name
todoElement = node4->ToElement();
todoElement->QueryValueAttribute("src", &temp);
strPicName = strChange.doChange(temp).c_str(); // rect info
todoElement->QueryValueAttribute("size", &temp);
strTemp = strChange.doChange(temp).c_str();
AfxExtractSubString(str1, strTemp, 0, ',');
AfxExtractSubString(str2, strTemp, 1, ',');
AfxExtractSubString(str3, strTemp, 2, ',');
AfxExtractSubString(str4, strTemp, 3, ','); xpos = _ttoi(str1);
ypos = _ttoi(str2);
width = _ttoi(str3);
height = _ttoi(str4);
UIDrawPic(strTemp, xpos, ypos, width, height); } while (node4 = node4->NextSibling("img"));
}
}
// end of adjustimg // create static text
WORD fontsize, fontType, limitLen;
if (node3 = node2->FirstChild("adjuststatic"))
{
// RETAILMSG(DllGUI_DEBUG, (L"DllGUI: draw static text......\r\n"));
if (node4 = node3->FirstChild("static"))
{
do
{
// static text
todoElement = node4->ToElement();
todoElement->QueryValueAttribute("name", &temp);
theApp.stc.strStatic = strChange.doChange(temp).c_str(); // font info
todoElement->QueryValueAttribute("fontSize", &fontsize);
todoElement->QueryValueAttribute("fontType", &fontType);
todoElement->QueryValueAttribute("limitLen", &limitLen);
theApp.stc.fontsize = fontsize;
theApp.stc.fontType = fontType;
theApp.stc.limitLen = limitLen; // rect info
todoElement->QueryValueAttribute("CRect", &temp);
strTemp = strChange.doChange(temp).c_str();
AfxExtractSubString(str1, strTemp, 0, ',');
AfxExtractSubString(str2, strTemp, 1, ',');
AfxExtractSubString(str3, strTemp, 2, ',');
AfxExtractSubString(str4, strTemp, 3, ',');
theApp.stc.i_left = _ttoi(str1);
theApp.stc.i_top = _ttoi(str2);
theApp.stc.i_right = _ttoi(str3);
theApp.stc.i_bottom = _ttoi(str4); // color info
int cor1, cor2, cor3;
todoElement->QueryValueAttribute("color", &temp);
strTemp = strChange.doChange(temp).c_str(); cor1 = cor2 = cor3 = 0;
_stscanf((LPCTSTR)strTemp, L"RGB(%d,%d,%d)", &cor1, &cor2, &cor3);
theApp.stc.cRed = cor1;
theApp.stc.cGreen = cor2;
theApp.stc.cBlue = cor3;
//RETAILMSG(DllGUI_DEBUG, (L"DllGUI: static color = RGB(%d,%d,%d)\r\n", cor1, cor2, cor3));
UISetDCFont(fontsize, fontType);
UIDrawString(theApp.stc.strStatic, CRect(theApp.stc.i_left, theApp.stc.i_top, theApp.stc.i_right, theApp.stc.i_bottom),
RGB(cor1, cor2, cor3), limitLen, fontsize+1, 2, DT_LEFT);
} while (node4 = node4->NextSibling("static"));
}
}
// end of adjuststatic // create edits
if (node3 = node2->FirstChild("adjustedit"))
{
// RETAILMSG(DllGUI_DEBUG, (L"DllGUI: creating edit......\r\n"));
if (node4 = node3->FirstChild("edit"))
{
do
{
// edit内容和样式
CString strStr, strStyle;
DWORD style = 0;
todoElement=node4->ToElement();
std::string value;
todoElement->QueryValueAttribute("limit", &limitLen);
todoElement->QueryValueAttribute("fontsize", &fontsize);
todoElement->QueryValueAttribute("str", &value);
strStr = strChange.doChange(value).c_str();
todoElement->QueryValueAttribute("x", &xpos);
todoElement->QueryValueAttribute("y", &ypos);
todoElement->QueryValueAttribute("width", &width);
todoElement->QueryValueAttribute("height", &height);
todoElement->QueryValueAttribute("style", &temp);
strStyle = strChange.doChange(temp).c_str();
if(strStyle == L"password")
{
style |= ES_PASSWORD;
} UICreateEdit(limitLen, fontsize, strStr, style, xpos, ypos, width, height);
}while (node4 = node4->NextSibling("edit"));
}
UIEditSetFocus();
}
//end of adjustedit
break;
}while (node2 = node2->NextSibling("dlg"));
}
dcex->InvalidateEx(0);
time2 = GetTickCount();
RETAILMSG(DllGUI_DEBUG, (L"\r\n DllGUI: load XML in %d milliseconds \r\n", time2-time1));根据对话框的id号加载相应的xml界面配置, DllGUI: load XML in 472 milliseconds ,加载时间过长
我是在xml里循环遍历<dlg id="8000">属性,真到找到了相应的id号,tinyxml有没专门查找某一id号的功能?
如何加快xml的加载速度,我是dll初始化的时候doc.LoadFile(xmlFile),然后该文件一直打开没有关闭,还是很慢.
大家有没好的建议?
EXPORTC void UITestXML(int i_dlg)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState()); DWORD time1, time2;
time1 = GetTickCount();
CharsChange strChange;
TiXmlNode* node1 = 0;
TiXmlNode* node2 = 0;
TiXmlNode* childNode2 = NULL;
TiXmlElement* todoElement = 0; // 资源清理
UIDeleteEdits();
theApp.v_edit.clear();
theApp.v_menu.clear();
SetFocus(theApp.gHwnd);
theApp.sc_dlg.push(i_dlg);
node1 = theApp.doc.FirstChild("system");
if (!node1)
return;
if (node2 = node1->FirstChild("dlg"))
{
CString strTemp;
std::string temp;
CString strPicName;
CString str1, str2, str3, str4;
int xpos, ypos, width, height;
do
{
todoElement = node2->ToElement();
todoElement->QueryValueAttribute("id", &temp);
strTemp = strChange.doChange(temp).c_str();
if (_ttoi(strTemp) != i_dlg)
{
continue;
}
//RETAILMSG(DllGUI_DEBUG, (L"DllGUI: cur dlg = %d\r\n", i_dlg));
// dialog matched, setting back image
childNode2 = node2->FirstChild("backfile");
strTemp = strChange.doChange(childNode2->ToElement()->GetText()).c_str();
theApp.strBkImg = strTemp; if(strTemp.Compare(L"black.bmp") != 0)
{
UISetBkImg(strTemp, 1);
}
else
{
//dcex->SetBkImg2();
UIFillSolidRect(NULL, RGB(0, 0, 0));
} // draw image
TiXmlNode* node3;
TiXmlNode* node4;
if (node3 = node2->FirstChild("adjustimg"))
{
// RETAILMSG(DllGUI_DEBUG, (L"DllGUI: draw image......\r\n"));
if (node4 = node3->FirstChild("img"))
{
do
{
// image name
todoElement = node4->ToElement();
todoElement->QueryValueAttribute("src", &temp);
strPicName = strChange.doChange(temp).c_str(); // rect info
todoElement->QueryValueAttribute("size", &temp);
strTemp = strChange.doChange(temp).c_str();
AfxExtractSubString(str1, strTemp, 0, ',');
AfxExtractSubString(str2, strTemp, 1, ',');
AfxExtractSubString(str3, strTemp, 2, ',');
AfxExtractSubString(str4, strTemp, 3, ','); xpos = _ttoi(str1);
ypos = _ttoi(str2);
width = _ttoi(str3);
height = _ttoi(str4);
UIDrawPic(strTemp, xpos, ypos, width, height); } while (node4 = node4->NextSibling("img"));
}
}
// end of adjustimg // create static text
WORD fontsize, fontType, limitLen;
if (node3 = node2->FirstChild("adjuststatic"))
{
// RETAILMSG(DllGUI_DEBUG, (L"DllGUI: draw static text......\r\n"));
if (node4 = node3->FirstChild("static"))
{
do
{
// static text
todoElement = node4->ToElement();
todoElement->QueryValueAttribute("name", &temp);
theApp.stc.strStatic = strChange.doChange(temp).c_str(); // font info
todoElement->QueryValueAttribute("fontSize", &fontsize);
todoElement->QueryValueAttribute("fontType", &fontType);
todoElement->QueryValueAttribute("limitLen", &limitLen);
theApp.stc.fontsize = fontsize;
theApp.stc.fontType = fontType;
theApp.stc.limitLen = limitLen; // rect info
todoElement->QueryValueAttribute("CRect", &temp);
strTemp = strChange.doChange(temp).c_str();
AfxExtractSubString(str1, strTemp, 0, ',');
AfxExtractSubString(str2, strTemp, 1, ',');
AfxExtractSubString(str3, strTemp, 2, ',');
AfxExtractSubString(str4, strTemp, 3, ',');
theApp.stc.i_left = _ttoi(str1);
theApp.stc.i_top = _ttoi(str2);
theApp.stc.i_right = _ttoi(str3);
theApp.stc.i_bottom = _ttoi(str4); // color info
int cor1, cor2, cor3;
todoElement->QueryValueAttribute("color", &temp);
strTemp = strChange.doChange(temp).c_str(); cor1 = cor2 = cor3 = 0;
_stscanf((LPCTSTR)strTemp, L"RGB(%d,%d,%d)", &cor1, &cor2, &cor3);
theApp.stc.cRed = cor1;
theApp.stc.cGreen = cor2;
theApp.stc.cBlue = cor3;
//RETAILMSG(DllGUI_DEBUG, (L"DllGUI: static color = RGB(%d,%d,%d)\r\n", cor1, cor2, cor3));
UISetDCFont(fontsize, fontType);
UIDrawString(theApp.stc.strStatic, CRect(theApp.stc.i_left, theApp.stc.i_top, theApp.stc.i_right, theApp.stc.i_bottom),
RGB(cor1, cor2, cor3), limitLen, fontsize+1, 2, DT_LEFT);
} while (node4 = node4->NextSibling("static"));
}
}
// end of adjuststatic // create edits
if (node3 = node2->FirstChild("adjustedit"))
{
// RETAILMSG(DllGUI_DEBUG, (L"DllGUI: creating edit......\r\n"));
if (node4 = node3->FirstChild("edit"))
{
do
{
// edit内容和样式
CString strStr, strStyle;
DWORD style = 0;
todoElement=node4->ToElement();
std::string value;
todoElement->QueryValueAttribute("limit", &limitLen);
todoElement->QueryValueAttribute("fontsize", &fontsize);
todoElement->QueryValueAttribute("str", &value);
strStr = strChange.doChange(value).c_str();
todoElement->QueryValueAttribute("x", &xpos);
todoElement->QueryValueAttribute("y", &ypos);
todoElement->QueryValueAttribute("width", &width);
todoElement->QueryValueAttribute("height", &height);
todoElement->QueryValueAttribute("style", &temp);
strStyle = strChange.doChange(temp).c_str();
if(strStyle == L"password")
{
style |= ES_PASSWORD;
} UICreateEdit(limitLen, fontsize, strStr, style, xpos, ypos, width, height);
}while (node4 = node4->NextSibling("edit"));
}
UIEditSetFocus();
}
//end of adjustedit
break;
}while (node2 = node2->NextSibling("dlg"));
}
dcex->InvalidateEx(0);
time2 = GetTickCount();
RETAILMSG(DllGUI_DEBUG, (L"\r\n DllGUI: load XML in %d milliseconds \r\n", time2-time1));根据对话框的id号加载相应的xml界面配置, DllGUI: load XML in 472 milliseconds ,加载时间过长
我是在xml里循环遍历<dlg id="8000">属性,真到找到了相应的id号,tinyxml有没专门查找某一id号的功能?
如何加快xml的加载速度,我是dll初始化的时候doc.LoadFile(xmlFile),然后该文件一直打开没有关闭,还是很慢.
大家有没好的建议?
<?xml version="1.0" encoding="gb2312"?>
<system>
<dlg id="1000">
<backfile>black.bmp</backfile>
<adjuststatic>
<static name ="欢迎使用" fontSize="30" fontType="1" limitLen="10" CRect="70,50,240,320" color="RGB(255,0,0)"/>
</adjuststatic>
</dlg> <dlg id="2000">
<backfile>\ResidentFlash\图\背景\开机密码.bmp</backfile>
<adjustedit>
<edit limit="8" fontsize="30" str="" x="20" y="212" width="190" height="32" style="password"/>
</adjustedit>
</dlg> <dlg id="8000">
<backfile>\ResidentFlash\图\硬件检测\硬件检测_空白.bmp</backfile>
<adjuststatic>
<static name="按<上><下><确认>操作或<取消>返回" fontSize="11" fontType="1" limitLen="20" CRect="10,285,240,320" color="RGB(2,112,2)"/>
</adjuststatic>
<adjustmenu pos="10,70" pagesize="6" itemSize="220,35" font="18" >
<img src="\ResidentFlash\图\常用提示\选中绿条.bmp" width="180" height="30" />
<menu name="01.连续测试" dlg="8001" />
<menu name="02.适配器及电池电压测试" dlg="8002" />
<menu name="03.触摸屏测试" dlg="8003" />
<menu name="04.手写板测试" dlg="8004" />
<menu name="05.彩色显示屏测试" dlg="8005" />
<menu name="06.音频测试" dlg="8006" />
<menu name="07.SD卡测试" dlg="8007" />
<menu name="08.键盘测试" dlg="8008" />
<menu name="09.无线Modem测试" dlg="8009" />
<menu name="10.打印机测试" dlg="8010" />
<menu name="11.PSAM卡测试" dlg="8011" />
<menu name="12.空卡测试" dlg="8012" />
<menu name="13.RTC测试" dlg="8013" />
<menu name="14.烤机测试" dlg="8014" />
<menu name="15.本地升级" dlg="8015" />
<menu name="16.系统版本号" dlg="8016" />
</adjustmenu>
</dlg> <dlg id="101">
<fontname size="20">宋体</fontname>
<backfile>\ResidentFlash\图\硬件检测\硬件检测_空白.bmp</backfile>
<adjuststatic>
<static name="按<取消>退出" CRect="10,270,240,320" color="RGB(2,112,2)"/>
</adjuststatic>
<adjustedit>
</adjustedit>
<adjustmenu pos="18,30" pagesize="6" itemSize="230,25" >
<!--itemSize:输出的每个菜单的大小-->
<img src="\ResidentFlash\图\常用提示\选中绿条3.bmp" size="30,80,0,0" />
<menu name="01.进度条测试" dlg="201" more="这是连续测试的说明" color="RGB(0,0,0)"/>
<menu name="02.编辑框测试" dlg="202" more="这是的说明" color="RGB(0,0,0)"/>
<menu name="03.其他测试" dlg="999" more="这是的说明" color="RGB(0,0,0)"/>
</adjustmenu>
</dlg> <dlg id="102">
<fontname size="21">宋体</fontname>
<backfile>\ResidentFlash\图\硬件检测\硬件检测_空白.bmp</backfile>
<adjuststatic>
<static name="按取消键退出2" CRect="70,150,230,450" color="RGB(2,112,2)"/>
</adjuststatic>
<adjustedit>
</adjustedit>
</dlg> <dlg id="103">
<fontname size="21">宋体</fontname>
<backfile>\ResidentFlash\图\硬件检测\硬件检测_空白.bmp</backfile>
<adjuststatic>
<static name="校准模式,请点击屏幕上的十字中心位置" CRect="30,10,230,100" color="RGB(2,112,2)"/>
<static name="按<取消>退出" CRect="70,150,230,450" color="RGB(2,112,2)"/>
</adjuststatic>
<adjustedit>
</adjustedit>
</dlg> <dlg id="999">
<fontname size="20">宋体</fontname>
<backfile>\ResidentFlash\图\硬件检测\硬件检测_空白.bmp</backfile>
<adjuststatic>
<static name="本功能暂不开放" CRect="10,50,240,75" color="RGB(2,112,2)"/>
<static name="按<取消>退出" CRect="10,290,240,320" color="RGB(2,112,2)"/>
</adjuststatic>
</dlg></system>