Pls debug my scroll program

This is a discussion on Pls debug my scroll program within the Windows Programming forums, part of the Platform Specific Boards category; REALLY GRATEFUL if someone can help. I've been debugging this program for very long and i still cant find the ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    133

    Pls debug my scroll program

    REALLY GRATEFUL if someone can help.

    I've been debugging this program for very long and i still cant find the problem. If u keep scrolling the child window down, it wont end(i want it to stop scrolling at 'p'). It works fine if u keep scrolling up. In particular, you might want to check the scrolling implements which is found in scroll.cpp.

    The file is zipped and attached.
    Compiler:VC++ 6.0

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    There's some issue with oldPos. When it should be 41, its not. It's lagging by about 10 places. I'll keep debugging.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  3. #3
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    What the!! I was scrolling step by step, pausing at every call to the scroll_onVscroll() function, and the odd behavior didn't occur! Now I'm freaked out.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  4. #4
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    I'm spent. As it's not my code, I really can't figure out how each part works together as a whole. I suggest starting again. Build it slowly, compiling and checking behavior step by step.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  5. #5
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Okay I've got it. You're letting nPos get all the way to nMax, but logically it shouldn't. Because the scroll window displays more than one entry at a time, and because nPos represents the TOP of the scrolling area, when nPos is nMax, it will be displaying an entire page past nPos. So what you need to do is stop scrolling when nPos equals nMax-nPage. I think that should fix it.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  6. #6
    Registered User
    Join Date
    Sep 2003
    Posts
    133
    Thanks for the great help, benny!!!

    If i stop scrolling when nPos reach (si.nMax-si.nPage), the scroll box never reach the bottom of the scroll bar. But i managed to solve it by using (si.nMax-si.nPage+1) instead.

    Code:
    	oldPos = si.nPos;
    	newPos = si.nPos + y;
    	si.nPos = max(0, min(newPos, (si.nMax-si.nPage+1)));
    
    	if(si.nPos != oldPos)
    	{
    
    		SetScrollInfo (hwnd, SB_VERT, &si, TRUE);
    		ScrollWindow(hwnd,0,cychar*(oldPos-si.nPos),NULL,NULL);
    		UpdateWindow(hwnd);
    	}
    However, if i want the window to be able to scroll till only the last 'p' is on the screen. What should i do? In fact, i tried (si.nMax-si.nPage+2) for experiment and the endless scrolling problem comes again. The window kept printing '.' after the 'p'. I really dont understand where the '.' come from.

  7. #7
    Registered User
    Join Date
    Sep 2003
    Posts
    133
    oh yeah!
    I figured out the solution.
    Just change the nMax during each resize:

    Code:
    	si.cbSize = sizeof(SCROLLINFO);
    	si.fMask = SIF_PAGE | SIF_RANGE;
    	si.nMin = 0;
    	si.nPage = (height/cychar);
    	si.nMax = 40 +si.nPage;
    	SetScrollInfo(hwnd,SB_VERT,&si,TRUE);
    But i wish i know where the '.' come from.

  8. #8
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    I'm glad we worked this out.

    As far as I can tell, the dots shouldn't be there. The TextOut() loop only runs to si.nMax, and anyway, letter[] does not contain a dot. I believe it has something to do with the fact that you are not actively erasing the client area each time you paint. However, I am not sure. I will look into it later today.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pls help me on this program
    By Lopen007 in forum C++ Programming
    Replies: 2
    Last Post: 03-07-2008, 03:14 AM
  2. need to convert my program into function type.. help pls..
    By toruhikaru in forum C++ Programming
    Replies: 3
    Last Post: 08-25-2005, 12:10 AM
  3. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM
  4. Pls explain how this program works...
    By Unregistered in forum C Programming
    Replies: 9
    Last Post: 01-05-2002, 08:53 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21