[C++] Setting Printer to Duplex

MdSalih

The Boss
Joined
2 Dec 2001
Messages
1,730
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 profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back