1

I am trying to Subclass the Listbox and the Edit Control of a Combobox for some customasing reasons. Below is the code work . Subclassing for Edit Control is working perfect but Listbox is not getting the messeage of MouseDown.

void Subclass(HWND hComboBox)
{
    HWND hEdit=FindWindowEx(hComboBox, NULL, WC_EDIT, NULL);
    HWND hCombo=FindWindowEx(hComboBox, NULL, WC_LISTBOX, NULL);
    SetProp(hEdit, TEXT("Wprc"), (HANDLE)GetWindowLongPtr(hEdit, GWL_WNDPROC));
    SubclassWindow(hEdit, ComboBox_Proc);
    SetProp(hCombo, TEXT("Wprc1"), (HANDLE)GetWindowLongPtr(hCombo, GWL_WNDPROC));
    SubclassWindow(hCombo, ComboBox_Proc1);
}


static LRESULT CALLBACK ComboBox_Proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{

    switch(msg)
    {
        case WM_CHAR:
            break;
        case WM_KEYDOWN:
            break;
        case WM_DESTROY:
            SetWindowLongPtr(hwnd, GWLP_WNDPROC, (DWORD)GetProp(hwnd, TEXT("Wprc")));
            RemoveProp(hwnd, TEXT("Wprc"));
            break;
        default:
            return CallWindowProc((WNDPROC)GetProp(hwnd, TEXT("Wprc")), hwnd, msg, wParam, lParam);
    }
    return FALSE;
}

static LRESULT CALLBACK ComboBox_Proc1(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 {
    switch(msg)
    {
        case WM_LBUTTONDOWN:
          //PROBLEM IS HERE
            break;
        case WM_DESTROY: 
            SetWindowLongPtr(hwnd, GWLP_WNDPROC, (DWORD)GetProp(hwnd, TEXT("Wprc1")));
            RemoveProp(hwnd, TEXT("Wprc1"));
            break;
        default:
            return CallWindowProc((WNDPROC)GetProp(hwnd, TEXT("Wprc1")), hwnd, msg, wParam, lParam);
    }
    return FALSE;
}
Shegit Brahm
  • 725
  • 2
  • 9
  • 22
Murat Tutu
  • 41
  • 2
  • 4

2 Answers2

1

The ListBox part of a ComboBox is of type COMBOLBOX (with L).

The ComboLBox window is not a child of the ComboBox window. The only way I found to subclass the COMBOLBOX control is as follows.

Windows sends the WM_CTLCOLORLISTBOX message to the COMBOBOX (no L) before the listbox is drawn. The lParam of this message contains the handle of the listbox.

 case  WM_CTLCOLORLISTBOX:
 {       
    if ( !hSubclassedListBox ) 
    { 
        hSubclassedListBox = (HWND)lParam; 
        SubclassWindow(hSubclassedListBox , MyLBProc);
    }
 }

Alsoo see this link for more information

Flot2011
  • 4,601
  • 3
  • 44
  • 61
1

For those who are using Visual Studio with WINVER set to 0500 or higher (Windows XP or later), you can use the GetComboBoxInfo function (passing the handle to the ComboBox), which will return (in a COMBOBOXINFO structure) the handles to both the Edit box and the ComboLBox (ListBox). The handles can then be used to get the CWnd-derived objects they represent.