Solved

Printing out the bitmap in the client area

Posted on 1998-09-05
2
202 Views
Last Modified: 2010-04-10
This is the Printing Method I implemented.
But it just print out the blank page.
My intent was to print out the image which is displayed in the client area.
If there's any problem you found please let me know.
Thank you in advance.

afx_msg void CMainWin::OnPrintPicture()
{
    CPrintDialog *pDlg = new CPrintDialog(FALSE);

    if(pDlg->DoModal() == IDCANCEL)
    {
            delete pDlg;
        return;
    }
         
    CClientDC dc(this);
    CDC             dc1;
      
    dc1.CreateCompatibleDC(&dc);
      dc1.BitBlt(0, 0, maxX, maxY, &dc, 0, 0, SRCCOPY);
    HDC hdc = pDlg->GetPrinterDC();
    DOCINFO di = {sizeof(DOCINFO), NULL, NULL};

    ::StartDoc(hdc, &di);
    ::StartPage(hdc);
    ::BitBlt(hdc, 0, 0, maxX, maxY, dc1.m_hDC, 0, 0, SRCCOPY);
    ::RestoreDC(hdc, -1);
    ::EndPage(hdc);
    ::EndDoc(hdc);

    delete pDlg;
}
0
Comment
Question by:jaewoo082098
2 Comments
 
LVL 2

Expert Comment

by:prasanth
ID: 1172053
What happens if you copy directly from the client dc (dc) insetad of copying it first to dc1 and then copying it again to the printer?
0
 
LVL 3

Accepted Solution

by:
LucHoltkamp earned 20 total points
ID: 1172054
You should indeed copy directly to the PrinterDC.

You can copy to the CompatibleDC but then you must select a bitmap in the CompatibleDC. It's a memory device CONTEXT and needs a device to blit on, in the case  a memory device context, and is needs a bitmap..
luc.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

832 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