[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to print a dialog widow

Posted on 1998-06-23
6
Medium Priority
?
265 Views
Last Modified: 2013-11-20
How can i print a dialog window (created with CDialog MFC class) using PrintClient function, or WM_PRINTCLIENT message, or anything else ...

Thanks
0
Comment
Question by:fbt
[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
  • 3
  • 3
6 Comments
 
LVL 7

Accepted Solution

by:
galkin earned 200 total points
ID: 1318329
Use WM_PRINT with PRF_CLIENT|PRF_NONCLIENT|PRF_ERASEBKGND|PRF_CHILDREN flag.
Take into account that you must perform appropriate scaling and offset because of difference in printer resolution. i suggest you create memory DC, sending WM_PRINT message passing memory DC as WPARAM and then use StretchBlt to stretch memory DC on printer DC.
0
 

Author Comment

by:fbt
ID: 1318330
Thank you galkin for your answer.

I tried to print my dialog with your suggestion, by my page is
still empty.
Can you tell me where i am wrong ???

Thanks.

(CResult is a CDialog class)

void CResult::OnPrint()
{
HDC    hdcPrn ;

    // Instantiate a CPrintDialog.
    CPrintDialog *printDlg =
        new CPrintDialog(FALSE, PD_ALLPAGES | PD_RETURNDC, NULL);


    // Display Windows print dialog box.
    // Initialize some of the fields in PRINTDLG structure.
    printDlg->m_pd.nMinPage = printDlg->m_pd.nMaxPage = 1;
    printDlg->m_pd.nFromPage = printDlg->m_pd.nToPage = 1;

    printDlg->DoModal();
    // Obtain a handle to the device context.
    hdcPrn = printDlg->GetPrinterDC();

    if (hdcPrn != NULL)
    {
        CDC *pDC = new CDC;
        pDC->Attach (hdcPrn);      // attach a printer DC

      DOCINFO di;
      ::ZeroMemory (&di, sizeof (DOCINFO));
      di.cbSize = sizeof (DOCINFO);
      di.lpszDocName = _T("WNObnsk");

      pDC->StartDoc(&di); // Begin a new print job

      short cxPage = ::GetDeviceCaps (hdcPrn, HORZRES);
      short cyPage = ::GetDeviceCaps (hdcPrn, VERTRES);

      BOOL b = ::StretchBlt (hdcPrn, 0, 0, cxPage, cyPage,
            pDC->GetSafeHdc(), 0, 0, 1000, 1000, MERGEPAINT);
      AfxTrace (_T("StretchBlt : %d\n"), b);

        pDC->StartPage();          // begin a new page
      SendMessage (WM_PRINT, (WPARAM) pDC, PRF_CLIENT|PRF_NONCLIENT|PRF_ERASEBKGND|PRF_CHILDREN);
        pDC->EndPage();            // end a page

        pDC->EndDoc();             // end a print job

        pDC->Detach();             // detach the printer DC
        delete pDC;
    }

    delete printDlg;
}

0
 
LVL 7

Expert Comment

by:galkin
ID: 1318331
WPARAM should be HDC not CDC*.
SendMessage (WM_PRINT, (WPARAM) pDC->GetSafeHdc(), PRF_CLIENT|PRF_NONCLIENT|PRF_ERASEBKGND|PRF_CHILDREN);

0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

Author Comment

by:fbt
ID: 1318332
My dialog is now printing on my page, but it's still tiny.

I tried many differents values in StretchBlt, but the dialog
on the page is like a stamp !!

Can you explain me what is the problem ???

Thanks
0
 
LVL 7

Expert Comment

by:galkin
ID: 1318333
I already mentioned you must adjust scaling factor.
Use GetDeviceCaps(LOGPIXELX) and GetDeviceCaps(LOGPIXELY) passing iHDC of screen and HDC of the printer.
0
 

Author Comment

by:fbt
ID: 1318334
I'm sorry about my basic questions, but even with
GetDeviceCaps (LOGPIXELSX) and GetDeviceCaps (LOGPIXELSY),
the dialog is still tiny on my print page (I watched the
values of the datas on debug and cxPage = cyPage =
cxDC = cyDC = 600, and StretchBlt status is TRUE).

This is my code (if you have enough time to read it,
or a full example, to save your time - Thanks).



void CResult::OnPrint()
{
HDC    hdcPrn ;

    // Instantiate a CPrintDialog.
    CPrintDialog *printDlg =
        new CPrintDialog(FALSE, PD_ALLPAGES | PD_RETURNDC, NULL);


    // Display Windows print dialog box.
    // Initialize some of the fields in PRINTDLG structure.
    printDlg->m_pd.nMinPage = printDlg->m_pd.nMaxPage = 1;
    printDlg->m_pd.nFromPage = printDlg->m_pd.nToPage = 1;

    printDlg->DoModal();
    // Obtain a handle to the device context.
    hdcPrn = printDlg->GetPrinterDC();

    if (hdcPrn != NULL)
    {
        CDC *pDC = new CDC;
        pDC->Attach (hdcPrn);      // attach a printer DC

      DOCINFO di;
      ::ZeroMemory (&di, sizeof (DOCINFO));
      di.cbSize = sizeof (DOCINFO);
      di.lpszDocName = _T("WNObnsk");

      pDC->StartDoc(&di); // Begin a new print job

      int cxPage = ::GetDeviceCaps (hdcPrn, LOGPIXELSX);
      int cyPage = ::GetDeviceCaps (hdcPrn, LOGPIXELSY);

      int cxDC = pDC->GetDeviceCaps (LOGPIXELSX);
      int cyDC = pDC->GetDeviceCaps (LOGPIXELSY);

      BOOL b = ::StretchBlt (hdcPrn, 0, 0, cxPage, cyPage,
            pDC->GetSafeHdc(), 0, 0, cxDC, cyDC, MERGEPAINT);
      AfxTrace (_T("StretchBlt : %d\n"), b);

        pDC->StartPage();          // begin a new page
      SendMessage (WM_PRINT, (WPARAM) pDC->GetSafeHdc(), PRF_CLIENT|PRF_NONCLIENT|PRF_ERASEBKGND|PRF_CHILDREN);
        pDC->EndPage();            // end a page
        pDC->EndDoc();             // end a print job
        pDC->Detach();             // detach the printer DC
        delete pDC;
    }

    delete printDlg;
}

0

Featured Post

Industry Leaders: 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: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

656 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