Hi
I am trying to learn how to print the content of a window. By now I've ended up with the following code (it should just draw a line as a test print). When executing it, the printer starts working but gives out an empty page. If I choose deskPDF Creator instead of a printer, a pdf file is created, however when trying to open it the pdf reader reports an "internal error".
What am I missing here?


Code:
PRINTDLG pd;
DOCINFO di = {0};
HPEN hpen;
.......
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = "Printout";
hpen = CreatePen(PS_SOLID, 2, RGB(256,0,0));
// Initialize PRINTDLG
ZeroMemory(&pd, sizeof(pd));
pd.lStructSize = sizeof(pd);
pd.hwndOwner   = hwnd;
pd.hDevMode    = NULL;     // Don't forget to free or store hDevMode.
pd.hDevNames   = NULL;     // Don't forget to free or store hDevNames.
pd.Flags       = PD_USEDEVMODECOPIESANDCOLLATE | PD_RETURNDC;
pd.nCopies     = 1;
pd.nFromPage   = 1;
pd.nToPage     = 1;
pd.nMinPage    = 1;
pd.nMaxPage    = 1;

PrintDlg(&pd);
SelectObject(pd.hDC, hpen);
StartDoc(pd.hDC, &di);
StartPage(pd.hDC);
MoveToEx(pd.hDC, 10,100,NULL);
LineTo(pd.hDC,20,200);
EndPage(pd.hDC);
EndDoc(pd.hDC);
DeleteObject(hpen);