From: David Hedberg Subject: [PATCH 5/5] comdlg32: Expand the filetype combobox dropdown to fit the contents. Message-Id: <1408840748-21728-5-git-send-email-david.hedberg@gmail.com> Date: Sun, 24 Aug 2014 02:39:08 +0200 --- dlls/comdlg32/comdlg32.rc | 2 +- dlls/comdlg32/itemdlg.c | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/dlls/comdlg32/comdlg32.rc b/dlls/comdlg32/comdlg32.rc index 3118610..d3deeab 100644 --- a/dlls/comdlg32/comdlg32.rc +++ b/dlls/comdlg32/comdlg32.rc @@ -487,7 +487,7 @@ FONT 8, "MS Shell Dlg" EDITTEXT IDC_FILENAME, 226, 240, 100, 12, WS_CHILD | WS_VISIBLE | WS_TABSTOP LTEXT "Files of type:", IDC_FILETYPESTATIC, 160, 256, 60, 9, SS_RIGHT - COMBOBOX IDC_FILETYPE, 226, 256, 100, 12, WS_CHILD | WS_VISIBLE | WS_TABSTOP | + COMBOBOX IDC_FILETYPE, 226, 256, 100, 12, WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | CBS_HASSTRINGS | CBS_DROPDOWNLIST DEFPUSHBUTTON "&Open", IDOK, 350, 240, 40, 14, WS_GROUP diff --git a/dlls/comdlg32/itemdlg.c b/dlls/comdlg32/itemdlg.c index f93f99f..7a71a1e 100644 --- a/dlls/comdlg32/itemdlg.c +++ b/dlls/comdlg32/itemdlg.c @@ -1535,10 +1535,30 @@ static LRESULT on_wm_initdialog(HWND hwnd, LPARAM lParam) hitem = GetDlgItem(This->dlg_hwnd, IDC_FILETYPE); if(This->filterspec_count) { - UINT i; - for(i = 0; i < This->filterspec_count; i++) + HDC hdc; + HFONT font; + SIZE size; + UINT i, maxwidth = 0; + + hdc = GetDC(hitem); + font = (HFONT)SendMessageW(hitem, WM_GETFONT, 0, 0); + SelectObject(hdc, font); + + for(i = 0; i < This->filterspec_count; i++) { SendMessageW(hitem, CB_ADDSTRING, 0, (LPARAM)This->filterspecs[i].pszName); + if(GetTextExtentPoint32W(hdc, This->filterspecs[i].pszName, lstrlenW(This->filterspecs[i].pszName), &size)) + maxwidth = max(maxwidth, size.cx); + } + ReleaseDC(hitem, hdc); + + if(maxwidth > 0) { + maxwidth += GetSystemMetrics(SM_CXVSCROLL) + 4; + SendMessageW(hitem, CB_SETDROPPEDWIDTH, (WPARAM)maxwidth, 0); + } + else + ERR("Failed to calculate width of filetype dropdown\n"); + SendMessageW(hitem, CB_SETCURSEL, This->filetypeindex, 0); } else -- 1.9.1