如何将指定设备上的内容输出到打印机 谢谢CDC 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 先把设备上面的内容输出位图,然后使用下面的函数就行了,主要是DDB-DIB的转换void Draw(HDC hDC,HBITMAP hBmp,double dScaleX,double dScaleY,int iX,int iY,int iWidth=0,int iLength=0){ HPALETTE hPal; BITMAP bm; BITMAPINFOHEADER bi; LPBITMAPINFOHEADER lpbi; DWORD dwLen; HANDLE hDIB; HANDLE handle; HDC hDC1; if(GetDeviceCaps(hDC,RASTERCAPS) & RC_PALETTE ) { UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * 256); LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize]; pLP->palVersion = 0x300; pLP->palNumEntries =GetSystemPaletteEntries( hDC, 0, 255, pLP->palPalEntry ); hPal=CreatePalette(pLP ); delete[] pLP; } if (hPal==NULL) hPal = (HPALETTE) GetStockObject(DEFAULT_PALETTE); ::GetObject(hBmp,sizeof(bm),(LPSTR)&bm); bi.biSize = sizeof(BITMAPINFOHEADER); bi.biWidth = bm.bmWidth; bi.biHeight = bm.bmHeight; bi.biPlanes = 1; bi.biBitCount = bm.bmPlanes * bm.bmBitsPixel; bi.biCompression = BI_RGB; bi.biSizeImage = 0; bi.biXPelsPerMeter = 0; bi.biYPelsPerMeter = 0; bi.biClrUsed = 0; bi.biClrImportant = 0; int nColors = (1 << bi.biBitCount); if( nColors > 256 ) nColors = 0; dwLen = bi.biSize + nColors * sizeof(RGBQUAD); hDC1 = ::GetDC(NULL); hPal = SelectPalette(hDC1,hPal,FALSE); RealizePalette(hDC1); hDIB = GlobalAlloc(GMEM_FIXED,dwLen); if (!hDIB) { SelectPalette(hDC1,hPal,FALSE); ::ReleaseDC(NULL,hDC1); DeleteObject(hPal); return ; } lpbi = (LPBITMAPINFOHEADER)hDIB; *lpbi = bi; ::GetDIBits(hDC1, hBmp, 0L, (DWORD)bi.biHeight, (LPBYTE)NULL, (LPBITMAPINFO)lpbi, (DWORD)DIB_RGB_COLORS); bi = *lpbi; if (bi.biSizeImage == 0) bi.biSizeImage = ((((bi.biWidth * bi.biBitCount) + 31) & ~31) / 8)* bi.biHeight; dwLen += bi.biSizeImage; if (handle = GlobalReAlloc(hDIB, dwLen, GMEM_MOVEABLE)) hDIB = handle; else { GlobalFree(hDIB); SelectPalette(hDC1,hPal,FALSE); ::ReleaseDC(NULL,hDC1); DeleteObject(hPal); return ; } lpbi = (LPBITMAPINFOHEADER)hDIB; BOOL bGotBits = GetDIBits( hDC1, hBmp,0L,(DWORD)bi.biHeight,(LPBYTE)lpbi+ (bi.biSize + nColors * sizeof(RGBQUAD)), (LPBITMAPINFO)lpbi,(DWORD)DIB_RGB_COLORS); if( !bGotBits ) { GlobalFree(hDIB); SelectPalette(hDC1,hPal,FALSE); ::ReleaseDC(NULL,hDC1); DeleteObject(hPal); return; } if(iWidth==0||iLength==0) { iWidth=lpbi->biWidth; iLength=lpbi->biHeight; iWidth=(int)(dScaleX*iWidth); iLength=(int)(iLength*dScaleY); } StretchDIBits(hDC,iX,iY,iWidth,iLength,0,0,lpbi->biWidth,lpbi->biHeight,(LPBYTE)lpbi // address for bitmap bits + (bi.biSize + nColors * sizeof(RGBQUAD)),(LPBITMAPINFO)lpbi,DIB_RGB_COLORS,SRCCOPY); SelectPalette(hDC1,hPal,FALSE); ::ReleaseDC(NULL,hDC1); DeleteObject(hDIB); DeleteObject(hPal);} 指针的问题 mfc CListCtrl item 中的图片 被选中行颜色覆盖问题。 为何驱动卸载不干净(紧急求教) 24岁开始学VC,晚吗? 如何使tab控件倒立 谁有以下这几本书的电子版本啊? 请问怎么统计月份? 有没有办法在机器上实现一个虚拟打印机? 在进度条调用语句中的父窗口指针具体指什么? 请问哪有《windows程序设计》的电子版下载? ?????? 我要打印一个饼图,放在剪贴板里,打印预览已经看到了该饼图,但是为啥不能打印出该饼图?
void Draw(HDC hDC,HBITMAP hBmp,double dScaleX,double dScaleY,int iX,int iY,int iWidth=0,int iLength=0)
{
HPALETTE hPal;
BITMAP bm;
BITMAPINFOHEADER bi;
LPBITMAPINFOHEADER lpbi;
DWORD dwLen;
HANDLE hDIB;
HANDLE handle;
HDC hDC1;
if(GetDeviceCaps(hDC,RASTERCAPS) & RC_PALETTE )
{
UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * 256);
LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize];
pLP->palVersion = 0x300;
pLP->palNumEntries =GetSystemPaletteEntries( hDC, 0, 255, pLP->palPalEntry );
hPal=CreatePalette(pLP );
delete[] pLP;
}
if (hPal==NULL) hPal = (HPALETTE) GetStockObject(DEFAULT_PALETTE);
::GetObject(hBmp,sizeof(bm),(LPSTR)&bm);
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = bm.bmWidth;
bi.biHeight = bm.bmHeight;
bi.biPlanes = 1;
bi.biBitCount = bm.bmPlanes * bm.bmBitsPixel;
bi.biCompression = BI_RGB;
bi.biSizeImage = 0;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0;
int nColors = (1 << bi.biBitCount);
if( nColors > 256 )
nColors = 0;
dwLen = bi.biSize + nColors * sizeof(RGBQUAD);
hDC1 = ::GetDC(NULL);
hPal = SelectPalette(hDC1,hPal,FALSE);
RealizePalette(hDC1);
hDIB = GlobalAlloc(GMEM_FIXED,dwLen);
if (!hDIB)
{
SelectPalette(hDC1,hPal,FALSE);
::ReleaseDC(NULL,hDC1);
DeleteObject(hPal);
return ;
}
lpbi = (LPBITMAPINFOHEADER)hDIB;
*lpbi = bi;
::GetDIBits(hDC1, hBmp, 0L, (DWORD)bi.biHeight,
(LPBYTE)NULL, (LPBITMAPINFO)lpbi, (DWORD)DIB_RGB_COLORS);
bi = *lpbi;
if (bi.biSizeImage == 0)
bi.biSizeImage = ((((bi.biWidth * bi.biBitCount) + 31) & ~31) / 8)* bi.biHeight;
dwLen += bi.biSizeImage;
if (handle = GlobalReAlloc(hDIB, dwLen, GMEM_MOVEABLE))
hDIB = handle;
else
{
GlobalFree(hDIB);
SelectPalette(hDC1,hPal,FALSE);
::ReleaseDC(NULL,hDC1);
DeleteObject(hPal);
return ;
}
lpbi = (LPBITMAPINFOHEADER)hDIB;
BOOL bGotBits = GetDIBits( hDC1, hBmp,0L,(DWORD)bi.biHeight,(LPBYTE)lpbi+ (bi.biSize + nColors * sizeof(RGBQUAD)),
(LPBITMAPINFO)lpbi,(DWORD)DIB_RGB_COLORS);
if( !bGotBits )
{
GlobalFree(hDIB);
SelectPalette(hDC1,hPal,FALSE);
::ReleaseDC(NULL,hDC1);
DeleteObject(hPal);
return;
}
if(iWidth==0||iLength==0)
{
iWidth=lpbi->biWidth;
iLength=lpbi->biHeight;
iWidth=(int)(dScaleX*iWidth);
iLength=(int)(iLength*dScaleY);
}
StretchDIBits(hDC,iX,iY,iWidth,iLength,0,0,lpbi->biWidth,lpbi->biHeight,(LPBYTE)lpbi // address for bitmap bits
+ (bi.biSize + nColors * sizeof(RGBQUAD)),(LPBITMAPINFO)lpbi,DIB_RGB_COLORS,SRCCOPY);
SelectPalette(hDC1,hPal,FALSE);
::ReleaseDC(NULL,hDC1);
DeleteObject(hDIB);
DeleteObject(hPal);
}