void TreeDlg::OnButtonExpandAll() { CTreeCtrl *ctrl = getTreeCtrl(); int hp = ctrl->GetScrollPos(SB_HORZ); int vp = ctrl->GetScrollPos(SB_VERT); TreeItemExpander(true).visitAllItems(ctrl); ctrl->SetFocus(); ctrl->SetScrollPos(SB_HORZ, hp); ctrl->SetScrollPos(SB_VERT, vp); }