//VC++裡是這樣轉的 我試過是可以的 把這段代碼轉成Delphi就可以.<br>void CDlg::ConvertDialogUnitsToPixels(LPCTSTR pszFontFace, WORD wFontSize,<br> int cxDlg, int cyDlg, SIZE* pSizePixel)<br>{<br> // Attempt to create the font to be used in the dialog box<br> UINT cxSysChar, cySysChar;<br> LOGFONT lf;<br> HDC hDC = ::GetDC(NULL);<br> memset(&lf, 0, sizeof(LOGFONT));<br> lf.lfHeight = -MulDiv(wFontSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);<br> lf.lfWeight = FW_NORMAL;<br> lf.lfCharSet = DEFAULT_CHARSET;<br> lstrcpy(lf.lfFaceName, pszFontFace);<br><br> HFONT hNewFont = CreateFontIndirect(&lf);<br> if (hNewFont != NULL)<br> {<br> HFONT hFontOld = (HFONT)SelectObject(hDC, hNewFont);<br> TEXTMETRIC tm;<br> GetTextMetrics(hDC, &tm);<br> cySysChar = tm.tmHeight + tm.tmExternalLeading;<br> SIZE size;<br> ::GetTextExtentPoint32(hDC,<br> _T("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"), 52,<br> &size);<br> cxSysChar = (size.cx + 26) / 52;<br> SelectObject(hDC, hFontOld);<br> DeleteObject(hNewFont);<br> }<br> else<br> {<br> // Could not create the font so just use the system's values<br> cxSysChar = LOWORD(GetDialogBaseUnits());<br> cySysChar = HIWORD(GetDialogBaseUnits());<br> }<br> ::ReleaseDC(NULL, hDC);<br><br> // Translate dialog units to pixels<br> pSizePixel->cx = MulDiv(cxDlg, cxSysChar, 4);<br> pSizePixel->cy = MulDiv(cyDlg, cySysChar, 8);<br>}<br><br>//Delphi<br>procedure ConvertDialogUnitsToPixels(FontFace : PChar; wFontSize : WORD;<br> cxDlg, cyDlg : Integer; var SizePixel : TSize);<br>var<br> cxSysChar, cySysChar : UINT;<br> lf : LOGFONT;<br> hFontOld, hNewFont, hDC : THandle;<br> tm : TTextMetric;<br> size : TSize;<br>begin<br> hDC := GetDC(0);<br> FillChar(lf, sizeof(LOGFONT), 0);<br> lf.lfHeight := -MulDiv(wFontSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);<br> lf.lfWeight := FW_NORMAL;<br> lf.lfCharSet:= DEFAULT_CHARSET;<br> lstrcpy(lf.lfFaceName, FontFace);<br><br> hNewFont := CreateFontIndirect(lf);<br> if hNewFont <> 0 then<br> begin<br> hFontOld := SelectObject(hDC, hNewFont);<br> GetTextMetrics(hDC, tm);<br> cySysChar := tm.tmHeight + tm.tmExternalLeading;<br> GetTextExtentPoint32(hDC,<br> 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', 52,<br> size);<br> cxSysChar := (size.cx + 26) div 52;<br> SelectObject(hDC, hFontOld);<br> DeleteObject(hNewFont);<br> end<br> else<br> begin<br> cxSysChar := LOWORD(GetDialogBaseUnits());<br> cySysChar := HIWORD(GetDialogBaseUnits());<br> end;<br> ReleaseDC(0, hDC);<br><br> SizePixel.cx := MulDiv(cxDlg, cxSysChar, 4);<br> SizePixel.cy := MulDiv(cyDlg, cySysChar, 8);<br>end;