Neat Tooltip for Combobox

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


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.


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.


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...


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

发布了116 篇原创文章 · 获赞 1 · 访问量 30万+


©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客