--- mstools/samples/ole/srvrdemo/obj.c 2018/08/09 18:20:49 1.1 +++ mstools/samples/ole/srvrdemo/obj.c 2018/08/09 18:21:49 1.1.1.2 @@ -245,7 +245,8 @@ static VOID DrawObj (HDC hdc, LPOBJ lpob HPEN hpenOld; HPALETTE hpalOld = NULL; - if (dctype == dctypeMetafile || dctype == dctypeEnhMetafile) +// if (dctype == dctypeMetafile || dctype == dctypeEnhMetafile) + if (dctype == dctypeMetafile) { SetWindowOrgEx (hdc, 0, 0, NULL); // Paint entire object into the given rectangle. @@ -337,7 +338,7 @@ static HBITMAP GetBitmap (LPOBJ lpobj) // convert width and height to HIMETRIC units rc.right = rc.right - rc.left; rc.bottom = rc.bottom - rc.top; - DeviceToHiMetric (hwndMain, (LPPOINT) &rc.right); + DeviceToHiMetric ( (LPPOINT) &rc.right ); // Set the 1/10 of HIMETRIC units for the bitmap SetBitmapDimensionEx (hbitmap, (DWORD) (rc.right/10), (DWORD) (rc.bottom/10), NULL); @@ -454,7 +455,7 @@ static HANDLE GetMetafilePict (LPOBJ lpo rc.right = rc.right - rc.left; rc.bottom = rc.bottom - rc.top; - DeviceToHiMetric (hwndMain, (LPPOINT) &rc.right); + DeviceToHiMetric ( (LPPOINT) &rc.right); lppict->mm = MM_ANISOTROPIC; lppict->hMF = hMF; @@ -482,19 +483,41 @@ static HANDLE GetEnhMetafile (LPOBJ lpob LPMETAFILEPICT lppict = NULL; HANDLE hemf = NULL; HANDLE hMF = NULL; - RECT rc,rect; - HDC hdc; + RECT rc; + HDC hdc, hdc2; + GetClientRect (lpobj->hwnd, (LPRECT)&rc); - rect.left = rect.top = 0; - rect.right = rc.right - rc.left; - rect.bottom = rc.bottom - rc.top; + rc.right -= rc.left; + rc.bottom -= rc.top; + rc.left = rc.top = 0; + + DeviceToHiMetric ( (LPPOINT) &rc.right ); + + hdc = CreateEnhMetaFile ( NULL, NULL, &rc, NULL ); - DeviceToHiMetric (hwndMain, (LPPOINT) &rect.right); + //* this is necessary because + //* we need to draw the object + //* in device coordinates that are + //* the same physical size as the HIMETRIC + //* logical space used in CreateEnhMetaFile. + //* In this case we have scaled the HIMETRIC + //* units down in order to use the logical + //* pixel ratio (which is recommended UI) + //* so we therefore have to convert the + //* scaled HIMETRIC units back to Device. + + hdc2 = GetDC(NULL); + + SetMapMode(hdc2, MM_HIMETRIC); + LPtoDP (hdc2, (LPPOINT)&rc.right, 1); + if (rc.bottom < 0) rc.bottom *= -1; + + ReleaseDC(NULL,hdc2); + + DrawObj (hdc, lpobj, rc, dctypeMetafile); - hdc = CreateEnhMetaFile(NULL, NULL, &rect, NULL); - DrawObj (hdc, lpobj, rc, dctypeMetafile); if ((hemf = (HANDLE)CloseEnhMetaFile (hdc)) == NULL) return NULL; @@ -846,7 +869,7 @@ OLESTATUS APIENTRY ObjSetBounds (LPOLEO // the units are in HIMETRIC rect.right = rect.right - rect.left; rect.bottom = rect.top - rect.bottom; - HiMetricToDevice (hwndMain, (LPPOINT) &rect.right); + HiMetricToDevice ( (LPPOINT) &rect.right); MoveWindow (lpobj->hwnd, lpobj->native.nX, lpobj->native.nY, rect.right + 2 * GetSystemMetrics(SM_CXFRAME), rect.bottom + 2 * GetSystemMetrics(SM_CYFRAME), @@ -938,8 +961,11 @@ OLESTATUS APIENTRY ObjSetData docMain.rgfObjNums [GetObjNum(lpobj)] = TRUE; MoveWindow (lpobj->hwnd, 0, 0, - lpobj->native.nWidth + 2 * GetSystemMetrics(SM_CXFRAME), - lpobj->native.nHeight+ 2 * GetSystemMetrics(SM_CYFRAME), +// lpobj->native.nWidth + 2 * GetSystemMetrics(SM_CXFRAME), +// lpobj->native.nHeight+ 2 * GetSystemMetrics(SM_CYFRAME), + lpobj->native.nWidth, + lpobj->native.nHeight, + FALSE); GlobalUnlock (hdata); }