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;
    }
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  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!
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



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, 06:41 PM
  2. 2d game
    By JordanCason in forum Game Programming
    Replies: 5
    Last Post: 12-08-2007, 10: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, 11:20 AM
  4. Trying to store system(command) Output
    By punxworm in forum C++ Programming
    Replies: 5
    Last Post: 04-20-2005, 07:46 PM
  5. sorting output on student info program
    By indigo0086 in forum C++ Programming
    Replies: 2
    Last Post: 11-05-2002, 11:29 AM

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