Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CScrollBar doesn't work!

Status
Not open for further replies.

Hossein

Programmer
Joined
Mar 28, 2001
Messages
1
Location
CZ
Hi there,I want to scroll an image in a CView window and
I have not (and do not want to) use CScrollView .I mean I
want do the scrolling with CScrollBar control.I have done
the work but it doesn't scroll.When I drag the scroll,it
goes back in its first position .Any suggestion?
I have initializd the control in this way:

scroll.Create(SBS_VERT|WS_CHILD,r,this,100);
scroll.SetScrollRange(0,b.bmHeight);
scroll.SetScrollPos(0);
scroll.ShowScrollBar();

where ,scroll is a CScrollBar inside CView class.
please help me.

 
What I have had to do is handle the ON_HSCROLL or ON_VSCROLL messages for the scrollbar. From what I can tell all scrollbars, either dialog controlls you place, or the ones that automatically appear as a part of the view, trigger these messages. When you override the handler the function is this:

Code:
OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)

The first thing you want to do is checkthat the pScrollBar passed into this function is the scrollbar you want to work with. In your case a simple

Code:
 if (&scroll == pScrollBar)

will work.

The nSBCode is what action was performed on the scroll bar, and you can alter the position by processing that code, and using the SetScrollPos() function.

I would recommend checking out the MSDN help on the OnHScroll/OnVScroll functions to get all the different nSBCodes, its pretty good.

Dragoon.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top