19,468
社区成员
发帖
与我相关
我的任务
分享
HBITMAP hBitmap=(HBITMAP)LoadImage(0,_T(".\\config\\page1.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE | LR_CREATEDIBSECTION);
BITMAP bitmap;
if (MemDC.GetSafeHdc() == NULL)
{
Bitmap.Attach(hBitmap);
MemDC.CreateCompatibleDC(pDC);
Bitmap.GetObject(sizeof(bitmap),&bitmap);
pOldBmp=MemDC.SelectObject(&Bitmap);
Source.top=0;
Source.left=0;
Source.right= bitmap.bmWidth;
Source.bottom = bitmap.bmHeight;
Dest = Source;
}
pDC->DPtoLP(&Dest);
pDC->StretchBlt(Dest.left, Dest.top, Dest.right, Dest.bottom,&MemDC,Source.left, Source.top, Source.right,Source.bottom,SRCCOPY);
HANDLE hPrinter;
char * const PrinterName = "hp 7900";
if ( !OpenPrinter(PrinterName, &hPrinter, NULL) )
return ;
int nSize = DocumentProperties(NULL, hPrinter, PrinterName, NULL, NULL, 0);
DEVMODE * pDevMode = (DEVMODE *) new char[nSize];
if ( pDevMode==NULL )
return ;
// ask driver to initialize a devmode structure
DocumentProperties(NULL, hPrinter, PrinterName, pDevMode, NULL, DM_OUT_BUFFER);
pDevMode->dmPaperSize = DMPAPER_A4;
pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
DocumentProperties(NULL, hPrinter, PrinterName, NULL, pDevMode, DM_OUT_BUFFER);
// default preparation
HDC hDC = CreateDC(NULL, PrinterName, NULL, pDevMode);
SaveDC (hDC);
SetMapMode(hDC, MM_TEXT);
static DOCINFO di = { sizeof (DOCINFO), TEXT ("Print1: Printing") } ;
HBITMAP hBitmap = (HBITMAP)LoadImage(NULL, "01.bmp", IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
BITMAP bitmap;
::GetObject(hBitmap,sizeof(BITMAP),&bitmap);
int cxPage = GetDeviceCaps (hDC, HORZRES);
int cyPage = GetDeviceCaps (hDC, VERTRES);
float scale;
if((float)cxPage/(float)(bitmap.bmWidth) < (float)cyPage/(float)(bitmap.bmHeight))
{
scale = (float)cxPage/(float)(bitmap.bmWidth);
}
else
{
scale = (float)cyPage/(float)(bitmap.bmHeight);
}
StartDoc (hDC, &di);
StartPage (hDC);
HDC dcMem;
dcMem=::CreateCompatibleDC(hDC);
SelectObject(dcMem, hBitmap);
// 按比例缩放
::StretchBlt(hDC,0,0,bitmap.bmWidth*scale,bitmap.bmHeight*scale,dcMem,0,0,bitmap.bmWidth,bitmap.bmHeight,SRCCOPY);
// ::StretchBlt(hDC,0,0,cxPage,cyPage,dcMem,0,0,bitmap.bmWidth,bitmap.bmHeight,SRCCOPY);
delete pDevMode;
EndPage (hDC);
EndDoc (hDC);
RestoreDC (hDC, -1);
DeleteDC(hDC);