Click here to Skip to main content
15,040,212 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear Seniors,
I would like to know the mechanism in increasing the size of a vertical scroll bar dynamically in my output window.

Ex: I want to take input a file name and display the contents of it. But each time the user inputs a different file name the length of the file changes as well. So length of the scroll bar do changes each time.
Please suggest me a way in implementing the above.

My Approach:
Step-1
------
I have predefined the total number of lines to be display as below
#define MAXLINES 100

Step-2
------
I am using the below in WM_SIZE:
case WM_SIZE:
scrollinfo.nMin = 0;
scrollinfo.nMax = MAXLINES - 1;
SetScrollInfo( hwnd, 0, NUMLINES - 1, &si );

Step-3
------
case WM_PAINT:
step: finding the paint limits;
for( i = PaintBeg; i <= PaintEnd; i++ )
{
  using textout function to print a line
}


But the above procedure is fixed to the preassumed predefined macro MAXLINES which is 100 and can only print upto 100 lines but not more.

Language: C ( only ) using win32 api.
Compiler: VC++

Regards,
Kiran.
Posted
Updated 23-Jul-11 11:14am
v2
Comments
TweakBird 23-Jul-11 17:16pm
   
Please use <pre> tag for code blocks.

1) Replace you macros with variable (number of lines).

2) When you load the file, count the number of lines.

3) Update the variable that contains the number of line and also reset another variable that is used for the index of the first displayed line.

4) You should update your scroll bar information when the file is loaded and not in WM_SIZE (well if you do word wrap and need to start on splitted line), you might still need WM_SIZE handler.

See the MSDN documentation for exact computation needed for scroll information.
   
Why not use a TEXTBOX control and set the appropriate styles?

A TEXTBOX already know how to adjust its scrollbar. You just have to adjust the style to hve a vertical scrollbar (and an horizontal one, it you don't use wrod wrapping).

Also you won't have to uses textout as a TEXTBOX control already know how to draw itself.

If you want, you can make the TEXTBOX read-only so that the user won't be able to modify the text.

Finally, it you would like some formatting then you can uses a Rich text box control or a web browser control (that last one might be harder to use from plain C).
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900