scollbar in CStatic
-
Hi Friends I have created a class CImageViewer from CStatic. I also need scrolling of image in horizontal and vertical. I set scrollinfo for both scrolls and scrollbars (both) shown in my control. But it does not work. How can i solve this problem thanks in advance
-kk.tvm-
-
Hi Friends I have created a class CImageViewer from CStatic. I also need scrolling of image in horizontal and vertical. I set scrollinfo for both scrolls and scrollbars (both) shown in my control. But it does not work. How can i solve this problem thanks in advance
-kk.tvm-
Please explain what you mean by "it does not work" and provide relevant code snippet.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
Please explain what you mean by "it does not work" and provide relevant code snippet.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++Hi Cédric Moonen, Basically my class is subclass of CStatic. I set scrollinfo using below code
void CImageViewer::PreSubclassWindow()
{
CRect rect;
GetClientRect( &rect );// set horizontal scroll bar SCROLLINFO si; ZeroMemory( &si, sizeof( SCROLLINFO )); si.cbSize = sizeof( SCROLLINFO ); si.fMask = SIF\_ALL; si.nMin = 0; si.nMax = nScrWidth; si.nPage = rect.Width(); si.nPos = 0; si.nTrackPos = 0; SetScrollInfo( SB\_HORZ, &si ); CStatic::PreSubclassWindow();
}
and handled OnHScroll Message
void CImageViewer::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
SCROLLINFO si;
int nScrollPos = nPos;
pScrollBar->GetScrollInfo( &si );
int nCurPos = si.nPos;
int nMin = si.nMin;
int nMax = si.nMax;switch( nSBCode ) { case SB\_THUMBPOSITION: case SB\_THUMBTRACK: nScrollPos = si.nTrackPos; break; case SB\_LEFT: nScrollPos = nMin; break; case SB\_RIGHT: nScrollPos = nMax; break; case SB\_LINELEFT: nScrollPos = nCurPos - 2; break; case SB\_LINERIGHT: nScrollPos = nCurPos + 2; break; case SB\_PAGELEFT: nScrollPos = nCurPos - 5; break; case SB\_PAGERIGHT: nScrollPos = nCurPos + 5; break; case SB\_ENDSCROLL: nScrollPos = nCurPos; break; } if(nScrollPos < nMin) nScrollPos = nMin; else if(nScrollPos > nMax) nScrollPos = nMax; pScrollBar->SetScrollPos( nScrollPos ); Invalidate(); CStatic::OnHScroll(nSBCode, nPos, pScrollBar);
}
After this a scroll bar appears with my control. But i can't change scroll position.
-kk.tvm-
-
Hi Cédric Moonen, Basically my class is subclass of CStatic. I set scrollinfo using below code
void CImageViewer::PreSubclassWindow()
{
CRect rect;
GetClientRect( &rect );// set horizontal scroll bar SCROLLINFO si; ZeroMemory( &si, sizeof( SCROLLINFO )); si.cbSize = sizeof( SCROLLINFO ); si.fMask = SIF\_ALL; si.nMin = 0; si.nMax = nScrWidth; si.nPage = rect.Width(); si.nPos = 0; si.nTrackPos = 0; SetScrollInfo( SB\_HORZ, &si ); CStatic::PreSubclassWindow();
}
and handled OnHScroll Message
void CImageViewer::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
SCROLLINFO si;
int nScrollPos = nPos;
pScrollBar->GetScrollInfo( &si );
int nCurPos = si.nPos;
int nMin = si.nMin;
int nMax = si.nMax;switch( nSBCode ) { case SB\_THUMBPOSITION: case SB\_THUMBTRACK: nScrollPos = si.nTrackPos; break; case SB\_LEFT: nScrollPos = nMin; break; case SB\_RIGHT: nScrollPos = nMax; break; case SB\_LINELEFT: nScrollPos = nCurPos - 2; break; case SB\_LINERIGHT: nScrollPos = nCurPos + 2; break; case SB\_PAGELEFT: nScrollPos = nCurPos - 5; break; case SB\_PAGERIGHT: nScrollPos = nCurPos + 5; break; case SB\_ENDSCROLL: nScrollPos = nCurPos; break; } if(nScrollPos < nMin) nScrollPos = nMin; else if(nScrollPos > nMax) nScrollPos = nMax; pScrollBar->SetScrollPos( nScrollPos ); Invalidate(); CStatic::OnHScroll(nSBCode, nPos, pScrollBar);
}
After this a scroll bar appears with my control. But i can't change scroll position.
-kk.tvm-
kk.tvm wrote:
But i can't change scroll position.
Do you mean that the scroll is displayed properly and that you can use it correctly but it doesn't have any effect on your drawing ? That's what I would guess by seeing your code, since you do not do anything with the scroll position (it's a local variable). What you need to do is remember the scroll position and use it when you draw your picture: you have to apply it as an offset to the picture. It's not because you added a scroll bar to a control that it will magically move when you use the scrollbar. You have to do that yourself by shifting the picture when the scroll is moved.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
kk.tvm wrote:
But i can't change scroll position.
Do you mean that the scroll is displayed properly and that you can use it correctly but it doesn't have any effect on your drawing ? That's what I would guess by seeing your code, since you do not do anything with the scroll position (it's a local variable). What you need to do is remember the scroll position and use it when you draw your picture: you have to apply it as an offset to the picture. It's not because you added a scroll bar to a control that it will magically move when you use the scrollbar. You have to do that yourself by shifting the picture when the scroll is moved.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
Hi Cédric Moonen ok, i want to write code to scroll the image. what i mean.... Scrollbar is properly shown with control. But when i press arrow heads (left or right) or thumb it does not move or changed, like disabled. thanks in advance
-kk.tvm-
Perhaps your increments are too small compared to the full lenght of the scroll bar. Did you check with the debugger to see the values nMin, nMax, ... to see if everything seems correct ? And compare them to the -2/+2 you add when you click the arrow. I guess they are neglectable compared to nMax.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
Perhaps your increments are too small compared to the full lenght of the scroll bar. Did you check with the debugger to see the values nMin, nMax, ... to see if everything seems correct ? And compare them to the -2/+2 you add when you click the arrow. I guess they are neglectable compared to nMax.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++