0

Give the need to do a work around for a tab control, I want to save then restore the CEditView contents. What I do is shown below, and while the scrollbars and position go back to where they were properly, the actual contents of the edit control don't scroll (it is in the upper left like it has never been scrolled). I tried RedrawWindow(), didn't work. I've been mainly dealing with the horizontal scrollbar, f I just simply click on the horizontal bar the contents jumps to where it should have been.

What am I missing or what is the trick to make it work?

TIA!!

  // 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);
  }
user3161924
  • 1,849
  • 18
  • 33
  • I see there is `EM_LINELENGTH` and I see `EM_GETFIRSTVISIBLELINE` but I don't see where I could get the horizontal position (other than maybe having to do some type of math based on the horizontal scrollbar). – user3161924 Jul 19 '21 at 00:59

1 Answers1

0

Finally got something that worked:

      // 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);
      }
user3161924
  • 1,849
  • 18
  • 33