【问题标题】:Why CListCtrl Update() not necessary in the example below?为什么在下面的示例中不需要 CListCtrl Update()?
【发布时间】:2016-05-04 18:20:54
【问题描述】:

在下面的代码中,如果我在 first“If”条件之后不使用“Update()”,ListCtrl 将更新项目,但 将即使在第二个“If”条件之后没有调用“Update()”方法,也要更新。为什么是这样?我只是想知道何时需要 Update() 何时不需要!

   class MyDialog()
   {
    public:
         void MyFunction();
    private:
      CListCtrl myListControl;
   }

   void MyDialog::Myfunction()
   {
       bool bCondition;
       for (auto i = 0, i < myListControl.GetItemCount(); ++i)
       {
         auto n  = myListControl.SetItemText(i, 1, "Start");
         if (n)
           myListControl.Update(i);
         /*Update() is required here */

         EvaluateCondition( bConditon);

         if(bConditon)
            myListControl.SetItemText(i, 1, "End");
         /* Why is Update() ***Not*** required here? */
       }
 }

【问题讨论】:

    标签: c++ mfc clistctrl


    【解决方案1】:

    Update 使更改立即显示在屏幕上。如果您不调用它,Windows 会在您的消息循环下一次运行时(在您的 MyFunction 退出后)自动将更改放在屏幕上。这就是为什么您需要在将其更改为“结束”之前调用它以查看“开始”。当您的函数退出时,Windows 会自动将其更新为“结束”。

    【讨论】:

      【解决方案2】:

      如果X 是假的,你怎么回答Why X is true? 的问题???

      当您设置某些项目的文本时 - 列表控件使相应区域无效;最终,当涉及到绘画时 - 它会重新绘制新文本。

      根据MSDN (CListCtrl::Update)

      强制列表视图控件重新绘制由 nItem 指定的项目。

      所以你可以立即看到结果。

      【讨论】:

        猜你喜欢
        • 2014-06-19
        • 2017-12-21
        • 1970-01-01
        • 2020-05-03
        • 2017-06-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多