Search code examples
c++mfccwnd

MFC PrintWindow(CPaintDC) works but PrintWindow(CDC) doesnt


I'm implementing a Printing Function in a big Project to print so called gadgets (derived from CWnd). In the Gadget Class I've created a Function to Render it to the Device Context

PrintPageContent(CDC * pDC, const CRect & rContent, int page, int numPages) {
    PrintWindow(pDC, PW_CLIENTONLY);
    pDC->Rectangle(rContent.left,rContent.top, rContent.right, rContent.bottom);

To Render the Gadget easily I thought about using the PrintWindow Function https://msdn.microsoft.com/en-us/library/x51z0shh.aspx

But this only works when Rendering the PrintPreview. When I'm actually Printing it wont. In both cases the same Function is called and the only Thing that differs is that in case of the Preview -> "CDC * pDC" is a "CPaintDC" Object and in Case of the Actual Printing its a "CDC" Object.

To be sure that its really the "PrintWindow" function what wont work I added another Line of Code to the Function [pDC->Rectangle(...);] which I can see in the Preview as well as on Paper.

I also thought about using the CWnd::Print or CWnd::PrintClient Function but none of them work in both cases.

So my Question is what can I do as a Workaround or what could be the Cause why rendering an Object (derived from CWnd) wont work on a CDC but on a CPaintDC?


Solution

  • I just found out that the Problem isn't the CDC/CpaintDC. It just wont work for the Printers I tested it in the first place. I tried another Printer and it worked.

    I have created another Question for the "REAL" problem MFC Printing with CDC just works on some Printers