Adding a tooltip to ComboBoxEx fails

Consider the code below, where 2 different types of combo boxes (WC_COMBOBOX and WC_COMBOBOXEX) are created, and then each is attached to the tooltip.

The tool for WC_COMBOBOX works as expected, but WC_COMBOBOXEX does not display the tooltip.

What is the problem?

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;
}
+6
source share
1 answer

WC_COMBOBOXEX 2 - , , , , . . CBEM_GETCOMBOCONTROL. :

    HWND hwndCBex = CreateWindowEx(0, WC_COMBOBOXEX, ...);
    ti.uId = (UINT_PTR)SendMessage(hwndCBex, CBEM_GETCOMBOCONTROL, 0, 0);
    ti.lpszText = L"This is tooltip for WC_COMBOBOXEX.";
    SendMessage(g_hwndTooltip, TTM_ADDTOOL, 0, (LPARAM)&ti);  
+5

All Articles