Advertisement

How can I use window's scrolling

Started by July 14, 2001 05:15 AM
3 comments, last by Alload 23 years, 7 months ago
Hello folks, I have to implement scrolling in my Win32 application. I read the SDK documentation, it didn''t look too hard so I wrote code at once. But my scrolling code doesn''t work at all. And I don''t know where''s the error... Here''s the global variables: SCROLLINFO si; short nScreenMaxX; short nScreenMaxY; short nScrollX = 0; short nScrollY = 0; Here''s the message handler''s part which use the scrolling: case WM_SIZE: { nScreenMaxX = LOWORD(lParam); nScreenMaxY = HIWORD(lParam); si.cbSize = sizeof(SCROLLINFO); si.fMask = SIF_ALL; si.nMin = 0; si.nMax = nScreenMaxX; si.nPage = 50; si.nPos = nScrollX; SetScrollInfo(hWnd, SB_HORZ, &si, true); InvalidateRect(hWnd, NULL, true); return 0; } case WM_HSCROLL: { short nInc; switch (LOWORD(wParam)) { case SB_PAGEUP: { nInc = si.nPage; } case SB_PAGEDOWN: { nInc = -si.nPage; } case SB_LINELEFT: { nInc = -1; } case SB_LINERIGHT: { nInc = 1; } case SB_THUMBTRACK: { nInc = HIWORD(wParam) - nScrollX; } default: { nInc = 0; } } nScrollX += nInc; si.nPos = nScrollX; SetScrollInfo(hWnd, SB_HORZ, &si, true); InvalidateRect(hWnd, NULL, true); return 0; } Does anyone see what''s going wrong?
Hi,
Did you create the window with scroll bar style:
WS_HSCROLL | WS_VSCROLL
did you call ShowScrollBar(TRUE); ?
Maybe one of these two things is the cause of your problems.
-- Gilad
Advertisement
I created my window using the WS_HSCROLL and WS_VSCROLL tags, but I didn''t call the function ShowScrollBar.

I''m going to try to put it, I thought it was just a function to initialise scroll bars when they weren''t created with the window.

Thanks.
It still doesn''t work...
Ah, scroll bars, the bane of windows programming (I swear, scroll bars have to be the absolute worst thing to program as far as the GUI goes).

here''s a snippet of my code that works. kind of in a rush right now, just cut and paste, so see if it makes any sense:

  //some code herecase WM_SIZE:		wmId = LOWORD(lParam);		// the width of the window		GetClientRect(hWnd,&rt);	// gets the client rectangle		// gets the maximum scrolling position		hscroll.nMax=windowlength-(rt.right-rt.left)+Paint.getStepSize();		if(wmId!=0){			hscroll.nPage=getWinRatio(wmId-STAT_OFFSET);	// gets the scrollinng thickness//			hscroll.nPage*=Paint.getStepSize();			resize=false;						// no resize		}		else{			hscroll.nPos=0;			// the offset = the maximum scroll postion			resize=true;						// resize the window								// scroll the window all the way right		}		if(windowlength<(rt.right-rt.left)){			windowoffset = 0;			hscroll.nPos = 0;			hscroll.nMax = 0;			hscroll.nMin = 0;			hscroll.nPage = 0;		}		else{			if(hscroll.nPos>hscroll.nMax){				windowoffset = hscroll.nMax;			}			else{				windowoffset=hscroll.nPos;	// the window offset = the horiztonal scroll position					}		}		SetScrollInfo(hWnd,SB_HORZ,&hscroll,false);	// set the scroll info//some more code here in the WM_SIZEcase WM_HSCROLL: //. scroll bar stuff			hscroll.fMask = SIF_ALL;			wmId	= LOWORD(wParam);	// the width of the window			GetScrollInfo(hWnd,SB_HORZ,&hscroll);	// get the scroll bar info			i=hscroll.nPos;				// keep the previous postion			switch(wmId){			case SB_LINELEFT:			// the user clicks the left button				hscroll.nPos-=Paint.getStepSize();				break;			case SB_LINERIGHT:			// the user clicks the right button				hscroll.nPos+=Paint.getStepSize();				break;			case SB_THUMBTRACK:			// the user drags the scroll bar				hscroll.nPos=hscroll.nTrackPos;				break;			case SB_PAGEDOWN:			// the user clicks to the right of the bar				hscroll.nPos+=(hscroll.nPage*Paint.getStepSize());				break;			case SB_PAGEUP:				// the user clicks to the left of the bar				hscroll.nPos-=(hscroll.nPage*Paint.getStepSize());				break;				// stop using the scroll bar			case SB_THUMBPOSITION:			case SB_ENDSCROLL:				// set the scroll info				SetScrollInfo(hWnd,SB_HORZ,&hscroll,true);				// retrieve the scroll info				GetScrollInfo(hWnd,SB_HORZ,&hscroll);				// set the window offset				windowoffset=hscroll.nPos;				// sets the scroll info				SetScrollInfo(hWnd,SB_HORZ,&hscroll,false);				// recalculate the windows if scaling is enabled				if(Paint.getScale())					calcRatio(numwindows,false);				return 0;			default:				break;			}			// set the scroll info			SetScrollInfo(hWnd,SB_HORZ,&hscroll,true);			// get the scroll info			GetScrollInfo(hWnd,SB_HORZ,&hscroll);			// if the new position != the old position, scroll the windows			// to do: ScrollWindow has been replaced by ScrollWindowEx			if(i!=hscroll.nPos){				windowoffset=i-hscroll.nPos;				ScrollWindow(Window1->gethWnd(),windowoffset,0,0,0);				ScrollWindow(Window2->gethWnd(),windowoffset,0,0,0);				ScrollWindow(Window3->gethWnd(),windowoffset,0,0,0);				windowoffset=hscroll.nPos;		// the window offset = the scroll position				SetScrollInfo(hWnd,SB_HORZ,&hscroll,false);	// set the scroll info							}			break;  

This topic is closed to new replies.

Advertisement