|
|||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionWhat does a When I started to develop the control, I was planning to design a composite control consisting of a static control along with a small button. When clicking the button, a popup window would be displayed where the user could select or unselect the items. The problem was that it took too much code to implement. I wanted the look and feel just like a standard combo box and that was not possible with a reasonable amount of code. So I decided to subclass the combo box. A problem when subclassing the combo box is that you have no window handle to the list portion of the combo box that you may subclass. You only have the combo box window handle and that doesn't help. The trick is to listen to the The code below shows how this is done: BEGIN_MESSAGE_MAP(CCheckComboBox, CComboBox)
...
ON_MESSAGE(WM_CTLCOLORLISTBOX, OnCtlColorListBox)
...
END_MESSAGE_MAP()
...
LRESULT CCheckComboBox::OnCtlColorListBox(WPARAM wParam, LPARAM lParam)
{
// If the listbox hasn't been subclassed yet, do so...
if (m_hListBox == 0) {
HWND hWnd = (HWND)lParam;
if (hWnd != 0 && hWnd != m_hWnd) {
// Save the listbox handle
m_hListBox = hWnd;
// Do the subclassing
m_pWndProc = (WNDPROC)GetWindowLong(m_hListBox, GWL_WNDPROC);
SetWindowLong(m_hListBox, GWL_WNDPROC, (LONG)ComboBoxListBoxProc);
}
}
return DefWindowProc(WM_CTLCOLORLISTBOX, wParam, lParam);
}
After this is done, the rest is fairly straight forward. The Please note that the Since the check mark information is stored in the combo box item data, this may not be used by the application. Setting it to zero unselects the item otherwise it selects the item. But use the It is easy to use this control since it is derived from the MFC Well, I hope someone finds this useful. At least I did.
|
||||||||||||||||||||||||||||||