0

需要为选项卡控件做一个工作,我想保存然后恢复CEditView内容。我所做的如下所示,当滚动条和位置回到正确的位置时,编辑控件的实际内容不会滚动(它在左上角,就像它从未滚动过一样)。我试过RedrawWindow()了,没有用。我一直主要处理水平滚动条,我只需单击水平条,内容就会跳转到它应该在的位置。

我错过了什么或者让它发挥作用的诀窍是什么?

蒂亚!!

  // hack to work around ceditview getting its window contents changed
  CView* pview=GetView(tabi);
  if (pview->IsKindOf(RUNTIME_CLASS(CEditView))) {
    CEditView* peditview=reinterpret_cast<CEditView*>(pview);
    CEdit& editctrl=peditview->GetEditCtrl();
    int startchar, endchar;
    editctrl.GetSel(startchar, endchar);
    int nhorzpos=peditview->GetScrollPos(SB_HORZ);
    int nvertpos=peditview->GetScrollPos(SB_VERT);
    CString strexistingtext;
    pview->GetWindowText(strexistingtext);
    // change label
    tabctrl.SetTabLabel(tabi, strlabel);
    // put back text
    pview->SetWindowText(strexistingtext);
    // put back where we were
    peditview->SetScrollPos(SB_VERT, nvertpos);
    peditview->SetScrollPos(SB_HORZ, nhorzpos);
    editctrl.SetSel(startchar, endchar, TRUE);
  }
  else {
    // change label
    tabctrl.SetTabLabel(tabi, strlabel);
  }
4

1 回答 1

0

终于得到了一些有用的东西:

      // hack to work around ceditview getting its window contents changed
      CView* pview=GetView(tabi);
      if (pview->IsKindOf(RUNTIME_CLASS(CEditView))) {
        CEditView* peditview=reinterpret_cast<CEditView*>(pview);
        CEdit& editctrl=peditview->GetEditCtrl();
        int startchar, endchar;
        editctrl.GetSel(startchar, endchar);
        int topline=editctrl.GetFirstVisibleLine();
        int nhorzpos=peditview->GetScrollPos(SB_HORZ);
        CString strexistingtext;
        pview->GetWindowText(strexistingtext);
        // change label
        tabctrl.SetTabLabel(tabi, strlabel);
        // put back text
        pview->SetWindowText(strexistingtext);
        // put back where we were
        editctrl.SetSel(startchar, endchar, TRUE);
        peditview->SetScrollPos(SB_HORZ, nhorzpos); // prevents ficker
        editctrl.SendMessage(WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION, nhorzpos), NULL);
        editctrl.SendMessage(WM_HSCROLL, MAKEWPARAM(SB_ENDSCROLL, 0), NULL);
        editctrl.LineScroll(topline,0);
      }
      else {
        // change label
        tabctrl.SetTabLabel(tabi, strlabel);
      }
于 2021-07-19T06:12:51.557 回答