CMFCPropertyGridCtrl添加文本
CMFCPropertyGridCtrl Adding text
在CMFCPropertyGridCtrl中插入文本时遇到问题。基本上,我用以下代码插入值:
void GridBuilder::buildGrid() {
int cycles = 0, buisnessRules = 0;
for(vector<cycle *>::iterator it = this->listCycle.begin(); it!= this->listCycle.end(); ++it) {
buisnessRules = 0;
cycles++;
if(!this->mFilter->assertCycleConstraints((*it)->idthread, (*it)->dataStart, (*it)->dateStop, (*it)->name.c_str(), cycles)) {
continue;
}
CString text;
text.Format(_T("cycle : %S"), (*it)->name.c_str());
CMFCPropertyGridProperty* parent = new CMFCPropertyGridProperty(text);
mGrid->AddProperty(parent);
time_t timestampBegin = (*it)->dataStart / 1000;
char bufferBegin[256];
strftime(bufferBegin, sizeof(bufferBegin), "%A %d %B %Y - %X", localtime(×tampBegin));
time_t timestampEnd = (*it)->dateStop / 1000;
char bufferEnd[256];
strftime(bufferEnd, sizeof(bufferEnd), "%A %d %B %Y - %X", localtime(×tampBegin));
text.Format(_T("%d"), (*it)->idthread); parent->AddSubItem(new CMFCPropertyGridProperty(_T("Thread Id"), text));
text.Format(_T("%S"), (*it)->name.c_str()); parent->AddSubItem(new CMFCPropertyGridProperty(_T("Name"), text));
text.Format(_T("%S:%d"), bufferBegin, (*it)->dataStart % 1000); parent->AddSubItem(new CMFCPropertyGridProperty(_T("DateStart"), text));
text.Format(_T("%S:%d"), bufferEnd, (*it)->dateStop % 1000); parent->AddSubItem(new CMFCPropertyGridProperty(_T("DateStop"), text));
parent->Expand(FALSE);
for(vector<br *>::iterator itBr = (*it)->listBr.begin(); itBr!=(*it)->listBr.end(); ++itBr) {
buisnessRules++;
if(!this->mFilter->assertBuisnessRuleConstraints((*itBr)->dateStart, (*itBr)->dateStop, (*itBr)->name.c_str(), buisnessRules)) {
continue;
}
UINT64 executionTime = (*itBr)->dateStop - (*itBr)->dateStart;
CString text;
text.Format(_T("%S (%d u00B5s)"), (*itBr)->name.c_str(), executionTime);
CMFCPropertyGridProperty* buisnessRule = new CMFCPropertyGridProperty(text);
parent->AddSubItem(buisnessRule);
text.Format(_T("%S"), (*itBr)->name.c_str()); buisnessRule->AddSubItem(new CMFCPropertyGridProperty(_T("Name"), text));
text.Format(_T("%d u00B5s"), executionTime); buisnessRule->AddSubItem(new CMFCPropertyGridProperty(_T("Execution time"), text));
buisnessRule->Expand(FALSE);
}
}
}
这工作得很好,并显示了我想要的一切。然而,我的向量通常非常大(超过8000个元素),这需要大量时间来渲染。。。
我怀疑每次插入新元素时CMFCPropertyGridCtrl都会重新绘制整个树,这需要相当长的时间。。。
我的问题如下:如何在CMFCPropertyGridCtrl中添加文本而不重新绘制整个树?或者如何优化此代码?谢谢
我就是这样做的:
在开始向网格中添加项目之前,请调用LockWindowUpdate
(此处从CWnd
-MSDN继承),然后在完成时调用UnlockWindowUpdate
(此处为MSDN)和Invalidate
m_Grid->LockWindowUpdate();
// ... populate grid
m_Grid->UnlockWindowUpdate();
m_Grid->Invalidate();
相关文章:
- 从文本文件在组合框中添加项目
- 定义宏以将前缀 0x 添加到十六进制字符串文本
- 如何调用继承的重载运算符<<并在派生类的输出中添加更多文本?
- 如何从 c++ winrt UWP 应用中的代码将文本添加到富文本块
- c++ 添加具有写入文件错误的文本变量
- 在 MFC 组合框中设置文本,而不将其添加到列表中
- 将时间戳添加到文本文件中的空行中
- 将文本添加到鼠标位置时,请单击“给出分割故障”
- 如何在C++的文本变量中添加变量值
- 如何使用键盘输入和sf ::文本在SFML中添加一种文本框以显示文本字符串
- 将文本注释添加到exe文件mingw
- 使用FreeImage向图像添加文本
- 将文本添加到另一个程序文本框 C++
- 问答游戏/单击按钮将文本添加到标签
- 如何将文本添加到QTextEdit的顶部
- 从数据库检索后,将其他文本添加到组合框中
- 如何在Qt中使用线程将文本添加到文本编辑器中
- 使用QPushButton将文本添加到QTextEdit
- 为什么将文本添加到 RichEdit 窗口会冻结它
- C++将字符串文本添加到字符文本