How do I get the dropped height of a combo box?

Raymond Chen

Via the Suggestion Box, commenter Twisted Combo responds to an old blog entry on why the size of a combo box includes the height of the drop-down by asking, But how do I *get* the dropped down height?”

By using the deviously-named CB_GETDROPPEDCONTROLRECT message, which the windowsx.h header file wraps inside the ComboBox_GetDroppedControlRect macro.

Start with the scratch program and make these changes:

OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
  g_hwndChild = CreateWindow(
      TEXT("combobox"), NULL, WS_CHILD | WS_VISIBLE |
      0, 0, 500, 500, hwnd, (HMENU)1, g_hinst, 0);
  ComboBox_AddString(g_hwndChild, TEXT("First"));
  ComboBox_AddString(g_hwndChild, TEXT("Second"));
  ComboBox_AddString(g_hwndChild, TEXT("Third"));
  ComboBox_AddString(g_hwndChild, TEXT("Fourth"));
  TCHAR szBuf[200];
  RECT rcWindow;
  GetWindowRect(g_hwndChild, &rcWindow);
  RECT rcDrop;
  ComboBox_GetDroppedControlRect(g_hwndChild, &rcDrop);
  wsprintf(szBuf, TEXT("window height %d, dropdown height %d"),
    rcWindow.bottom -, rcDrop.bottom -;
  SetWindowText(hwnd, szBuf);
  return TRUE;

The actual results will naturally vary depending on your system configuration, but when I ran this program, the window caption said “24 / 500”.


Discussion is closed.

Feedback usabilla icon