void CTreeListFrame::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { CRect m_treeRect; getTree().GetClientRect(&m_treeRect); if(pScrollBar == &m_horScrollBar) { int m_nCurPos = m_horScrollBar.GetScrollPos(); int m_nPrevPos = m_nCurPos; switch(nSBCode) { case SB_LEFT: m_nCurPos = 0; break; case SB_RIGHT: m_nCurPos = m_horScrollBar.GetScrollLimit()-1; break; case SB_LINELEFT: m_nCurPos = max(m_nCurPos-6, 0); break; case SB_LINERIGHT: m_nCurPos = min(m_nCurPos+6, m_horScrollBar.GetScrollLimit()-1); break; case SB_PAGELEFT: m_nCurPos = max(m_nCurPos-m_treeRect.Width(), 0); break; case SB_PAGERIGHT: m_nCurPos = min(m_nCurPos+m_treeRect.Width(), m_horScrollBar.GetScrollLimit()-1); break; case SB_THUMBTRACK: case SB_THUMBPOSITION: if(nPos==0) m_nCurPos = 0; else m_nCurPos = min(StretchWidth(nPos, 6), m_horScrollBar.GetScrollLimit()-1); break; } // 6 is Microsoft's step in a CListCtrl for example m_horScrollBar.SetScrollPos(m_nCurPos); getTree().m_nOffset = -m_nCurPos; // smoothly scroll the tree control { CRect m_scrollRect; getTree().GetClientRect(&m_scrollRect); getTree().ScrollWindow(m_nPrevPos - m_nCurPos, 0, &m_scrollRect, &m_scrollRect); } CRect m_headerRect; getTree().m_wndHeader.GetWindowRect(&m_headerRect); CRect m_wndRect; GetClientRect(&m_wndRect); getTree().m_wndHeader.SetWindowPos(&wndTop, getTree().m_nOffset, 0, max(StretchWidth(getTree().GetColumnsWidth(),m_treeRect.Width()),m_wndRect.Width()), m_headerRect.Height(), SWP_SHOWWINDOW); } CWnd::OnHScroll(nSBCode, nPos, pScrollBar); }
void CTreeListFrame::ResetScrollBar() { // resetting the horizontal scroll bar int m_nTotalWidth=0, m_nPageWidth; CRect m_treeRect; getTree().GetClientRect(&m_treeRect); CRect m_wndRect; GetClientRect(&m_wndRect); CRect m_headerRect; getTree().m_wndHeader.GetClientRect(&m_headerRect); CRect m_barRect; m_horScrollBar.GetClientRect(m_barRect); m_nPageWidth = m_treeRect.Width(); m_nTotalWidth = getTree().GetColumnsWidth(); if(m_nTotalWidth > m_nPageWidth) { // show the scroll bar and adjust it's size { m_horScrollBar.EnableWindow(TRUE); m_horScrollBar.ShowWindow(SW_SHOW); // the tree becomes smaller getTree().SetWindowPos(&wndTop, 0, 0, m_wndRect.Width(), m_wndRect.Height()-m_barRect.Height()-m_headerRect.Height(), SWP_NOMOVE); if(!VerticalScrollVisible()) // i.e. vertical scroll bar isn't visible { m_horScrollBar.SetWindowPos(&wndTop, 0, 0, m_wndRect.Width(), m_barRect.Height(), SWP_NOMOVE); } else { m_horScrollBar.SetWindowPos(&wndTop, 0, 0, m_wndRect.Width() - GetSystemMetrics(SM_CXVSCROLL), m_barRect.Height(), SWP_NOMOVE); } } m_horScrollBar.SetScrollRange(0, m_nTotalWidth-m_nPageWidth); // recalculate the offset { CRect m_wndHeaderRect; getTree().m_wndHeader.GetWindowRect(&m_wndHeaderRect); ScreenToClient(&m_wndHeaderRect); getTree().m_nOffset = m_wndHeaderRect.left; m_horScrollBar.SetScrollPos(-getTree().m_nOffset); } } else { m_horScrollBar.EnableWindow(FALSE); // we no longer need it, so hide it! { m_horScrollBar.ShowWindow(SW_HIDE); getTree().SetWindowPos(&wndTop, 0, 0, m_wndRect.Width(), m_wndRect.Height() - m_headerRect.Height(), SWP_NOMOVE); // the tree takes scroll's place } m_horScrollBar.SetScrollRange(0, 0); // set scroll offset to zero { getTree().m_nOffset = 0; getTree().Invalidate(); CRect m_headerRect; getTree().m_wndHeader.GetWindowRect(&m_headerRect); CRect m_wndRect; GetClientRect(&m_wndRect); getTree().m_wndHeader.SetWindowPos(&wndTop, getTree().m_nOffset, 0, max(StretchWidth(getTree().GetColumnsWidth(),m_wndRect.Width()),m_wndRect.Width()), m_headerRect.Height(), SWP_SHOWWINDOW); } } }
void CTLFrame::ResetScrollBar() { // resetting the horizontal scroll bar int m_nTotalWidth=0, m_nPageWidth; CRect m_treeRect; m_tree.GetClientRect(&m_treeRect); CRect m_wndRect; GetClientRect(&m_wndRect); CRect m_headerRect; m_tree.m_wndHeader.GetClientRect(&m_headerRect); CRect m_barRect; m_horScrollBar.GetClientRect(m_barRect); m_nPageWidth = m_treeRect.Width(); m_nTotalWidth = m_tree.GetColumnsWidth(); if(m_nTotalWidth > m_nPageWidth) { // show the scroll bar and adjust it's size { m_horScrollBar.EnableWindow(TRUE); m_horScrollBar.ShowWindow(SW_SHOW); // the tree becomes smaller CRect TreeRect; m_tree.GetWindowRect(&TreeRect); if(TreeRect.Width() != m_wndRect.Width() || TreeRect.Height() != m_wndRect.Height()-m_barRect.Height()-m_headerRect.Height()) m_tree.SetWindowPos(&wndTop, 0, 0, m_wndRect.Width(), m_wndRect.Height()-m_barRect.Height()-m_headerRect.Height(), SWP_NOMOVE); CRect ScrollRect; m_horScrollBar.GetWindowRect(&ScrollRect); if(!VerticalScrollVisible()) // i.e. vertical scroll bar isn't visible { m_horScrollBar.SetWindowPos(&wndTop, 0, 0, m_wndRect.Width(), m_barRect.Height(), SWP_NOMOVE); } else { m_horScrollBar.SetWindowPos(&wndTop, 0, 0, m_wndRect.Width() - GetSystemMetrics(SM_CXVSCROLL), m_barRect.Height(), SWP_NOMOVE); } } SCROLLINFO si; si.fMask = SIF_PAGE | SIF_RANGE; si.nPage = m_treeRect.Width(); si.nMin = 0; si.nMax = m_nTotalWidth; m_horScrollBar.SetScrollInfo(&si, FALSE); // recalculate the offset { CRect m_wndHeaderRect; m_tree.m_wndHeader.GetWindowRect(&m_wndHeaderRect); ScreenToClient(&m_wndHeaderRect); m_tree.m_nOffset = m_wndHeaderRect.left; m_horScrollBar.SetScrollPos(-m_tree.m_nOffset); } } else { m_horScrollBar.EnableWindow(FALSE); // we no longer need it, so hide it! { m_horScrollBar.ShowWindow(SW_HIDE); // the tree takes scroll's place CRect TreeRect; m_tree.GetClientRect(&TreeRect); m_tree.SetWindowPos(&wndTop, 0, 0, m_wndRect.Width(), m_wndRect.Height() - m_headerRect.Height(), SWP_NOMOVE); } m_horScrollBar.SetScrollRange(0, 0); // set scroll offset to zero { m_tree.m_nOffset = 0; m_tree.Invalidate(); CRect m_headerRect; m_tree.m_wndHeader.GetWindowRect(&m_headerRect); CRect m_wndRect; GetClientRect(&m_wndRect); m_tree.m_wndHeader.SetWindowPos(&wndTop, m_tree.m_nOffset, 0, max(StretchWidth(m_tree.GetColumnsWidth(),m_wndRect.Width()),m_wndRect.Width()), m_headerRect.Height(), SWP_SHOWWINDOW); } } }