Printer output mirrored!

This is a discussion on Printer output mirrored! within the Windows Programming forums, part of the Platform Specific Boards category; I am using VC++.net and I am printing to a networked HP882c. I have the following code that prints a ...

  1. #1
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396

    Printer output mirrored!

    I am using VC++.net and I am printing to a networked HP882c.

    I have the following code that prints a simple scaled quadrilateral to my printer but the output is mirrored horizontally!

    What have I done wrong?


    Code:
    HDC getDefaultPrinterDC()
    {
    	// Initialize GDI+.
    	GdiplusStartupInput gdiplusStartupInput;
    	ULONG_PTR gdiplusToken;
    	GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
    	DOCINFO docInfo;
    	ZeroMemory(&docInfo, sizeof(docInfo));
    	docInfo.cbSize = sizeof(docInfo);
    	docInfo.lpszDocName = "GdiplusPrint";
       
    	// Create a PRINTDLG structure, and initialize the appropriate fields.
    	PRINTDLG printDlg;
    	ZeroMemory(&printDlg, sizeof(printDlg));
    	printDlg.lStructSize = sizeof(printDlg);
    	printDlg.Flags = PD_RETURNDC;
       
    	// Display a print dialog box.
    	if(!PrintDlg(&printDlg))
    	{
    		// This should be a messagebox...
    		printf("Failure\n");
    	}
    	else
    	{
    		// Now that PrintDlg has returned, a device context handle
    		// for the chosen printer is in printDlg->hDC.
    	  
    		StartDoc(printDlg.hDC, &docInfo);
    		StartPage(printDlg.hDC);
    		Graphics* graphics = new Graphics(printDlg.hDC);
    		//Pen* pen = new Pen(Color(255, 0, 0, 0));
    
    		///////////////////////////////////////
    		// Begin centering output on printer. //
    		///////////////////////////////////////
    		int iWidth = GetDeviceCaps(printDlg.hDC,HORZSIZE); // returns full screen in mm.
    		int iHeight = GetDeviceCaps(printDlg.hDC,VERTSIZE); // returns full screen in mm.
    		int iHorzRes = GetDeviceCaps(printDlg.hDC,HORZRES); // returns pixel width for printable area.
    		int iVertRes = GetDeviceCaps(printDlg.hDC,VERTRES); // returns pixel Height for printable area.
    		int iPixelsPerInchX = GetDeviceCaps(printDlg.hDC,LOGPIXELSX);
    		int iPixelsPerInchY = GetDeviceCaps(printDlg.hDC,LOGPIXELSY);
    		ScreenWidthInInches = (GetDeviceCaps(printDlg.hDC,HORZRES) / GetDeviceCaps(printDlg.hDC,LOGPIXELSX) );
    		ScreenHeightInInches = (GetDeviceCaps(printDlg.hDC,VERTRES) / GetDeviceCaps(printDlg.hDC,LOGPIXELSY) );
    		//		ratio =			pixels/full screen pixels * full screen in mm /(mm/in)
    		double xRatio = ( (GetDeviceCaps(printDlg.hDC,HORZRES) / GetDeviceCaps(printDlg.hDC,LOGPIXELSX) ) 
    			/ (MaxX-MinX) );
    		double yRatio = ( (GetDeviceCaps(printDlg.hDC,VERTRES) / GetDeviceCaps(printDlg.hDC,LOGPIXELSY) ) 
    			/ (MaxY-MinY) );
    		double ZoomFactor = xRatio > yRatio
    			? yRatio
    			: xRatio;
    		if(bDisplayCoords)
    			ZoomFactor *= .70;
    		if(bDisplayLengthsAngles) // currently this doesn't enable viewing the dims.
    			ZoomFactor *=.9;
    		ZoomFactor *=.97;
    		double OffsetX = ((ScreenWidthInInches-(MaxX*ZoomFactor))/2);
    		double OffsetY = ((ScreenHeightInInches-(MaxY*ZoomFactor))/2);
    		/////////////////////////////////////
    		// End centering output to printer. //
    		/////////////////////////////////////
    
    		// temp coord values for printing just to simplify.
    		// temp x coords.
    		int tempX0 = int( ( (Intersections[0].x*ZoomFactor) + OffsetX ) * double (iPixelsPerInchX) ) ;
    		int tempX1 = int( ( (Intersections[1].x*ZoomFactor) + OffsetX ) * double (iPixelsPerInchX) ) ;
    		int tempX2 = int( ( (Intersections[2].x*ZoomFactor) + OffsetX ) * double (iPixelsPerInchX) ) ;
    		int tempX3 = int( ( (Intersections[3].x*ZoomFactor) + OffsetX ) * double (iPixelsPerInchX) ) ;
    		// temp y coords.
    		int tempY0 = int( ( (Intersections[0].y*ZoomFactor) + OffsetY ) * double (iPixelsPerInchY) ) ;
    		int tempY1 = int( ( (Intersections[1].y*ZoomFactor) + OffsetY ) * double (iPixelsPerInchY) ) ;
    		int tempY2 = int( ( (Intersections[2].y*ZoomFactor) + OffsetY ) * double (iPixelsPerInchY) ) ;
    		int tempY3 = int( ( (Intersections[3].y*ZoomFactor) + OffsetY ) * double (iPixelsPerInchY) ) ;
    
    		// Draw crap here...
    		SelectObject (printDlg.hDC, GetStockObject (BLACK_PEN)) ;
    		MoveToEx ( printDlg.hDC, tempX0 , tempY0, NULL );
    		LineTo   (printDlg.hDC, tempX1, tempY1) ;
    		LineTo   (printDlg.hDC, tempX2, tempY2) ;
    		LineTo   (printDlg.hDC, tempX3, tempY3) ;
    		LineTo   (printDlg.hDC, tempX0, tempY0) ;
    
    		// ...miscellaneous text output omitted for brevity...
    
    		// Delete gdi stuff here.
    		//delete pen;
    		delete graphics;
    		EndPage(printDlg.hDC);
    		EndDoc(printDlg.hDC); 
    	}
    	if(printDlg.hDevMode) 
    		GlobalFree(printDlg.hDevMode);
    	if(printDlg.hDevNames) 
    		GlobalFree(printDlg.hDevNames);
    	if(printDlg.hDC)
    		DeleteDC(printDlg.hDC);
    	GdiplusShutdown(gdiplusToken);
    return 0;
    }
    "A government big enough to give you everything you want, is big enough to take away everything you have." - Thomas Jefferson
    MSVS 2008 Pro / DevPartner / CB NightlyBuilds / MinGW / Cygwin

  2. #2
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396
    I think I figured it out:

    From MSDN:

    "The default mapping mode is MM_TEXT. One logical unit equals one pixel. Positive x is to the right, and positive y is down."

    Somewhere along the way a cut my mapping mode out!
    "A government big enough to give you everything you want, is big enough to take away everything you have." - Thomas Jefferson
    MSVS 2008 Pro / DevPartner / CB NightlyBuilds / MinGW / Cygwin

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic C input output program help
    By trevordunstan in forum C Programming
    Replies: 2
    Last Post: 01-27-2008, 05:41 PM
  2. 2d game
    By JordanCason in forum Game Programming
    Replies: 5
    Last Post: 12-08-2007, 09:08 PM
  3. Having trouble making a function do what I want.
    By Shamino in forum C++ Programming
    Replies: 9
    Last Post: 12-07-2007, 10:20 AM
  4. Trying to store system(command) Output
    By punxworm in forum C++ Programming
    Replies: 5
    Last Post: 04-20-2005, 06:46 PM
  5. sorting output on student info program
    By indigo0086 in forum C++ Programming
    Replies: 2
    Last Post: 11-05-2002, 10:29 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21