I assume you're asking how do you print an MFC dialog with all of its controls. Is that correct? If so, try adding a method to your dialog class with this code:
CPrintDialog printDlg(FALSE);
if (printDlg.DoModal() != IDOK)
return;
DOCINFO documentInfo;
::ZeroMemory(&documentInfo, sizeof(documentInfo));
documentInfo.cbSize = sizeof(documentInfo);
documentInfo.lpszDocName = _T("Dialog Document");
HDC hdcPrinter = printDlg.GetPrinterDC();
CDC printerDC;
printerDC.Attach(hdcPrinter);
printerDC.StartDoc(&documentInfo);
printerDC.StartPage();
HDC hdcScreen = ::GetDC(NULL);
CDC screenDC;
screenDC.Attach(hdcScreen);
long screenPpiX = ::GetDeviceCaps(hdcScreen, LOGPIXELSX)
;
long screenPpiY = ::GetDeviceCaps(hdcScreen, LOGPIXELSY);
long printerPpiX = ::GetDeviceCaps(hdcPrinter, LOGPIXELSX);
long printerPpiY = ::GetDeviceCaps(hdcPrinter, LOGPIXELSY);
long xRatio = printerPpiX / screenPpiX;
long yRatio = printerPpiY / screenPpiY;
CRect windowRect;
GetWindowRect(&windowRect);
CRect targetRect = windowRect;
targetRect.right = targetRect.left + (targetRect.Width() * xRatio);
targetRect.bottom = targetRect.top + (targetRect.Height() * yRatio);
targetRect.OffsetRect(
-targetRect.left + (targetRect.left * xRatio),
-targetRect.top + (targetRect.top * yRatio)
);
CDC* dialogDC = GetDC();
printerDC.StretchBlt(
0,
0,
targetRect.Width(),
targetRect.Height(),
dialogDC,
0,
0,
windowRect.Width(),
windowRect.Height(),
SRCCOPY
);
ReleaseDC(dialogDC);
screenDC.Detach();
p
rinterDC.EndPage();
printerDC.EndDoc();
printerDC.Detach();
This isn't perfect, but hopefully it can get you started.
- Elton