# Scrollbar warps

This topic is 4453 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Did anybody ever have this problem... (by the way, I'm using c++) You have a vertical or horizontal scrollbar. Let's use a horizontal one for this example. If the SCROLLINFO.nPos member is at 0 (thumb is all the way at the left), and you click on the left arrow, the thumb shoots to the right. That happened to me with this code...

LRESULT CALLBACK cEditor::prTileHandler(HWND hTileWnd, UINT msg, WPARAM wParam,
LPARAM lParam){

// Scrolling information
SCROLLINFO si;
BITMAP bm;
RECT rcTileWnd;
static short sXTilePos;

switch(msg){

// Called when Tile Selector window is resized
case WM_SIZE:

GetObject(tlSelectedSet.hTileset, sizeof(bm), &bm); // Just retrieves dimensions of current tileset for scrolling
GetClientRect(hTileWnd, &rcTileWnd);

si.cbSize = sizeof(SCROLLINFO);
si.nMin = 0;

si.nPage = rcTileWnd.right;
si.nMax = bm.bmWidth - 1;
si.nPos = sXTilePos;

SetScrollInfo(hTileWnd, SB_HORZ, &si, TRUE);

// WM_SIZE message handled, return 0;
return 0;

// Called when the Tile Selector window is scrolled horizontally
case WM_HSCROLL:

GetScrollInfo(hTileWnd, SB_HORZ, &si);

{
switch(LOWORD(wParam)){
case SB_LINELEFT:
si.nPos -= 1;
break;

case SB_LINERIGHT:
si.nPos += 1;
break;

case SB_THUMBTRACK:
si.nPos = HIWORD(wParam); // Oh and this doesn't work either
break;
}

SetScrollInfo(hTileWnd, SB_HORZ, &si, TRUE);
}

// WM_HSCROLL message handled, return 0
return 0;

// ... rest of messages
}
}


Anyone have an idea? It wasn't messing up before but I had to delete all the code here to integrate it into my Map Editor Engine.

##### Share on other sites
You seem to be experiencing what looks to me like an automatic wraparound. This occurs where you have a number, say, 0, for an unsigned char, or an unsigned int. Now, you ask the program to take 0, and then to detract one (because you press the left arrow) which is basically saying - what's the number before 0 in an unsigned number. Well, there is none. If you were to look at your variables in binary - it's much more complicated than that, but point being - if you were to go less than 0 in an unsigned number, your variable would 'wrap around' to the next number - in this case, the greatest number that data type can hold.
What you should do inside your switch statement:
Quote:
 switch(LOWORD(wParam))
is this:
case SB_LINELEFT:            if (si.nPos &gt; 0)                        si.nPos -= 1;            break;          case SB_LINERIGHT:            if (si.nPos &lt; 255)                        si.nPos += 1;            break;
Now, I used 255 there for the highest value that si.nPos can be, that is assuming you used an unsigned char. If you used an unsigned int, change it to 65535.
Hope this helps.

1. 1
2. 2
3. 3
4. 4
Rutin
13
5. 5

• 13
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633692
• Total Posts
3013355
×