2012-04-26 67 views
1

我想爲一些定製原因子類化組合框的列表框和編輯控件。以下是代碼工作。編輯控件的子類化工作正常,但Listbox沒有獲取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; 
} 

回答

1

ComboBox的列表框部分是類型COMBOLBOX(與L-)的。

ComboLBox窗口不是ComboBox窗口的子項。 我發現子類COMBOLBOX控件的唯一方法如下。

在繪製列表框之前,Windows將WM_CTLCOLORLISTBOX消息發送到COMBOBOX(no L)。該消息的lParam包含列表框的句柄。

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

Alsoo看到這個link以獲取更多信息