DOCINFO docInfo;
ZeroMemory(&docInfo, sizeof(docInfo));
docInfo.cbSize = sizeof(docInfo);
docInfo.lpszDocName = "GdiplusPrint";
// Create a PRINTDLG structure, and initialize the appropriate fields.
PRINTDLG printDlg;
ZeroMemory(&printDlg, sizeof(printDlg));
printDlg.lStructSize = sizeof(printDlg);
printDlg.Flags = PD_RETURNDC;
// Display a print dialog box.
if(!PrintDlg(&printDlg))
{
printf("Failure/n");
}
else
{
// Now that PrintDlg has returned, a device context handle
// for the chosen printer is in printDlg->hDC.
//GetDefaultPrinter()
CRect printClientRect;
Rect printRect;
int prHeight,prWidth,phyHeight,phyWidth;
int hSize,wSize;
CDC * printpCDC = CDC::FromHandle(printDlg.hDC);
prWidth = printpCDC->GetDeviceCaps(HORZRES);
prHeight = printpCDC->GetDeviceCaps(VERTRES);
//phyHeight = printpCDC->GetDeviceCaps(PHYSICALHEIGHT);
//phyWidth = printpCDC->GetDeviceCaps(PHYSICALWIDTH);
wSize = printpCDC->GetDeviceCaps(HORZSIZE);
hSize = printpCDC->GetDeviceCaps(VERTSIZE);
int printx=printpCDC->GetDeviceCaps(LOGPIXELSX);
int printy=printpCDC->GetDeviceCaps(LOGPIXELSY);
int screenx=GetDC()->GetDeviceCaps(LOGPIXELSX);
int screeny=GetDC()->GetDeviceCaps(LOGPIXELSY);
float xRate = (float)((float)printx / (float)screenx);
float yRate = (float)((float)printy / (float)screeny);
//tmpwnd->GetClientRect(printClientRect);
//printClientRect.left = (phyWidth - prWidth) / 2;
//printClientRect.top = (phyHeight - prHeight) / 2;
//printClientRect.right = printClientRect.left + prWidth;
//printClientRect.bottom = printClientRect.top + prHeight;
printClientRect.left = 0;
printClientRect.top = 0;
printClientRect.right = (float)(((float)wSize / (float)25.4)) * screenx;
printClientRect.bottom = (float)(((float)hSize / (float)25.4)) * screeny;
StartDoc(printDlg.hDC, &docInfo);
StartPage(printDlg.hDC);
Graphics graphics(printDlg.hDC);
//prImage.GetVerticalResolution()
//float wRateImage = (float)prImage.GetHorizontalResolution();
//float hRateImage = (float)prImage.GetVerticalResolution();
// GetImageRect(printClientRect,prImage.GetHeight(),prImage.GetWidth(),1,printRect);
graphics.DrawImage(m_pbmpSrc, 0, 0); //这里使用GDI+来打印到打印机的内容
//graphics->DrawImage();
EndPage(printDlg.hDC);
EndDoc(printDlg.hDC);
}
if(printDlg.hDevMode)
GlobalFree(printDlg.hDevMode);
if(printDlg.hDevNames)
GlobalFree(printDlg.hDevNames);
if(printDlg.hDC)
DeleteDC(printDlg.hDC);