CMFCPropertyGridCtrl添加文本

时间:2013-07-05 13:32:43

标签: c++ mfc

我在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(&timestampBegin));

        time_t timestampEnd = (*it)->dateStop / 1000;
        char bufferEnd[256];
        strftime(bufferEnd, sizeof(bufferEnd), "%A %d %B %Y - %X", localtime(&timestampBegin));

        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);
        }

    }
}

这很好用,可以显示我想要的所有内容。 但是,我的向量通常非常大(超过8 000个元素),这需要花费大量时间来渲染......

我怀疑CMFCPropertyGridCtrl每次插入一个需要很长时间的新元素时都会重绘整个树...


我的问题如下: 如何在不重绘整个树的情况下在CMFCPropertyGridCtrl中添加文本? 或者我如何优化此代码? 谢谢 !

1 个答案:

答案 0 :(得分:0)

我就是这样做的:

在开始向网格添加项目之前,请致电LockWindowUpdate(继承自CWnd - MSDN here),然后致电UnlockWindowUpdateMSDN here)和{ {1}}完成后

Invalidate
相关问题