Hãy xem xét mã bên dưới nơi có 2 loại hộp tổ hợp khác nhau được tạo (WC_COMBOBOX và WC_COMBOBOXEX), rồi mỗi hộp được gắn một đầu công cụ.Thêm chú giải công cụ vào một ComboBoxEx không thành công
Mẹo công cụ cho WC_COMBOBOX hoạt động như mong đợi, nhưng WC_COMBOBOXEX không hiển thị đầu công cụ.
Sự cố là gì?
BOOL TooltipDlg_OnInitDialog(HWND hWndDialog, HWND hWndFocus, LPARAM lParam)
{
// Load and register Tooltip, ComboBox, ComboBoxEx control classes
INITCOMMONCONTROLSEX iccx;
iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
iccx.dwICC = ICC_WIN95_CLASSES | ICC_USEREX_CLASSES;
if (!InitCommonControlsEx(&iccx))
return FALSE;
// Create combo boxes
const int idc_ComboBox = 1000;
const int idc_ComboBoxEx = 1001;
{
// create WC_COMBOBOX
CreateWindow(WC_COMBOBOX, NULL,
WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST,
40, 80,
100, 20,
hWndDialog, (HMENU)idc_ComboBox, g_hInst,
NULL);
// create WC_COMBOBOXEX
CreateWindowEx(0, WC_COMBOBOXEX, NULL,
WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST,
40, 110,
100, 20,
hWndDialog, (HMENU)(idc_ComboBoxEx), g_hInst,
NULL);
}
// Create tooltip
g_hwndTooltip = CreateWindowEx(0, TOOLTIPS_CLASS, L"",
TTS_ALWAYSTIP,
0, 0, 0, 0,
hWndDialog, 0, g_hInst, 0);
// attach the tooltip to controls
{
TOOLINFO ti;
ti.cbSize = sizeof(ti);
ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
// attach to idc_ComboBox -- works fine
ti.uId = (UINT_PTR)GetDlgItem(hWndDialog, idc_ComboBox);
ti.lpszText = L"This is tooltip for WC_COMBOBOX.";
SendMessage(g_hwndTooltip, TTM_ADDTOOL, 0, (LPARAM)&ti);
// attach to idc_ComboBoxEx -- does NOT work: no tooltip displayed
ti.uId = (UINT_PTR)GetDlgItem(hWndDialog, idc_ComboBoxEx);
ti.lpszText = L"This is tooltip for WC_COMBOBOXEX.";
SendMessage(g_hwndTooltip, TTM_ADDTOOL, 0, (LPARAM)&ti);
}
return TRUE;
}