473,473 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ScrollBar issue

48 New Member
Hi windows API programmers,

I'm so close to making my vertical scrollbar to work properly, except for:

After pushing or dragging the scrollbar the window scrolls properly until I let go of the mouse. When I let go the window scrolls another unit to which I don't want to happen. I want to have the scrollbar place the window where it was set rather than 1 unit up or down.

Another odd thing is the WM_VSCROLL message is called once when the mouse is down and once when the mouse is up. I think if I can make it only call it for mousedown then it would fix this problem.


Suggestions? Thanks.

Expand|Select|Wrap|Line Numbers
  1. case WM_VSCROLL:
  2. {
  3.     int nScrollCode = (int)LOWORD(wParam);
  4.     int nPos = (short int)HIWORD(wParam);
  5.     controlVbar(nScrollCode, nPos);
  6.  
  7.     if(curScrollPos!=oldScrollPos && curScrollPos > 0 && curScrollPos < 100)
  8.     {
  9.         ScrollWindowEx(hwndMain, 0, oldScrollPos-curScrollPos, NULL, NULL, NULL, NULL, SW_SCROLLCHILDREN);
  10.         RedrawWindow(hwndMain, NULL, NULL, RDW_ERASE | RDW_INVALIDATE );
  11.  
  12.     }
  13. }    
  14. break;
  15.  
The following is the controlVbar function called from the above line 5.
Expand|Select|Wrap|Line Numbers
  1. void mainWindow::controlVbar(int nScrollCode, int nPos)
  2. {
  3.  
  4.     switch (nScrollCode)
  5.     {
  6.         // Include code that checks for other values of nScrollCode.
  7.         // ...
  8.         case SB_THUMBTRACK:
  9.         {
  10.             oldScrollPos=curScrollPos;
  11.             curScrollPos=nPos;
  12.             SetScrollPos(hwndMain, SB_VERT, nPos, TRUE);
  13.         }
  14.         break;
  15.  
  16.         case SB_LINEUP:
  17.         {
  18.             if(curScrollPos > 0)
  19.             {
  20.                 oldScrollPos=curScrollPos;
  21.                 curScrollPos=oldScrollPos-1;
  22.             }
  23.             SetScrollPos(hwndMain, SB_VERT, curScrollPos, TRUE);
  24.         }
  25.         break;
  26.  
  27.         case SB_LINEDOWN:
  28.         {
  29.             oldScrollPos=curScrollPos;
  30.             if(curScrollPos < 100)
  31.             {
  32.                 oldScrollPos=curScrollPos;
  33.                 curScrollPos=oldScrollPos+1;
  34.             }
  35.             SetScrollPos(hwndMain, SB_VERT, curScrollPos, TRUE);
  36.         }
  37.         break;
  38.  
  39.     }
  40.  
  41.  
  42. }
  43.  
Jun 7 '07 #1
2 2297
qhimq
48 New Member
to complete this with an answer I figured out:

first make 3 global int
Expand|Select|Wrap|Line Numbers
  1. int oldScrollPos=0;
  2. int curScrollPos=1;
  3. int lastScroll;
  4.  

Then add these functions:
Expand|Select|Wrap|Line Numbers
  1. void msWheel(HWND hwnd, int zDelta)
  2. {
  3.     if(zDelta > 0)
  4.         zDelta=120;
  5.     else
  6.         zDelta=-120;
  7.  
  8.     oldScrollPos=curScrollPos;
  9.     if(curScrollPos <= 680 && zDelta < 0)
  10.         curScrollPos+=120;
  11.     else if(curScrollPos > 680 && zDelta < 0)
  12.         curScrollPos=799;
  13.  
  14.     if(curScrollPos > 120 && zDelta > 0)
  15.         curScrollPos+=-120;
  16.     else if(curScrollPos < 120 && zDelta > 0)
  17.         curScrollPos=1;
  18.  
  19.     SetScrollPos(hwnd, SB_VERT, curScrollPos, TRUE);
  20.  
  21.     if(curScrollPos!=lastScroll && curScrollPos > 0 && curScrollPos < 800)
  22.     {
  23.         ScrollWindowEx(hwnd, 0, oldScrollPos-curScrollPos,
  24.                         NULL, NULL, NULL, NULL, SW_SCROLLCHILDREN);
  25.         RedrawWindow(hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE );//| RDW_ALLCHILDREN
  26.  
  27.         lastScroll=curScrollPos;
  28.  
  29.     }
  30.  
  31. }
  32.  
  33. void controlVbar(int nScrollCode, int nPos, HWND hwnd)
  34. {
  35.  
  36.     switch (nScrollCode)
  37.     {
  38.         // Include code that checks for other values of nScrollCode.
  39.         // ...
  40.         case SB_THUMBTRACK:
  41.         {
  42.             oldScrollPos=curScrollPos;
  43.             curScrollPos=nPos;
  44.             SetScrollPos(hwnd, SB_VERT, nPos, TRUE);
  45.         }
  46.         break;
  47.  
  48.         case SB_LINEUP:
  49.         {
  50.             if(curScrollPos > 0)
  51.             {
  52.                 oldScrollPos=curScrollPos;
  53.                 if(curScrollPos > 10)
  54.                     curScrollPos=oldScrollPos-10;
  55.                 else
  56.                     curScrollPos=1;
  57.             }
  58.             SetScrollPos(hwnd, SB_VERT, curScrollPos, TRUE);
  59.         }
  60.         break;
  61.  
  62.         case SB_LINEDOWN:
  63.         {
  64.             oldScrollPos=curScrollPos;
  65.             if(curScrollPos < 800)
  66.             {
  67.                 oldScrollPos=curScrollPos;
  68.                 curScrollPos=oldScrollPos+10;
  69.             }
  70.             SetScrollPos(hwnd, SB_VERT, curScrollPos, TRUE);
  71.         }
  72.         break;
  73.  
  74.     }
  75.  
  76.             if(curScrollPos!=lastScroll && curScrollPos > 0 && curScrollPos < 800)
  77.             {
  78.                 ScrollWindowEx(hwnd, 0, oldScrollPos-curScrollPos,
  79.                                 NULL, NULL, NULL, NULL, SW_SCROLLCHILDREN);
  80.                 RedrawWindow(hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE );//| RDW_ALLCHILDREN
  81.  
  82.                 lastScroll=curScrollPos;
  83.             }
  84.  
  85.  
  86. }
  87.  
Then to call those functions add these cases in your CALLBACK switch:

Expand|Select|Wrap|Line Numbers
  1. case WM_VSCROLL:
  2.     {
  3.         int nScrollCode = (int)LOWORD(wParam);
  4.         int nPos = (short int)HIWORD(wParam);//short int?
  5.         controlVbar(nScrollCode, nPos, hwnd);
  6.     }
  7.         break;
  8.     case WM_MOUSEWHEEL:
  9.         msWheel(hwnd, GET_WHEEL_DELTA_WPARAM(wParam));
  10.  
  11.  
  12.     break;
  13.  
Jun 18 '07 #2
qhimq
48 New Member
To create the scrollbar I added the vertical scrollbar style on the parent dialog.

then did this code in the main:

Expand|Select|Wrap|Line Numbers
  1. SCROLLINFO si = {sizeof(SCROLLINFO), 
  2.             SIF_PAGE|SIF_POS|SIF_RANGE|SIF_TRACKPOS, 1, 799, 0, 0, 
  3.             0};
  4.     SetScrollInfo (hwnd, SB_VERT, &si, TRUE);
  5.  
Jun 18 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Roderik | last post by:
Hi, At http://archytas.nl/ there appears to be a horizontal scrollbar when using Mozilla Firebird (not in IE). The website (container DIV) should be 770 px wide, so there shouldn't be any reason...
0
by: Jeje | last post by:
Hi everybody, I have an issue using the scrollbar under Internet explorer 6, WinXP and transitional.dtd. Here's my code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
0
by: markusszil | last post by:
Hello all I have a fairly simple listbox into which I add, insert, and remove strings It has the following property settings HorizontalScrollbar - true HorizontalExtent - ScrollAlwaysVisible...
7
by: Sujan | last post by:
Hello all, Is it possible to remove scrollbar(s) without using frames. Is there any code which could be applied in body tag to remove scrollbar(s). Thanks in adv, Sujan
5
by: Spondishy | last post by:
Hi, I am using the following in my stylesheet to center divs in firefox. html>body { font-size: 13px; } div.centerdiv {
2
by: Coder | last post by:
my question is not only specific to C#. In most of the visual environments we use textboxes, buttons etc.. Exp: In C# i have a textbox (multiline textbox). Suppose that, application is...
3
by: weston | last post by:
I'm making a foray into trying to create custom vertical scrollbars and sliders, and thought I had a basic idea how to do it, but seem to be having some trouble with the implementation. My...
3
hsriat
by: hsriat | last post by:
How can I temporarily disable vertical scrollbar? I have replaced confirmation boxes and alert boxes with inlay popup DIVs. But while they are on the screen, I need to disable scrollbar of the...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.