List Box ---如何添加水平滚动条

VC ListBox列表框实现自动水平滚动功能 利用CListBox::SetHorizontalExtent()成员可实现该功能。网上可行的方法主要是添加一个CListBox的派生类,并重载其AddString, InsertString方法。虽然使用方便,但是额外添加一个类。本文在不添加派生类的情况下实现该功能。 1. 首先建立一个对话框CMyDlg的应用程序,添加一个列表框、三个按钮(添加、编辑、删除),列表框右键属性-》Horizon... 阅读详情

前段时间做了一个DLL,输出一个Dialog,里面的ListBox用到了水平滚动条.

VC6.0中作出来水平滚动条无法自动做,网上Google了一吧,www.codeguru.com中有偏文章很是好用.

转贴到这里:

http://www.codeguru.com/cpp/controls/listbox/article.php/c4759/

Overview

CListBox: This is a wrapper class for the ListBox control, and it's used in almost every application. There is a little "gotcha" to this class: The horizontal scroll bar doesn't work. Okay, I created it with the WS_HSCROLL flag set, the scroll bar is visible, and strings that I'm adding to the box are obviously longer then the box's horizontal extent, but I'm unable to scroll. What's wrong?

My theory is that the guy who originally implemented that control had way too much Greek mythology in his childhood. Villainous Procrustes and his bed where he had to cut off travelers' legs if they didn't fit in had a huge impact on the poor guy. If something is too long, chop it off. Well, whatever the reason is, the control simply ignores the fact that the strings are longer then it can show. How can we fix it?

Well, first, we have to catch all messages sent to the control that affect the box's content, hence the strings that it has (behind such functions as AddString() or ResetContent(), is SendMessage() with LB_ADDSTRING and LB_RESETCONTENT respectively). There are five messages of that type (at least that's the number I've come with. There may be more; I'm not sure.). Once they are identified, they can be caught and modified the same way as the others:

  • LB_ADDSTRING
  • LB_INSERTSTRING
  • LB_DELETESTRING
  • LB_DIR
  • LB_RESETCONTENT

After the control is subclassed, we can catch any message that is sent to it through the control's message map:

...
BEGIN_MESSAGE_MAP(CHScrollListBox, CListBox)
  //{{AFX_MSG_MAP(CHScrollListBox)
  // NOTE - the ClassWizard will add and remove mapping macros here.
  //}}AFX_MSG_MAP
  ON_MESSAGE(LB_ADDSTRING, OnAddString)
  ON_MESSAGE(LB_INSERTSTRING, OnInsertString)
  ON_MESSAGE(LB_DELETESTRING, OnDeleteString)
  ON_MESSAGE(LB_DIR, OnDir)
  ON_MESSAGE(LB_RESETCONTENT, OnResetContent)
END_MESSAGE_MAP()
...

When we catch the message (for example, LB_ADDSTRING), we are going to call default processing first, and, if the returned code is okay (most of these messages return some kind of a completion indicator), call our functions, either SetNewHExtent() or ResetHExtent(), that will bring the horizontal extent member of ListBox (this is the parameter that affects the horizontal scroll bar, if the bar is present) in sync with the longest string that it contains:

...
////////////////////////////////////////////////////////////////
// OnAddString: wParam - none, lParam - string, returns - int
////////////////////////////////////////////////////////////////
LRESULT CHScrollListBox::OnAddString(WPARAM wParam, LPARAM lParam)
{
  LRESULT lResult = Default();
  if (!((lResult == LB_ERR) || (lResult == LB_ERRSPACE)))
    SetNewHExtent((LPCTSTR) lParam);
  return lResult;
}
...

SetNewHExtent() in turn will calculate in pixels the length of the supplied string in the given device context (GetTextLen()) and set a new horizontal extent for the control. The extent can be set through CListBox::SetHorizontalExtent(extent) and we do it only if it's bigger then the current extent:

...
////////////////////////////////////////////////////////////////
void CHScrollListBox::SetNewHExtent(LPCTSTR lpszNewString)
{
  int iExt = GetTextLen(lpszNewString);
  if (iExt > GetHorizontalExtent())
    SetHorizontalExtent(iExt);
}
...

Let's take a look at what GetTextLen() does:

...
int CHScrollListBox::GetTextLen(LPCTSTR lpszText)
{
  ASSERT(AfxIsValidString(lpszText));

  CDC *pDC = GetDC();
  ASSERT(pDC);

  CSize size;
  CFont* pOldFont = pDC->SelectObject(GetFont());
  if ((GetStyle() & LBS_USETABSTOPS) == 0)
  {
    size = pDC->GetTextExtent(lpszText, (int) _tcslen(lpszText));
    size.cx += 3;
  }
  else
  {
    // Expand tabs as well
    size = pDC->GetTabbedTextExtent(lpszText, (int)
          _tcslen(lpszText), 0, NULL);
    size.cx += 2;
  }
  pDC->SelectObject(pOldFont);
  ReleaseDC(pDC);

  return size.cx;
}
...

The first call is a sanity check with AfxIsValidString(). Then we get the control's DC through GetDC() and select the control's font in the context. After that, we look at the styles. If LBS_USETABSTOPS is set, we call GetTabbedTextExtent(); otherwise, it's GetTextExtent(), which returns the number of pixels that the specified string will occupy on the screen in a horizontal direction when drawn in that device context. I add a few more pixels here, just to make sure the string looks symmetrical when displayed, because the box has a margin on the left. That's it.

In calls OnDeleteString() and OnDir(), I use the function named ResetHExtent(). Because I do not know what string has the next longest extent from the one I'm deleting and since OnDir() will reset the content and fill it in with directory or file names, I'm simply going through the whole list, looking for the longest string the list has and setting its extent.

 

Usage

Okay, how one can utilize CHScrollListBox class? Here are some steps to take, sort of manual labor, that will get you there:

  1. In the resource editor, create a dialog template that will host a listbox control.
  2. Set properties of the list box according to the picture above (at least, Horizontal Scroll, Selection, and Owner Draw should match).
  3. In the header file of your dialog's class, associated with the template, add:
    #include "HScrollListBox.h"
  4. Define a member variable of CHScrollListBox, like so:
    CHScrollListBox m_listBox;
  5. In the implementation file, in DoDataExchange() function, add a line:
    DDX_Control(pDX, IDC_YOUR_LISTBOX_CTRL_ID, m_listBox);
    This call in turn calls SubclassDlgItem(), which does the trick of routing all messages destined to the control to our message map.

Of course, IDC_YOUR_LISTBOX_CTRL_ID and m_listBox are orbitrary names; you should use your own instead.

 

任务17:Box组件和List组件的组合使用实现排行榜 文章目录一、任务目标二、任务分解2.1 如何让Box容器在List下渲染多个2.2 List常用属性的介绍2.3 Box常用属性的介绍2.4 排行榜示例三、参考资料 一、任务目标 从继承关系上来说,List组件是继承自Box组件的,但是从使用上来说,List组件是作为Box组件的父容器使用的,当我们需要将多个同类组件组合起来的时候,比如游戏中的排行榜,Box和List就派上了用场。 每个玩家的基本信息有头像,排名,得分,昵称等,将显示这些信息的组件放入一个Box容器中,如果此时我们希望节省一些力气,那么复制 阅读详情

相关推荐

UE4 UMG Scroll Box实战:打造高性能可滚动UI布局与优化指南

在游戏开发与交互界面设计中,可滚动容器是处理内容溢出的基础解决方案,其核心原理是通过视口裁剪与动态加载机制,仅渲染可见区域内容以优化性能。从技术价值看,高效的滚动实现直接关系到应用的流畅度与用户体验,尤其在数据密集型场景如游戏背包、列表视图中至关重要。在UE4的UMG框架下,Scroll Box控件正是这一理念的工程实践载体,它通过方向控制、滚动行为参数(如惯性滚动)与裁剪优化,为复杂UI布局提供了灵活支持。本文聚焦于Scroll Box的实战配置与性能调优,深入解析如何结合ListView实现动态条目复用

weixin_30542079的博客 423

为List组件添加可随内容变化的滚动条

 http://www.adobe.com/2006/mxml" creationComplete="init();">      import mx.collections.ArrayCollection;                  [Bindable]         private var listData:ArrayCollection = new ArrayCollecti

待定的专栏 1153

VB在ListBox列表上增加水平滚动条的功能

内容索引:VB源码,报表打印,ListBox,滚动条  VB在ListBox列表上增加一个水平滚动条的功能,这样更方便于用户的操作,大家都知道,原有的listbox控件一般都没有自带这种功能,这样将ListBox里的文字比较多时,就会被隐藏,如果有了滚动条,用户就可以拖动滚动条将内容阅读完,也算是扩展了一下ListBox的功能吧。

C++ List Box新增水平滚动条功能

1、在MFC里面先定义一个List Box对象,再在类里面关联一个对象变量class CDlg_Multi : public CDialog{public:CListBox    m_ListInfo;......}2、在初始化成员函数里:BOOL CDlg_Multi::OnInitDialog(){......    m_ListInfo.SetHorizontalExtent(1000); ...

weixin_40407666的博客 673

一步步指导:在Chrome中安装Vue插件vue-devtools

Vue.js是现代Web开发中最流行的前端框架之一,它以其轻量级、高性能和易于理解的设计理念受到开发者的喜爱。为了更高效地开发和调试Vue应用,Vue.js官方提供了一个强大的开发工具——vue-devtools。

小透明的博客 5626

Trae+Playwright MCP自动化测试全流程指南:从环境搭建到智能体运行

本文提供了一份详细的Trae与Playwright MCP集成指南,涵盖从Node.js、Python环境搭建到智能体创建的全流程。通过结合MCP协议,AI智能体能够理解任务并驱动Playwright执行复杂的浏览器自动化操作,实现从网页数据抓取到端到端测试的智能工作流。

banana的博客 534

给 MHTML 添加滚动条.mhtml

摘要:本文提供了两种MHTML文件显示问题的解决方案。针对缺少滚动条的问题,建议在HTML头部添加CSS样式强制为根元素和body添加滚动条,并提供调试建议。对于水平宽度不足的问题,提供了扩展宽度并添加垂直滚动条的CSS方案,包括重置布局、移除宽度限制和确保内容换行等样式。两种方案都详细说明了具体添加位置,并提供了备选方案和调试方法,帮助用户优化MHTML文件的显示效果。

tiandyoin的专栏 842

Python实现支付宝转账接口

由于工作需要使用python开发一个自动转账接口,记录一下开发过程。 首先需要在蚂蚁金服上申请开通开发者账户,有了开发者账户就可以使用沙箱进行开发了。 在开发之前我们需要在沙箱应用中填写密钥,密钥的获取可以使用阿里提供的工具包自动生成。 前期准备工作完成了,接下来是编写代码部分。主要用到了python-alipay-sdk库,使用pip安装即可,如果安装的过程中遇到问题推荐使用Anaconda...

FanMLei的博客 8519

List Box 控件的水平滚动

在接收数据的时候,自动设置水平显示的长度  CSize   sz;  CPaintDC   dc(this);  sz=dc.GetTextExtent(str);  if(m_list_width  {   m_list_width=sz.cx + 100;   m_list_recv2.SendMessage(LB_SETHORIZONTALEXTENT,m_list_widt

badboyccj的专栏 533

工业视觉中HDR算法的动态范围优化与Debevec/Mertens方法实践

本文深入探讨了工业视觉中HDR(高动态范围)成像技术,重点解析了Debevec和Mertens两种核心算法。针对工业场景中因动态范围不足导致的过曝与欠曝问题,文章详细对比了两种方法的原理、实现步骤、参数调优及适用场景,为工程师在静态检测与高速产线等不同需求下,选择并实践HDR算法提供了清晰的指导。

weixin_29099217的博客 198

Armbian 国内源一键配置:告别卡顿,加速软件更新

本文详细介绍了如何为Armbian系统配置国内软件源,以解决默认国外源导致的更新缓慢、连接超时等问题。通过手动修改配置文件或使用高效的一键换源脚本,可将源切换至清华大学、阿里云等国内镜像站,实现apt更新与软件安装速度的质的飞跃,让Armbian开发体验更加流畅高效。

weixin_29215815的博客 251

MFC中List box的用法

List Box应该是同时具有Edit Control和Combo Box的一些特性.说它像前者因为它可以把所有的内容分行显示出来(但不可编辑),所以一般起显示信息的作用.而Edit Control主要是让用户输入信息,它也可以让用户输入多行信息,要是把它设成Read Only的话初看起来跟List Box样子还真像的. 另外嘛List Box有类似Combo Box的一些操作,比如Ad

曲终人散 8780

路径跟踪 | 图解路径跟踪PID算法(附ROS C++/Python/Matlab仿真)

PID控制是一种经典的控制算法,广泛应用于各种工业场景。在基于PID的局部路径规划中,希望机器人能快速跟踪上预设的轨迹。本文介绍PID控制的基本原理,并基于PID控制律设计路径跟踪算法,最后通过ROS C++/Python/Matlab进行仿真实现,加深理解

FRIGIDWINTER的博客 1万+

修改滚动条

css3修改滚动条的样式 修改某个div的滚动条默认样式: #search-list::-webkit-scrollbar-track { border-radius: 10px; background-color: #F5F5F5; } #search-list::-webkit-scrollbar { width: 14px; background-color: #F5F5F5; }...

努力让自己幸运... 286

打通ZYNQ的任督二脉:AXI_FIFO数据交互全解析

FIFO(First In First Out,先进先出)是一种经典的数据缓冲结构,就像排队买票一样,先来的人先得到服务。时钟域交叉(CDC):连接不同时钟频率的模块数据缓冲:平衡生产者和消费者的速度差异流量控制:防止数据丢失或溢出input clk,// 输入AXI4-Stream接口(从PS到PL)// 输出AXI4-Stream接口(从PL到PS)// 状态指示信号// 定义状态机状态// 数据缓存// 8个深度的缓存// 流水线处理寄存器。

QQ_778132974的博客 310

Visual Studio Code ADT Extension 能不能连接 ECC,答案是可以,但真正的门槛在 ABAP 后端版本

Visual Studio Code 版 ABAP Development Tools(ADT)支持连接传统 SAP ECC 系统,关键不在于系统名称,而在于底层 SAP NetWeaver AS ABAP 版本是否达到最低要求(7.31 SP04 及以上)。只要系统已支持 Eclipse ADT,即可无缝使用 VS Code ADT,无需升级后端。SAP 通过复用原有 ADT 技术栈,将兼容性逻辑置于客户端,实现对老系统的持续支持。尽管初期侧重 ABAP Cloud 模型,但 1.1 及后续版本已全面覆盖

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 73

List Box 消息

 LBS_EXTENDEDSEL       使用键盘“SHIFT”键或另指定键加鼠标进行多选。就是VC  RC 编辑器上的 Selection 里面选上ExtendedLBS_MULTICOLUMN       多列列表框,带有水平滚动条。应用程序可以用 LB_SETCOLUMNWIDTH 消息来为列表框指定列数。 LBS_MULTIPLESEL       支持多重选择。LBS

The past will never return. 646

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

VC++ List Box 控件 详解2

文章内容摘要: ListBox控件的使用 ListBox窗户用来列出一系列的文本,每条则本占一行。创建一个列表窗户可使用成员函数: BOOL CListBox::Create( LPCTSTR lpszText, DWORD dwStyle, const RECT rect, CWnd* pParentWnd, UINT nID = 0xffff ); 其中dwStyle将指明该窗户的风 Lis

1152

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

MFC控件(4):List Box

List Box应该是同时具有Edit Control和Combo Box的一些特性.说它像前者因为它可以把所有的内容分行显示出来(但不可编辑),所以一般起显示信息的作用.而Edit Control主要是让用户输入信息,它也可以让用户输入多行信息,要是把它设成Read Only的话初看起来跟List Box样子还真像的. 另外嘛List Box有类似Combo Box的一些操作,比如AddStr...

weiwenhp 9604

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

asp.net中给listbox添加横向滚动条

经常在listbox中的数据项太长而不能看完,系统本身是有纵向滚动条,只能是对多项数据项有效,而如果太长,则只能自己解决,一种解决办法:<div id='hello' style="z-index: 102; left: 240px; overflow: auto; width: 300px; top: 70px;height: 200px"><asp:ListBox ID="l...

weixin_30457551的博客 212

【Laya 教程】经典UI List 使用方式

LayaAir List组件使用教程摘要 本教程详细介绍了LayaAir 3.3中List列表组件的使用方法。主要内容包括: List组件概述:介绍List作为高性能列表组件的特点,包括虚拟列表技术、滚动支持和数据绑定等核心功能。 创建方法: 通过IDE创建:设置列表项模板、滚动属性和数据源绑定 通过代码创建:自定义列表项渲染器,设置滚动类型和数据源 关键特性: 支持垂直/水平滚动 数据源与单元格自动绑定 提供渲染处理器、选择处理器和鼠标事件处理器 支持橡皮筋回弹效果 实战应用: 展示20个项目的列表 自定

孟无岐的博客 1254
上一篇: 遁去的"一"
下一篇: SuSe上配置samba笔记
台风双头蛇
博客等级 码龄26年 7粉丝 13原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址