CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2001
    Posts
    401

    Please help------ Printer

    I am trying the code below to set the printer settings so that the page setup is Landscape but its not working.

    I have been stuck on it for some time now any help is very much appreciated.


    HANDLE m_hDevNames=NULL,m_hDevMode=NULL;
    PRINTDLG pd2;
    // Retrieve MFC's default printer.
    AfxGetApp()->GetPrinterDeviceDefaults(&pd2);

    // Make our own private copy of MFC's DEVMODE and DEVNAMES data.

    // Note: we should NOT GlobalFree the handles returned
    // to us in the PRINTDLG structure, because those are the
    // actual handles that MFC uses!
    m_hDevMode = CopyHandle(pd2.hDevMode);
    m_hDevNames = CopyHandle(pd2.hDevNames);


    {
    // Get default printer settings.
    PRINTDLG pd;

    pd.lStructSize = (DWORD) sizeof(PRINTDLG);
    if (AfxGetApp()->GetPrinterDeviceDefaults(&pd))
    {
    // Lock memory handle.
    DEVMODE FAR* pDevMode =
    (DEVMODE FAR*)::GlobalLock(m_hDevMode);
    LPDEVNAMES lpDevNames;
    LPTSTR lpszDriverName, lpszDeviceName, lpszPortName;
    HANDLE hPrinter;
    TCHAR name[256];
    DWORD sz=sizeof(name);
    ::GetDefaultPrinter(name,&sz);
    //_tcscpy(lpszDeviceName,name);
    if (pDevMode)
    {
    // Change printer settings in here.
    pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
    // Unlock memory handle.
    lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames);
    lpszDriverName = (LPTSTR )lpDevNames + lpDevNames->wDriverOffset;
    lpszDeviceName = (LPTSTR )lpDevNames + lpDevNames->wDeviceOffset;
    lpszPortName = (LPTSTR )lpDevNames + lpDevNames->wOutputOffset;

    BOOL hiya3 = ::OpenPrinter(name/*lpszDeviceName*/, &hPrinter, NULL);
    :ocumentProperties(NULL,hPrinter,lpszDeviceName,NULL,//pDevMode,
    pDevMode, DM_IN_BUFFER);//|DM_OUT_BUFFER);

    // Sync the pDevMode.
    // See SDK help for DocumentProperties for more info.
    ::ClosePrinter(hPrinter);
    ::GlobalUnlock(m_hDevNames);
    ::GlobalUnlock(m_hDevMode);
    }

    }

    }

    /////////Once above is done I am using the msword automation to print the //document


    }
    VARIANT vName;
    vName.vt = VT_BSTR;
    vName.bstrVal = SysAllocString(L"WdPrintOutRange.wdPrintFromTo");
    VARIANT vName2;
    vName2.vt = VT_BSTR;
    vName2.bstrVal = SysAllocString(L"1-2");
    TRY
    {Doc.PrintOut(covFalse, // Background.
    covOptional, // Append.
    covOptional, // Range.
    covOptional, // OutputFileName.
    covOptional, // // From.
    covOptional, // // To.
    covOptional, // Item.
    COleVariant((long)1), // Copies.
    covOptional, // Pages.
    covOptional, // PageType.
    covOptional, // PrintToFile.
    covOptional, // Collate.
    covOptional, // ActivePrinterMacGX.
    covOptional, // ManualDuplexPrint.
    covOptional, // PrintZoomColumn New with Word 2002
    covOptional, // PrintZoomRow ditto
    covOptional, // PrintZoomPaperWidth ditto
    covOptional);
    }
    CATCH(CException, e)
    {

    return FALSE;
    }
    END_CATCH

    Thanks for your time!
    Pauli

  2. #2
    Join Date
    Jun 2004
    Posts
    1,352
    Look at the CPrintInfo class/struct.

  3. #3
    Join Date
    Jun 2004
    Posts
    1,352
    Actually this strcut:


    typedef struct _devicemode { // dvmd
    BCHAR dmDeviceName[CCHDEVICENAME];
    WORD dmSpecVersion;
    WORD dmDriverVersion;
    WORD dmSize;
    WORD dmDriverExtra;
    DWORD dmFields;
    short dmOrientation;
    short dmPaperSize;
    short dmPaperLength;
    short dmPaperWidth;
    short dmScale;
    short dmCopies;
    short dmDefaultSource;
    short dmPrintQuality;
    short dmColor;
    short dmDuplex;
    short dmYResolution;
    short dmTTOption;
    short dmCollate;
    BCHAR dmFormName[CCHFORMNAME];
    WORD dmLogPixels;
    DWORD dmBitsPerPel;
    DWORD dmPelsWidth;
    DWORD dmPelsHeight;
    DWORD dmDisplayFlags;
    DWORD dmDisplayFrequency;
    #if(WINVER >= 0x0400)
    DWORD dmICMMethod; // Windows 95 only
    DWORD dmICMIntent; // Windows 95 only
    DWORD dmMediaType; // Windows 95 only
    DWORD dmDitherType; // Windows 95 only
    DWORD dmReserved1; // Windows 95 only
    DWORD dmReserved2; // Windows 95 only
    #endif /* WINVER >= 0x0400 */
    } DEVMODE;


    ... DEVMODE, .... I think it's the dmOrientation parameter you have to set!!1



    dmOrientation
    Selects the orientation of the paper. This member can be either DMORIENT_PORTRAIT (1) or DMORIENT_LANDSCAPE (2).

    ... DEVMODE, .... I think it's the



    Don't forget to post your results, I like to stay on top of the printing stuff, I like to get involved in all PRINTING threads.

  4. #4
    Join Date
    Nov 2001
    Posts
    401

    Hello

    Well thats what I am doing in the code above but its not working.


    Once this is done I alos have to implement selecting between color/ black and white printing as well.


    Thanks for your time!

    Pauli

  5. #5
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354
    I don't know. But, does the settings you do, get passed on to the automation object ?

  6. #6
    Join Date
    Jun 2004
    Posts
    1,352
    Quote Originally Posted by paulina_lui
    Well thats what I am doing in the code above but its not working.


    Once this is done I alos have to implement selecting between color/ black and white printing as well.


    Thanks for your time!

    Pauli
    The CPrintdlg class takes care of that. Once you call it, the dialog box has all those options????

  7. #7
    Join Date
    Nov 2001
    Posts
    401

    Well

    Kirants,

    I dont know how to pass those to he printer using automation(WORD,PowerPoint), so was hoping if I am able to change the default settings of the printer, anyone who prints afterwards should see the same settings and it should print fine, as this I what I plan to do.

    Change the printer setting to landscape and black and white only if possible, and then print.

    And thanks for your help earlier as well.


    ADSOFT,

    I dont want to display any dialog, and want to change the settings my self.


    Thanks for your time

    Pauli

  8. #8
    Join Date
    Aug 2004
    Posts
    18
    For full features about page setup of the printer,I think the fullowing 3rd Party XD++ MFC Flow/Diagram will help you:
    http://www.********.net
    Regards

  9. #9
    Join Date
    Jun 2004
    Posts
    1,352
    It doesn't look like its good at doing reports??


    For Graphical stuff it might be alright but the FRAMEWORK supports graphical by printing what is done via OnDraw(pDC);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured