Code:
case MENU_PRINT:
memset(&prntdlg, 0, sizeof(PRINTDLG));
prntdlg.hwndOwner = mainwnd;
prntdlg.Flags = PD_DISABLEPRINTTOFILE | PD_HIDEPRINTTOFILE
| PD_NOPAGENUMS | PD_NOSELECTION
| PD_RETURNDC;
prntdlg.nFromPage = 1;
prntdlg.nToPage = 1;
prntdlg.nMinPage = 1;
prntdlg.nMaxPage = 1;
prntdlg.nCopies = 1;
prntdlg.lStructSize = sizeof(PRINTDLG);
if (!PrintDlg(&prntdlg))
break;
dinfo.cbSize = sizeof(DOCINFO);
dinfo.lpszDocName = "ADACS Viewer Page";
i = StartDoc(prntdlg.hDC, &dinfo);
if (StartPage(prntdlg.hDC) < 0){
MessageBox(mainwnd, "Print Job Failed.",
"Could not start page!", MB_OK |
MB_ICONEXCLAMATION);
EndDoc(prntdlg.hDC);
} else {
send2printer(wnds, prntdlg.hDC);
EndPage(prntdlg.hDC);
EndDoc(prntdlg.hDC);
}
DeleteDC(prntdlg.hDC);
break;
The code is in my main window callback procedure. In this code, I'm answering the call to a File -> Print. Something isn't right, though. What I think is happening is that I'm not destroying all the data that comes out of the PrintDlg() and/or maybe I'm not releasing my DC correctly. I've looked around on MSDN, however, the only thing I could come up with was to DeleteDC() after the EndDoc().
What am I missing here?