Hi Dave,
I think you can print the graph just like printing any other images or other things in MFC. There is no special code needed, apart from normal MFC printing code. You just need to send the bitmap to the printer device context (usually in the MFC OnPrint method).
For example, the following is some code to print a general bitmap (CStatic control), which should work with the CChartViewer control tool. You may try this in the MFC OnPrint method.
//
// get the bitmap to print
//
BITMAPINFO stBitmapInfo;
memset(&stBitmapInfo, 0, sizeof(stBitmapInfo));
stBitmapInfo.bmiHeader.biSize = sizeof(stBitmapInfo.bmiHeader);
::GetDIBits(viewer->GetDC()->m_hDC, viewer->GetBitmap(), 0, 0, 0, &stBitmapInfo, DIB_RGB_COLORS);
stBitmapInfo.bmiHeader.biBitCount = 24;
stBitmapInfo.bmiHeader.biCompression = BI_RGB;
stBitmapInfo.bmiHeader.biSizeImage = ((((stBitmapInfo.bmiHeader.biWidth * 24) + 31) & ~31) >> 3) * stBitmapInfo.bmiHeader.biHeight;
void *data = malloc(stBitmapInfo.bmiHeader.biSizeImage);
::GetDIBits(viewer->GetDC()->m_hDC, viewer->GetBitmap(), 0, stBitmapInfo.bmiHeader.biHeight, data, &stBitmapInfo, DIB_RGB_COLORS);
//
// send the bitmap to the printer device context
//
double xScaleFactor = pDC->GetDeviceCaps(LOGPIXELSX) / 96.0;
double yScaleFactor = pDC->GetDeviceCaps(LOGPIXELSY) / 96.0;
::StretchDIBits (pDC->m_hDC,
(int)(40 * xScaleFactor),
(int)(40 * yScaleFactor),
(int)(stBitmapInfo.bmiHeader.biWidth * xScaleFactor),
(int)(stBitmapInfo.bmiHeader.biHeight * yScaleFactor),
0,
0,
stBitmapInfo.bmiHeader.biWidth,
stBitmapInfo.bmiHeader.biHeight,
data,
(LPBITMAPINFO)&stBitmapInfo,
DIB_RGB_COLORS,
SRCCOPY);
free(data);
Hope this can help.
Regards
Peter Kwan |