diff --git a/dlls/user/controls.h b/dlls/user/controls.h index a352d18a8ba..76271fb37d2 100644 --- a/dlls/user/controls.h +++ b/dlls/user/controls.h @@ -148,7 +148,6 @@ typedef struct #define DWLP_WINE_DIALOGINFO (DWLP_USER+sizeof(ULONG_PTR)) extern DIALOGINFO *DIALOG_get_info( HWND hwnd, BOOL create ); -extern BOOL DIALOG_GetCharSize( HDC hdc, HFONT hFont, SIZE * pSize ); extern void DIALOG_EnableOwner( HWND hOwner ); extern BOOL DIALOG_DisableOwner( HWND hOwner ); extern INT DIALOG_DoDialogBox( HWND hwnd, HWND owner ); diff --git a/dlls/user/dialog.c b/dlls/user/dialog.c index a9ad30e4152..7bc90f2c4e2 100644 --- a/dlls/user/dialog.c +++ b/dlls/user/dialog.c @@ -143,38 +143,6 @@ BOOL DIALOG_DisableOwner( HWND hOwner ) return FALSE; } -/*********************************************************************** - * DIALOG_GetCharSize - * - * Despite most of MSDN insisting that the horizontal base unit is - * tmAveCharWidth it isn't. Knowledge base article Q145994 - * "HOWTO: Calculate Dialog Units When Not Using the System Font", - * says that we should take the average of the 52 English upper and lower - * case characters. - */ -BOOL DIALOG_GetCharSize( HDC hDC, HFONT hFont, SIZE * pSize ) -{ - HFONT hFontPrev = 0; - const char *alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; - SIZE sz; - TEXTMETRICA tm; - - if(!hDC) return FALSE; - - if(hFont) hFontPrev = SelectObject(hDC, hFont); - if(!GetTextMetricsA(hDC, &tm)) return FALSE; - if(!GetTextExtentPointA(hDC, alphabet, 52, &sz)) return FALSE; - - pSize->cy = tm.tmHeight; - pSize->cx = (sz.cx / 26 + 1) / 2; - - if (hFontPrev) SelectObject(hDC, hFontPrev); - - TRACE("dlg base units: %ld x %ld\n", pSize->cx, pSize->cy); - return TRUE; -} - - /*********************************************************************** * DIALOG_GetControl32 * @@ -532,11 +500,14 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate, if (hUserFont) { SIZE charSize; - if (DIALOG_GetCharSize( dc, hUserFont, &charSize )) + HFONT hOldFont = SelectObject( dc, hUserFont ); + charSize.cx = GdiGetCharDimensions( dc, NULL, &charSize.cy ); + if (charSize.cx) { xBaseUnit = charSize.cx; yBaseUnit = charSize.cy; } + SelectObject( dc, hOldFont ); } ReleaseDC(0, dc); TRACE("units = %d,%d\n", xBaseUnit, yBaseUnit ); @@ -1439,7 +1410,8 @@ DWORD WINAPI GetDialogBaseUnits(void) if ((hdc = GetDC(0))) { - if (DIALOG_GetCharSize( hdc, 0, &size )) units = MAKELONG( size.cx, size.cy ); + size.cx = GdiGetCharDimensions( hdc, NULL, &size.cy ); + if (size.cx) units = MAKELONG( size.cx, size.cy ); ReleaseDC( 0, hdc ); } TRACE("base units = %d,%d\n", LOWORD(units), HIWORD(units) ); diff --git a/dlls/user/dialog16.c b/dlls/user/dialog16.c index d506c1bedb3..bdde9d2d63b 100644 --- a/dlls/user/dialog16.c +++ b/dlls/user/dialog16.c @@ -333,11 +333,14 @@ static HWND DIALOG_CreateIndirect16( HINSTANCE16 hInst, LPCVOID dlgTemplate, if (dlgInfo->hUserFont) { SIZE charSize; - if (DIALOG_GetCharSize( dc, dlgInfo->hUserFont, &charSize )) + HFONT hOldFont = SelectObject( dc, dlgInfo->hUserFont ); + charSize.cx = GdiGetCharDimensions( dc, NULL, &charSize.cy ); + if (charSize.cx) { dlgInfo->xBaseUnit = charSize.cx; dlgInfo->yBaseUnit = charSize.cy; } + SelectObject( dc, hOldFont ); } ReleaseDC(0, dc); TRACE("units = %d,%d\n", dlgInfo->xBaseUnit, dlgInfo->yBaseUnit ); diff --git a/dlls/user/menu.c b/dlls/user/menu.c index b1f29987f3a..913fbbbaffe 100644 --- a/dlls/user/menu.c +++ b/dlls/user/menu.c @@ -860,7 +860,9 @@ static void MENU_CalcItemSize( HDC hdc, MENUITEM *lpitem, HWND hwndOwner, MEASUREITEMSTRUCT mis; /* not done in Menu_Init: GetDialogBaseUnits() breaks there */ if( !menucharsize.cx ) { - DIALOG_GetCharSize( hdc, hMenuFont, &menucharsize ); + HFONT hOldFont = SelectObject( hdc, hMenuFont ); + menucharsize.cx = GdiGetCharDimensions( hdc, NULL, &menucharsize.cy ); + SelectObject( hdc, hOldFont ); /* Win95/98/ME will use menucharsize.cy here. Testing is possible * but it is unlikely an application will depend on that */ ODitemheight = HIWORD( GetDialogBaseUnits());