1

I know that the function EnsureVisible(HTREEITEM hItem) can show hItem by scrolling the bar of the CTreeCtrl control. But sometimes the hItem is displayed either beside the top or beside the bottom of the control, which is so unfriendly for users. I want the item to be shown in the middle of the control. Any good solutions?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
hsluoyz
  • 2,739
  • 5
  • 35
  • 59

1 Answers1

4

You would have to scroll the CTreeCtrl manually. Call CTreeCtrl::EnsureVisible() to make the item visible, then call CTreeCtrl::GetItemRect() to retrieve the item's current coordinates, and then call CWnd::ScrollWindow/Ex() specifying the necessary offset to put the item wherever you want it.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Very good solution, except the last function, ScrollWindows, I didn't know how to use it to scroll a window, at last I used ::SendMessage(m_hWnd, WM_VSCROLL, SB_LINEUP, 0); – hsluoyz Mar 10 '14 at 08:00