void DuiPixelToHiMetric(const SIZEL * lpSizeInPix, LPSIZEL lpSizeInHiMetric) { int nPixelsPerInchX; // Pixels per logical inch along width int nPixelsPerInchY; // Pixels per logical inch along height HDC hDCScreen = GetDC(NULL); nPixelsPerInchX = GetDeviceCaps(hDCScreen, LOGPIXELSX); nPixelsPerInchY = GetDeviceCaps(hDCScreen, LOGPIXELSY); ReleaseDC(NULL, hDCScreen); lpSizeInHiMetric->cx = MAP_PIX_TO_LOGHIM(lpSizeInPix->cx, nPixelsPerInchX); lpSizeInHiMetric->cy = MAP_PIX_TO_LOGHIM(lpSizeInPix->cy, nPixelsPerInchY); }
static void PixelToHiMetric(const SIZEL* lpSizeInPix, LPSIZEL lpSizeInHiMetric) { #define HIMETRIC_PER_INCH 2540 #define MAP_PIX_TO_LOGHIM(x,ppli) MulDiv(HIMETRIC_PER_INCH, (x), (ppli)) #define MAP_LOGHIM_TO_PIX(x,ppli) MulDiv((ppli), (x), HIMETRIC_PER_INCH) int nPixelsPerInchX; // Pixels per logical inch along width int nPixelsPerInchY; // Pixels per logical inch along height HDC hDCScreen = ::GetDC(NULL); nPixelsPerInchX = ::GetDeviceCaps(hDCScreen, LOGPIXELSX); nPixelsPerInchY = ::GetDeviceCaps(hDCScreen, LOGPIXELSY); ::ReleaseDC(NULL, hDCScreen); lpSizeInHiMetric->cx = MAP_PIX_TO_LOGHIM(lpSizeInPix->cx, nPixelsPerInchX); lpSizeInHiMetric->cy = MAP_PIX_TO_LOGHIM(lpSizeInPix->cy, nPixelsPerInchY); }
HRESULT _IFUNC BOleInProcHandler::GetExtent(DWORD dwDrawAspect, LONG lindex, DVTARGETDEVICE FAR *ptd, LPSIZEL lpsizel) { if (dwDrawAspect != DVASPECT_CONTENT) return ResultFromScode (E_FAIL); if (!lpsizel) return ResultFromScode (E_INVALIDARG); SIZE s; HRESULT hr = pProvider->GetPartSize (&s); lpsizel->cx = MAP_PIX_TO_LOGHIM (s.cx, BOleService::pixPerIn.x); lpsizel->cy = MAP_PIX_TO_LOGHIM (s.cy, BOleService::pixPerIn.y); return hr; }
void AFXAPI _AfxXformSizeInPixelsToHimetric( HDC hDC, LPSIZEL lpSizeInPix, LPSIZEL lpSizeInHiMetric) { int cxPPI; int cyPPI; if ((NULL == hDC) || (GetDeviceCaps(hDC, LOGPIXELSX) == 0)) { cxPPI = afxData.cxPixelsPerInch; cyPPI = afxData.cyPixelsPerInch; } else { cxPPI = GetDeviceCaps(hDC, LOGPIXELSX); cyPPI = GetDeviceCaps(hDC, LOGPIXELSY); } lpSizeInHiMetric->cx = (long)MAP_PIX_TO_LOGHIM((int)lpSizeInPix->cx, cxPPI); lpSizeInHiMetric->cy = (long)MAP_PIX_TO_LOGHIM((int)lpSizeInPix->cy, cyPPI); }