• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

[C++] Setting Printer to Duplex

#1
I am trying to put together a program which will change the settings of a printer to Duplex Printing (Printing on both sides).

Here is the code I am using:
Code:
   char PortName[256]    = {0};
   char DriverName[256]  = {0};
   char PrinterName[256] = {0};

   HANDLE hDevMode;
   LPDEVMODE pDevMode;

   // Lets load up all the printers into a ComboxBox so we can see them
   ListBox1->Items = Printer()->Printers;

   //Now lets go through them all and make the changes.
   for(int i = 0; i < ListBox1->Items->Count; i++)
    {
     Printer()->PrinterIndex = i;
     Printer()->GetPrinter( PrinterName, DriverName, PortName, (unsigned int)hDevMode );
     if( hDevMode )
       {
        String PrtName = PrinterName;
        ShowMessage(PrtName);

        // cast to a LPDEVMODE not PDEVMODE
        pDevMode = (LPDEVMODE) GlobalLock( hDevMode );
        if( pDevMode )
         {
           if( pDevMode->dmFields & DM_DUPLEX )
            {
             pDevMode->dmDuplex = DMDUP_HORIZONTAL;
              ShowMessage("Duplex Detected");
             }
            else
             ShowMessage("Not Duplex");

            GlobalUnlock( hDevMode );
           }
         Printer()->SetPrinter(PrinterName, DriverName, PortName, (unsigned int)hDevMode);
     }
    }//loop end
Now I've run this code, and it does change the dmDuplex to DMDUP_HORIZONTAL successfully, however when you go to print it does not print duplex.

In addition to this, if I manually change the printer settings to print Duplex from the Printer Settings Dialog box you get in something like word, and then check the value of dmDuplex I find that it is unchanged, i.e. if it was DMDUP_SIMPLEX and I set it to Duplex printing in the dialog box, it will remain as DMDUP_SIMPLEX.

Now, I am not sure what I am doing wrong. Do I need to update something once I have made the changes to DMDUP_HORIZONTAL so it will refresh it? Or am I barking up the wrong tree - do I need to look somewhere else?

Would be v. grateful if someone can anyone shed some light on this. Thank you.

MdSalih
 

Members online

No members online now.

Latest posts

Latest profile posts

Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,961
Messages
673,239
Members
89,017
Latest member
bettyicrewsi