Printing help - Programmer

This is a discussion on Printing help - Programmer ; The examples how how to print on MSDN don't quite show a complete, end-to-end example of using the page-setup and print dialogs together. After I call PageSetupDlg(), do I need to copy any of the field values of the PAGESETUPDLG ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Printing help

  1. Printing help

    The examples how how to print on MSDN don't quite show a complete,
    end-to-end example of using the page-setup and print dialogs together.

    After I call PageSetupDlg(), do I need to copy any of the field values
    of the PAGESETUPDLG struct out and put them into the DEVMODE struct
    myself? Or is it enough to have onto the DEVMODE ane DEVNAMES structs
    and use them to populate the hDevMode and hDevNames members of the
    PRINTDLGEX struct?

    - Paul

  2. Re: Printing help

    "Paul J. Lucas" wrote in message
    news:cVtyh.16849$ji1.8558@newssvr12.news.prodigy.n et...
    > The examples how how to print on MSDN don't quite show a complete,
    > end-to-end example of using the page-setup and print dialogs together.
    >
    > After I call PageSetupDlg(), do I need to copy any of the field values
    > of the PAGESETUPDLG struct out and put them into the DEVMODE struct
    > myself? Or is it enough to have onto the DEVMODE ane DEVNAMES structs
    > and use them to populate the hDevMode and hDevNames members of the
    > PRINTDLGEX struct?


    The following two msg responses in my main WndProc work fine for me. I just copy
    the required fields in global variables, lazy as I am; I use a few of them in
    the routine DoYourOwnPrintingHere(HDC *).
    And I even got the PagePaintHook to work! (Hint: it's a regular WndProc, only
    process cases WM_PSD_MARGINRECT and WM_PSD_GREEKTEXTRECT and return FALSE for
    the rest). A nice boost to your app to see a preview of your page.
    The calculations (sth)*1000/72 convert the interal units to typographical
    points, that was enough accuracy for me.

    case IDM_PAGESETUP: // This is the menu item "Page Setup"
    {
    PAGESETUPDLG psd;
    ZeroMemory(&psd, sizeof(PAGESETUPDLG));
    psd.lStructSize = sizeof(PAGESETUPDLG);
    psd.hwndOwner = hWnd;
    psd.hDevMode = printer_DevMode; // Don't forget to free or store
    hDevMode.
    psd.hDevNames = printer_DevNames; // Don't forget to free or store
    hDevNames.
    psd.Flags = PSD_INTHOUSANDTHSOFINCHES | PSD_MARGINS |
    PSD_ENABLEPAGEPAINTHOOK;
    psd.rtMargin.top = TopMargin*1000/72;
    psd.rtMargin.left = LeftMargin*1000/72;
    psd.rtMargin.right = RightMargin*1000/72;
    psd.rtMargin.bottom = BottomMargin*1000/72;
    psd.ptPaperSize.x = PageSize_Width*1000/72;
    psd.ptPaperSize.y = PageSize_Height*1000/72;
    psd.lpfnPagePaintHook = PaintHook;

    if (PageSetupDlg(&psd)==TRUE)
    {
    // check paper size and margin values here
    printer_DevMode = psd.hDevMode;
    printer_DevNames = psd.hDevNames;
    PageSize_Width = (psd.ptPaperSize.x*72)/1000;
    PageSize_Height = (psd.ptPaperSize.y*72)/1000;
    LeftMargin = (psd.rtMargin.left*72)/1000;
    RightMargin = (psd.rtMargin.right*72)/1000;
    TopMargin = (psd.rtMargin.top*72)/1000;
    BottomMargin = (psd.rtMargin.bottom*72)/1000;
    }
    }
    break;
    case IDM_PRINT: // The "Print" menu entry
    {
    PRINTDLG pd;
    ZeroMemory(&pd, sizeof(PRINTDLG));

    pd.lStructSize = sizeof(PRINTDLG);
    pd.hInstance = hInst;
    pd.hDevMode = printer_DevMode;
    pd.hDevNames = printer_DevNames;
    pd.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_USEDEVMODECOPIESANDCOLLATE |
    PD_NOSELECTION | PD_ENABLEPRINTTEMPLATE | PD_ENABLEPRINTHOOK ;
    pd.hwndOwner = hWnd;
    pd.nFromPage = 1;
    pd.nToPage = 1;
    pd.nCopies = 1;
    pd.lpfnPrintHook = (LPPRINTHOOKPROC)PrintHookProc;
    pd.lpPrintTemplateName = MAKEINTRESOURCE(IDD_PRINTTEMPLATE); // (LPSTR)
    NULL;

    // Display the PRINT dialog box.
    if (PrintDlg(&pd))
    {
    DoYourOwnPrintingHere (pd.hDC);
    }
    }
    break;


    [Jongware]



+ Reply to Thread