Hi, I want to make a Screenshot of a CWnd and then Print it out. I already created some basic Code for testing purposes but if I'm actually printing it only works sometimes (on some Printers in combination with some PC's I'm printing from). What's always working is to directly draw a Rectangle to the Device Context but when I'm calling the "printWindow" It sometimes has no effect (it always returns true). I also don't think that its a driver problem of the PC because I never had any problems and I also tested it on 2 more Pc's.
So there Are 2 Scenarios when I'm printing:
1) I only see a Rectangle (white/transparent inside)
2) I see the Window and a Rectangle around it
In my Example I created a Basic MFC App (DialogBased) and just added a Button to Print the Window. I also created another Function to get the Default Printer Name but I dont think thats the cause so I din't uploaded it here.
Here is the Code:
CDC pDC;
HDC hdc;
LPCSTR buffer = NULL;
GetDefaultPrinterName(buffer);
hdc = CreateDC(_T( "winspool" ), buffer, NULL, NULL);
pDC.Attach(hdc);
pDC.StartDoc("test");
pDC.StartPage();
if (! ::PrintWindow(this->GetSafeHwnd(), pDC.GetSafeHdc(), PW_CLIENTONLY))
AfxMessageBox("Error when calling \"PrintWindow()\"");
CRect WindowRect;
GetClientRect(WindowRect);
WindowRect.MoveToXY(0,0);
CBrush brush;
brush.CreateSolidBrush(RGB(0,0,0));
pDC.FrameRect(WindowRect, &brush);
pDC.EndPage();
pDC.EndDoc();
Do you know what causes the problem or what could I do as an Workaround?