CHtmlView & ScrollBar
-
Hello, In MDI project, i work with CHtmlView and i want to add scrollbar to my childs windows. so i do :
BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs) { cs.style = WS_VSCROLL | WS_HSCROLL |WS_OVERLAPPEDWINDOW; m_HScroll.Create(SBS_BOTTOMALIGN ,CRect(0,0,0,0),this,ID_HSCROLL); } int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { m_HScroll.SetScrollRange(0,50,TRUE); m_HScroll.SetScrollPos(0,TRUE); }
When the prorgram start, i have scrollbars in my child window, greats ! I can detect :
void CChildFrame::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) void CChildFrame::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
but when i do a
m_HScroll.SetScrollPos(10,TRUE);
the ScrollBar don't move it is always in the left. the user can use the scrollbar (it always stay in left position), i can detect when the user click on it and i can move my view, but i can't move my scrollbar. if i dom_HScroll.SetScrollPos(10,TRUE);
andint toto = m_HScroll.GetScrollPos()
toto == 10
! but "at the screen" the scrollbar stay in the left. Have you any idea ? PS: excuse for bad english -
Hello, In MDI project, i work with CHtmlView and i want to add scrollbar to my childs windows. so i do :
BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs) { cs.style = WS_VSCROLL | WS_HSCROLL |WS_OVERLAPPEDWINDOW; m_HScroll.Create(SBS_BOTTOMALIGN ,CRect(0,0,0,0),this,ID_HSCROLL); } int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { m_HScroll.SetScrollRange(0,50,TRUE); m_HScroll.SetScrollPos(0,TRUE); }
When the prorgram start, i have scrollbars in my child window, greats ! I can detect :
void CChildFrame::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) void CChildFrame::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
but when i do a
m_HScroll.SetScrollPos(10,TRUE);
the ScrollBar don't move it is always in the left. the user can use the scrollbar (it always stay in left position), i can detect when the user click on it and i can move my view, but i can't move my scrollbar. if i dom_HScroll.SetScrollPos(10,TRUE);
andint toto = m_HScroll.GetScrollPos()
toto == 10
! but "at the screen" the scrollbar stay in the left. Have you any idea ? PS: excuse for bad englishI think the problem is that
m_hScroll
isn't actually the scroll-bar that you see in the window. When you set the style (cs.style
() in PreCreateWindow toWS_VSCROLL | WS_HSCROLL
the window creates its own scrollbars, and you need to use the member functions of CWnd to access them. For example, to get and set the position of the horizontal scroll-barvoid CChildFrame::some_function(int sb_pos)
{
//Setting the horizontal scroll position
SetScrollPos(SB_HORZ, sb_pos, TRUE);
//Getting the horizontal scroll position
int current_pos = GetScrollPos(SB_HORZ);
ASSERT(current_pos==sb_pos);
}You'll also need to change your OnCreate function:
int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
SetScrollRange(SB_HORZ, 0, 50,TRUE);
SetScrollPos(SB_HORZ, 0,TRUE);
}And take out the m_hScroll from your window. Hope that helps (and I hope it's right too!)
"We are the knights who say Ni" (The Knights Who Say Ni)
-
I think the problem is that
m_hScroll
isn't actually the scroll-bar that you see in the window. When you set the style (cs.style
() in PreCreateWindow toWS_VSCROLL | WS_HSCROLL
the window creates its own scrollbars, and you need to use the member functions of CWnd to access them. For example, to get and set the position of the horizontal scroll-barvoid CChildFrame::some_function(int sb_pos)
{
//Setting the horizontal scroll position
SetScrollPos(SB_HORZ, sb_pos, TRUE);
//Getting the horizontal scroll position
int current_pos = GetScrollPos(SB_HORZ);
ASSERT(current_pos==sb_pos);
}You'll also need to change your OnCreate function:
int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
SetScrollRange(SB_HORZ, 0, 50,TRUE);
SetScrollPos(SB_HORZ, 0,TRUE);
}And take out the m_hScroll from your window. Hope that helps (and I hope it's right too!)
"We are the knights who say Ni" (The Knights Who Say Ni)