需要为选项卡控件做一个工作,我想保存然后恢复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);
}