Neat Tooltip for Combobox

博客围绕VC++中增强类CTTCombobox展开。作者因ComboBox关联工具提示问题,基于网络复杂示例封装该类。介绍了其特点,如不使用分离控件封装;说明了使用方法,包括继承、启用提示、设置延迟时间等;还阐述了实现过程,如创建提示窗口、安装钩子等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Download source files - 6 Kb
Download demo project - 19 Kb

Introduction


I have been ever perplexed by the question which's tool-tip associated with Combo-box,
On the internet I have searched lots of samples about this but these samples look like so complex, some samples that have wrapped the Combo-box using separated controls 'CListbox', 'CEdit', 'CButton', so that corresponding to generate many extra class for the Combo-box that lots of work to maintain the Combo-box. A couple of samples has using hooks for window subclassing that all messages go to new WindowProc(window procedure) before going to the combobox, ummm..., that's very useful. but they still don't be enough simply, thus base upon these samples I have wrapped a enhanced class CTTCombobox, According to expectation there use the new WindowProc to hold up the List-box's messages
and to do too-tip things. BTW, for the enhanced class CTTCombobox, the source files only contain 'TTCombobox.h' and 'TTCombobox.cpp',
that's very easy to embed into your VC++ project.

Noteworthy

The class CTTComboBox isn't wrapped using separated controls 'CListbox', 'CEdit', 'CButton'.

To use

1. The class CTTComboBox is derive from MFC class CCombobox, you can immediately use the class CTTComboBox as well as make new class derive from it.
2. Default, the too-tip is allowed for the combobox(instance with the class CTTComboBox), to enable/disable the too-tip, you need to perform the SetToolTip function before creating or subclassing combobox, details see attached demo project.
3. Using SetToolTipDelay function to set up the appropriate delayed time for show the tool-tip window.

Implementation

As mention above, default the tool-tip is allowed mean m_isEnableTool is TRUE, see codes as follows:

 

We have perform CreateTooltipWnd function that will createa tool-tip window
(note: all combobox with same class CTTComboBox has share a tool-tip window), then we have install hook for subclassing the list-box and edit-box portion of the combobox, see InstallHookForListboxAndEditbox function:

The GetComboBoxInfo function gets the handles to list-box and edit-box, then the SetWindowLong function creates the list-box and edit-box subclass, causing the system to call the new window procedure instead of the previous one, a trick that's all previous(old) window proceduce have been add to map, later we will reuse the old window procedure in new window procedure, such as window proceduce - HookListboxWndProc with the list-box:
At the function ending, we have reuse the old window proceduce via call CallWindowProc function from the map that like chain of window procedures. some messages have been reprocessed for the list-box, In processing the WM_MOUSEMOVE, the HandleListboxMouseMove function determine whether or not the tool-tip window is shown/hidden and the OnTrackMouseEvent function track mouse event messages WM_MOUSEHOVER or WM_MOUSELEAVE, that aim to reset original select of the list-box when fire up WM_MOUSELEAVE, waiting..., the WM_MOUSELEAVE message take continuous place but the mouse cursor still is above the list-box, Actually, the mouse cursor is above the tool-tip window when the tool-tip window show up, think over? so we must capture the list-box to prevent this, to release the mouse capture that only when the tool-tip has been hidden.

Specially, The combobox with owner DropList or DropDown style has a litte trouble, when release the mouse capture, the list-box became invisible.
thus I have hold the WM_CAPTURECHANGED and ignore the message...

Usage

you are allowed to use it for free and further modify it.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值