Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

print out a page with a all controls

Hello
Is it possible to print out all the controls on a page.
I meam all together with one function?
Thanks
Phil1
0 Kudos
Message 1 of 3
(2,749 Views)
What do you exactly mean by "page"? You can save a bitmap image of a whole panel using SavePanelDisplayToFile function, available in Programmer's Toolbox that ships with LabWindows/CVI, and print out hte bitmap file.

Mika Fukuchi
Application Engineer
National Instruments
0 Kudos
Message 2 of 3
(2,749 Views)
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
0 Kudos
Message 3 of 3
(2,749 Views)