动态增加滚动条的大小 [英] dynamic Increase in the size of a scroll bar

查看:95
本文介绍了动态增加滚动条的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的老年人,
我想知道在输出窗口中动态增加垂直滚动条大小的机制.

例如:我想输入一个文件名并显示它的内容.但是,每次用户输入不同的文件名时,文件的长度也会更改.因此滚动条的长度每次都会改变.
请为我建议一种实现上述方法的方法.

我的方法:
步骤1
------
我已经预定义了要显示的总行数,如下所示

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


步骤2
------
我在WM_SIZE中使用以下内容:


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 );


步骤3
------


Step-3
------

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



但是上述过程已固定为预设的预定义宏MAXLINES,该宏为100,最多只能打印100行,但不能打印更多行.

语言:使用Win32 API的C(仅).
编译器:VC ++

问候,
Kiran.



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.

推荐答案

为什么不使用TEXTBOX控件并设置适当的样式?

TEXTBOX已经知道如何调整其滚动条.您只需要调整样式即可使其具有垂直滚动条(水平滚动条,而无需使用粗线包装).

同样,您也不必使用textout,因为TEXTBOX控件已经知道如何绘制自身.

如果需要,可以将TEXTBOX设为只读,以便用户无法修改文本.

最后,您需要某种格式,然后可以使用Rich Text Box控件或Web浏览器控件(可能很难从纯C语言使用最后一个).
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).


1)替换您的宏带有变量(行数).

2)加载文件时,请计算行数.

3)更新包含行数的变量,并重置另一个变量,该变量用于显示的第一行的索引.

4)您应该在加载文件时而不是在WM_SIZE中更新滚动条信息(如果您进行自动换行并需要从分行开始),则可能仍需要WM_SIZE处理程序.

有关滚动信息所需的精确计算,请参见MSDN文档.
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.


这篇关于动态增加滚动条的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆