Strange problem with simple scroll bar
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Strange problem with simple scroll bar

  1. #1
    Join Date
    Apr 2010
    Location
    Western WA, USA
    Posts
    59

    Strange problem with simple scroll bar

    I have a dialog that contains a scroll bar (SB_CTL) that doesn't give the expected behavior. The first clue is that the size of the thumb button is wrong (too large) for the range/page proportions.

    It is initialized to a range of 0 to 112, with a page size of 48.
    Code:
    	vsi.nMin = 0;
    	vsi.nMax = 112;
    	vsi.nPage = 48;
    	vsi.nPos = 0;
    When I grab the thumb, the position will go from 0 to 65, and no higher.
    If click in the 'page down' area, it will go to 96, and no higher.
    If I use the 'line up' and 'line down' buttons, it will go the full range 0 to 112, but the thumb position stops early. If the position is at 112 and I click on the thumb (at the bottom of the bar), the position immediately jumps to 65.

    My experiments have yielded no joy, so I have distilled a minimum length test case, and I hope someone can please tell me why this code isn't working right. Using WinXP-SP3, VC++ 8.
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by cosmicvoid; April 6th, 2014 at 03:18 PM. Reason: Add image

  2. #2
    Join Date
    Apr 2010
    Location
    Western WA, USA
    Posts
    59

    Re: Strange problem with simple scroll bar

    I have found a way to get the results I expect, but I'm puzzled as to whether this is the usual way a scroll bar needs to be handled. I've never had this issue before, and I've used scroll bars many times. Or maybe I'm just getting feebleminded in my old age .

    Initialization values:
    Code:
    #define DESIREDRANGE  112
    #define PAGESIZ  48
    
    	vsi.nMin = 0;
    	vsi.nMax = DESIREDRANGE + PAGESIZ - 1;
    	vsi.nPage = PAGESIZ;
    	vsi.nPos = 0;
    Handling the messages:
    Code:
    	case WM_VSCROLL:
    		if ((HWND)lParam == hWvscrl)
    		{
    			switch (LOWORD(wParam))
    			{
    				case SB_LINEDOWN:
    					vsi.nPos++;
    					break;
    
    				case SB_LINEUP:
    					vsi.nPos--;
    					break;
    
    				case SB_PAGEDOWN:
    					vsi.nPos += PAGESIZ;
    					break;
    
    				case SB_PAGEUP:
    					vsi.nPos -= PAGESIZ;
    					break;
    
    				case SB_THUMBTRACK:
    					vsi.nPos = HIWORD(wParam);
    					break;
    			}
    			if (vsi.nPos > DESIREDRANGE) vsi.nPos = DESIREDRANGE;
    			if (vsi.nPos < vsi.nMin) vsi.nPos = vsi.nMin;
    			vsi.fMask = SIF_POS;
    			SetScrollInfo(hWvscrl, SB_CTL, &vsi, true);
    		}
    Attached Images Attached Images  
    Last edited by cosmicvoid; April 6th, 2014 at 09:25 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center