How to subclass CListBox and CEdit inside of CComboBox (174667)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++, 32-bit Editions 4.0
- Microsoft Visual C++, 32-bit Editions 4.1
- Microsoft Visual C++, 32-bit Enterprise Edition 4.2
- Microsoft Visual C++, 32-bit Professional Edition 4.2
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
This article was previously published under Q174667 SUMMARY
While it is simple to directly subclass a combo box control, it is not
simple to subclass the edit or list box inside a combo box. The problem is
that it is difficult to get the HWNDs of the child controls in a portable
manner.
One safe way to subclass the internal edit and list box controls is to
subclass them in the WM_CTLCOLORXXX messages. Because Win32 sends separate
WM_CTLCOLOREDIT and WM_CTLCOLORLISTBOX messages, these messages are safe
and easy ways to get the HWNDs of the child controls of the combo box.
Below is a CSuperComboBox class, which is an MFC implementation of this
method. Because MFC routes all the WM_CTLCOLOR messages to OnCtlColor, the
subclassing takes place there.
Modification Type: | Major | Last Reviewed: | 9/1/2005 |
---|
Keywords: | kbcode kbComboBox kbCtrl kbhowto KbUIDesign KB174667 kbAudDeveloper |
---|
|