SetMapMode ignores or clears SetViewportOrgEx (or SetWindowOrgEx or SetWorldTransform)



I am creating a DC that could be an EMF for going to the screen or a Printer DC.
This DC is passed to code that renders to the DC and is totally out of my control, I also might be playing an EMF to it that has SetMapMode internally.
Depending on user selections I may need to offset the DC to add or subtract a margin.
As long as the drawing code never calls SetMapMode everything works as expected, but the moment it does, then my previos calls to SetViewportOrgEx or SetWindowOrgEx or SetWorldTransform are ignored. I only need to call one of the offset functions, but none currently work.

hDC = CreateDC("WINSPOOL", pDevice, NULL, pDevMode);
SetMapMode(hDC, MM_ISOTROPIC);
SetGraphicsMode(hDC, GM_ADVANCED);
SetViewportOrgEx(hDC, MarginX * Res, MarginY * Res, NULL);
....
SetMapMode(hDC, MM_TWIPS);
SetGraphicsMode(hDC, GM_COMPATIBLE);

int left = 0;
int right = 4 * 1440;
int top = 0;
int bottom = -6 * 14400;

SelectObject(hDC, GetStockObject(BLACK_PEN));
SelectObject(hDC, GetStockObject(LTGRAY_BRUSH));
Rectangle(hDC, left, top, right, bottom);

Given the above code and setting Margin to the thickness of the papers margin should result in the rectangle being clipped, setting Margin to 0 should print the entire rectangle, starting from the first pritable pixel.
.



Relevant Pages

  • Re: SetMapMode ignores or clears SetViewportOrgEx (or SetWindowOrgEx or SetWorldTransform)
    ... This DC is passed to code that renders to the DC and is totally out of my control, I also might be playing an EMF to it that has SetMapMode internally. ... Given the above code and setting Margin to the thickness of the papers margin should result in the rectangle being clipped, setting Margin to 0 should print the entire rectangle, starting from the first pritable pixel. ...
    (microsoft.public.win32.programmer.gdi)
  • Re: How to print in full page without margins
    ... twice the width of what the actual hard margin is. ... I notice that for actual printing, the .NET graphics some how locates the 2 ... Some say if I print the rectangle at 0,0 position ... "Ron Allen" wrote: ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: How to print in full page without margins
    ... Thanks Ron, I am trying it right now and will post the result here how it ... > page and apply hard margin offets if this is true. ... > the right/bottom of the rectangle to get the whole thing shown. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: How to print in full page without margins
    ... > twice the width of what the actual hard margin is. ... > I notice that for actual printing, the .NET graphics some how locates the 2 ... Some say if I print the rectangle at 0,0 position ... >> Ron Allen ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: margin outline on business card project
    ... Group only that rectangle with a shape ... I have designed a business card with word-art objects on top of a photo ... design so I have a visual reference for that margin, ...
    (microsoft.public.publisher)

Loading