Solved

Change Printing Orientation during middle of print job.

Posted on 2006-11-27
9
359 Views
Last Modified: 2013-11-20
Hi experts, I know there is tons of stuff about this on web but cant get anything to work!

I am using VC++ MFC unmanaged.  I would like to change the orientation of my pages as the print job goes on.  Users have the option to have a page landscape or portrait when they work and obviously this needs to be reflected when they print.  How can i change printining orientation at run time.

Thanks

Will
0
Comment
Question by:wdhough
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 18018343
http://msdn2.microsoft.com/en-us/library/t5799e1d(vs.80).aspx

See void CMyApp::SetLandscapeMode() sample function. You can change it to somethong like:

void CMyApp::SetLandscapeMode(BOOL landscape)       // true - landscape, false - portrait

Call it from any place of the program:
((CMyApp*)AfxGetApp())->SetLandscapeMode(TRUE);   // or false

I am not sure that this will work in the middle of printing, but you can try. If this will not work, you need to make number of print jobs, for example:
Job 1 - portrait, page 1
Job 2 - landscape, page 2
...

User executes command "Print", and internally program runs number of print jobs.
0
 

Author Comment

by:wdhough
ID: 18018410
Tried you first choice and as we both suspected it didnt work.  I think you can really only take that approach before you decide to print.

The second point is interesting, remember I can be printing to any sort of printer including Adobe Distiller, which in the above example would produce two files.  I dont think this approach is the solution

Thanks

Will
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 18018547
<Users have the option to have a page landscape or portrait when they work and obviously this needs to be reflected when they print.>

I can't recall ever seeing this possibility.  Do you have an example?
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

Author Comment

by:wdhough
ID: 18018754
um, well i give them the option to work portrait or landscape.  You get this MS word.  I have just taken it a little further and allowed them to have page 1 portrait and page 2 landscape, instead of both pages either portrait or landscape.

the only problem at the moment is i cant give them this option for printing.


Thanks
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 18019176
Switching during the printing - that is what I mean.
0
 

Author Comment

by:wdhough
ID: 18019220
i agree in fact i said that at the start, but hwo do you do that?  working code example if possible please
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 18019633
>>but hwo do you do that?  working code example if possible please

Here is srccode what your are looking for :

How to change the page orientation without interacting with the common Print dialog box in Visual C++
http://support.microsoft.com/kb/214617

Download project Mfcdvmdvcnet.exe : http://download.microsoft.com/download/visualstudionet/other/1.33/win98mexp/en-us/mfcdvmdvcnet.exe

-MAHESH
0
 
LVL 22

Accepted Solution

by:
mahesh1402 earned 250 total points
ID: 18019685
Have a look at following function in MyPrintView.CPP :

LPDEVMODE CMyPrintView::ChangeDevMode(HWND hWnd, char *pDevice)
{
   HANDLE      hPrinter;
   LPDEVMODE   pDevMode;
   DWORD       dwNeeded, dwRet;

   /* Start by opening the printer */
   if (!OpenPrinter(pDevice, &hPrinter, NULL))
       return NULL;

   /*
    * Step 1:
    * Allocate a buffer of the correct size.
    */

   dwNeeded = DocumentProperties(hWnd,
       hPrinter,       /* handle to our printer */
       pDevice,        /* Name of the printer */
       NULL,           /* Asking for size so */
       NULL,           /* these are not used. */
       0);             /* Zero returns buffer size. */
   pDevMode = (LPDEVMODE)malloc(dwNeeded);

   /*
    * Step 2:
    * Get the default DevMode for the printer and
    * modify it for our needs.
    */
   dwRet = DocumentProperties(hWnd,
       hPrinter,
       pDevice,
       pDevMode,       /* The address of the buffer to fill. */
       NULL,           /* Not using the input buffer. */
       DM_OUT_BUFFER); /* Have the output buffer filled. */
   if (dwRet != IDOK)
   {
       /* if failure, cleanup and return failure */
       free(pDevMode);
       ClosePrinter(hPrinter);
       return NULL;
   }

   /*
    * Make changes to the DevMode which are supported.
    */
      if (pDevMode->dmFields & DM_ORIENTATION)      
      {
       /* if the printer supports paper orientation, set it*/
       pDevMode->dmOrientation = DMORIENT_LANDSCAPE;      
      }
   /*
    * Step 3:
    * Merge the new settings with the old.
    * This gives the driver a chance to update any private
    * portions of the DevMode structure.
    */
   dwRet = DocumentProperties(hWnd,
       hPrinter,
       pDevice,
       pDevMode,       /* Reuse our buffer for output. */
       pDevMode,       /* Pass the driver our changes. */
       DM_IN_BUFFER |  /* Commands to Merge our changes and */
       DM_OUT_BUFFER); /* write the result. */

   /* Done with the printer */
   ClosePrinter(hPrinter);

   if (dwRet != IDOK)
   {
       /* if failure, cleanup and return failure */
       free(pDevMode);
       return NULL;
   }

   /* return the modified DevMode structure */
   return pDevMode;

}

-MAHESH
0
 

Author Comment

by:wdhough
ID: 18053444
Mahesh,

Thanks for your help buddy, this seems to do the trick.  The only thing I will add to this is i seemed to need to put the line below in as well, as the paper size/type was being lost.

pDevMode->dmPaperSize = my_paper_id;

I had to put this at the same point that i changed the orientation.

Thanks for your help
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question