Thread: Scroll bar help

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    rEtaRD r HUMANS TOO !!! rEtard's Avatar
    Join Date
    Feb 2005
    Posts
    80
    anonytmouse, anyone, im at a total lost to this scrollbar thing. I reviewed MSDN scrolling examples, i did wat i could, modified the codes, improved on the scroll position and max n min values but i still can't get the output of my bitmap icons correct. Someone pls advise.
    Code:
    static int xClient, yClient, Column, IconsNo, CurrentPos;
    		case WM_SIZE:
    			IconsNo = 13;
    			Column = IconsNo / 4 + 1; // if possible correct this formula
                xClient = LOWORD (lParam) ;
                yClient = HIWORD (lParam) ; // this is what we wan
    			si.cbSize = sizeof(si);
    			si.fMask = SIF_RANGE | SIF_PAGE;
    			si.nPage = yClient; // page/viewing size is Y coord, Reasonable rite
    			si.nMin = 0;
    			si.nMax = Column * 150 + 10 - yClient;
    			SetScrollInfo(hwnd,SB_VERT,&si,TRUE);
    		case WM_PAINT:
    			HDC hdc;
    			hdc = BeginPaint(hwnd,&ps);
    			HBITMAP test;
    			test = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_NOTE));
    			int x,y,i;
    			x = 10; y = 10; // starting coordinates
    			i = 0;
    
    			// Displaying the Icons onto the client area
    			while(i<IconsNo)
    			{
    				if ( x > 265 ) 
    				{
    					x = 10;
    					y = y + 90;
    					bMp->Draw(test,hdc,1,x,y,0,0);
    				}
    				bMp->Draw(test,hdc,1,x,y,0,0);
    				x = x + 85;
    				i++;
    			}
    
    			if (Scroll )
    			{
    				HDC TempHDC;
    				TempHDC = CreateCompatibleDC(hdc);
    				SelectObject(TempHDC,test);
     // i did this SelectObject to show if scrolling worked
    // but this bitmap will only appear if i did an extreme
    // thumb position from down to up, other than it wun even appear
    				BitBlt(ps.hdc,ps.rcPaint.left,ps.rcPaint.top,
    					   ps.rcPaint.right - ps.rcPaint.left,
    					   ps.rcPaint.bottom - ps.rcPaint.top,
    					   TempHDC,
    					   ps.rcPaint.left + 0,
    					   ps.rcPaint.top + CurrentPos,SRCCOPY);
    				Scroll = FALSE;
    			}
    			
    			EndPaint(hwnd,&ps);
    			DeleteObject(test);
    			break;
    	    case WM_VSCROLL:
    			// coding this scroll bar is making my hair drop !
    			int YnewPos,MovedAmt;
                si.cbSize = sizeof (si); // impt
                si.fMask  = SIF_ALL; // impt
    			GetScrollInfo(hwnd,SB_VERT,&si);
    			YnewPos = si.nPos;
    			switch(LOWORD(wParam))
    			{
    		    	case SB_LINEDOWN:
    					si.nPos +=5;
    					break;
    				case SB_PAGEDOWN:
    					si.nPos += 20;
    					break;
    				case SB_THUMBPOSITION:
    					si.nPos = si.nTrackPos;
    					break;
    				case SB_PAGEUP:
    					si.nPos -= 20;
    					break;
    				case SB_LINEUP:
    					si.nPos -=5;
    					break;
    			}
    			if ( si.nPos != YnewPos )
    			{
    			    SetScrollInfo(hwnd,SB_VERT,&si,TRUE); // impt
    			    GetScrollInfo(hwnd,SB_VERT,&si); // impt
    
    			    Scroll = TRUE; // flag to inform WM_PAINT abt new job
    			    MovedAmt = YnewPos - si.nPos; // determine scroll moved amt
    
                    ScrollWindowEx(hwnd,0,MovedAmt,NULL,NULL,NULL,NULL,SW_INVALIDATE);
    			    UpdateWindow(hwnd); // push WM_PAINT now
    			}
    		  break;
    everithing abt the scrollbar is fine now, all i need is that it display the correct amount of icons being hidden below or above. This is what im stucked with.
    Please take a look at my attached Image1. My variable IconsNo was set to 13, so there should be another Bitmap icon at the end of my scroll.
    Ok, for now, let me get one thing straight first, do me(the programmer) have to take charge of all drawings to make up for the scrolling actions the user did ? or win32 will take care of it for me.
    Last edited by rEtard; 05-17-2005 at 02:52 PM.
    /* Have a nice day */

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. beach bar (sims type game)
    By DrKillPatient in forum Game Programming
    Replies: 1
    Last Post: 03-06-2006, 01:32 PM
  2. Bitmap with a scroll bar
    By SuperNewbie in forum Windows Programming
    Replies: 1
    Last Post: 10-29-2003, 11:36 PM
  3. no horizontal scroll bar?
    By scott27349 in forum C++ Programming
    Replies: 0
    Last Post: 03-16-2002, 10:41 PM
  4. Problem with Scroll Bar
    By Garfield in forum Windows Programming
    Replies: 8
    Last Post: 11-05-2001, 05:34 AM
  5. Problem with Scroll Bar
    By Garfield in forum Windows Programming
    Replies: 3
    Last Post: 11-01-2001, 02:23 PM