1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
HBITMAP hBmp;// L'image que tu veux imprimer
int iBmpWidth, iBmpHeight;// Dimensions de l'image
// Création de la boite de dialogue d'impression ( celle avec le choix de l'imprimante ...)
CPrintDialog dialog( FALSE, PD_USEDEVMODECOPIES | PD_NOSELECTION);
if (m_pApp->GetPrinterDeviceDefaults( & dialog.m_pd) && dialog.DoModal() == IDOK)
{
// Récupération de la résolution de l'imprimante afin de dessiner l'image sur la totalité de la surface d'impression
int iRatioRes = 1;
DEVMODE * pDev = (DEVMODE *)GlobalLock( dialog.GetDevMode());
if (pDev->dmFields & DM_ORIENTATION)
{
pDev->dmOrientation = DMORIENT_LANDSCAPE;
}
if (pDev->dmFields & DM_YRESOLUTION)
{
iRatioRes = pDev->dmYResolution / 96;
}
else
{
if (pDev->dmFields & DM_PRINTQUALITY)
{
iRatioRes = pDev->dmPrintQuality / 96;
}
}
GlobalUnlock( dialog.GetDevMode());
HDC hDCPrinter = dialog.CreatePrinterDC();
if (hDCPrinter != NULL)
{
int iTailleX = GetDeviceCaps( hDCPrinter, HORZSIZE);
int iTailleY = GetDeviceCaps( hDCPrinter, VERTSIZE);
int iResX = GetDeviceCaps( hDCPrinter, HORZRES);
int iResY = GetDeviceCaps( hDCPrinter, VERTRES);
double dRatioX = (double)iResX / (double)iTailleX;
double dRatioY = (double)iResY / (double)iTailleY;
// Rectangle de la page entière sans marge
CRect rcPage(0, 0, iResX, iResY);
rcPage.DeflateRect((int)(A2i::eMargeG * dRatioX), (int)(A2i::eMargeH * dRatioY), (int)(A2i::eMargeD * dRatioX), (int)(A2i::eMargeB * dRatioY));
// Rectangle d'impression
CRect rcImp( rcPage.left, rcPage.top, rcPage.right, rcPage.bottom);
DOCINFO diDocinfo;
memset( & diDocinfo, 0, sizeof( diDocinfo));
diDocinfo.cbSize = sizeof( diDocinfo);
diDocinfo.lpszDocName = m_bkgParams.strChartTitle.c_str();
// On démarre l'impression d'un document
if (StartDoc( hDCPrinter, & diDocinfo))
{
CRect rcRect;
GetClientRect( rcRect);
HDC hdcBitmap = CreateCompatibleDC( hDCPrinter);
SelectObject( hdcBitmap, hBmp);
SetStretchBltMode( hDCPrinter, HALFTONE);
StretchBlt( hDCPrinter, rcImp.left, rcImp.top, rcImp.Width(), rcImp.Height(), hdcBitmap, 0, 0, iBmpWidth, iBmpHeight, SRCCOPY);
DeleteDC( hdcBitmap);
EndDoc( hDCPrinter);
}
else
{
AbortDoc( hDCPrinter);
}
DeleteDC( hDCPrinter);
}
} |
Partager