我在客户区中用了个报表控件,但是他不支持打印,我想通过抓图的办法,把客户区的东西拷贝到打印DC 中,打印出来,如何代码实现???
解决方案 »
- 关于怎么开始MFC学习的提问
- 在mfcz中工具条的停靠风格中有一条“CBRS_FLOAT_MULTI”解析是允许在一单边窗口内存在多个可移动的控制条”其中的“单边窗口”什么意思?
- 如何把一个控件类改成OCX
- 一个问题
- 求助(愿散高分):如何将exe程序转换成dll
- 【求助】线程中发送消息,线程的执行速度会受到界面操作的影响?
- 怎样才能得到程序的可执行路径名 ?(用 GetCurrentDireCtory 得到目录,再加上程序名是不行的。 因为当我用 VC++ 编译程序时,路径名是-
- 有关显示输出的问题。
- 在vc中如何打dll文件
- 请大虾们帮我看看
- 请问如何将数组作为参数由VC的DLL返回到VB? 谢谢!
- 一个很菜的问题,一定有人知道
[email protected]
HBITMAP hBmp, // DDB for convert
int nBitCount, int nCompression) // format wanted
{
typedef struct
{
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[256+3];
} DIBINFO; BITMAP ddbinfo;
DIBINFO dibinfo; // retrieve DDB information
if ( GetObject(hBmp, sizeof(BITMAP), & ddbinfo)==0 )
return NULL; // fill out BITMAPINFOHEADER based on size and required format
memset(&dibinfo, 0, sizeof(dibinfo)); dibinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
dibinfo.bmiHeader.biWidth = ddbinfo.bmWidth;
dibinfo.bmiHeader.biHeight = ddbinfo.bmHeight;
dibinfo.bmiHeader.biPlanes = 1;
dibinfo.bmiHeader.biBitCount = nBitCount;
dibinfo.bmiHeader.biCompression = nCompression; HDC hDC = GetDC(NULL); // screen DC
HGDIOBJ hpalOld;
if ( hPal )
hpalOld = SelectPalette(hDC, hPal, FALSE);
else
hpalOld = NULL; // query GDI for image size
GetDIBits(hDC, hBmp, 0, ddbinfo.bmHeight, NULL, (BITMAPINFO *) & dibinfo, DIB_RGB_COLORS); int nInfoSize = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * GetDIBColorCount(dibinfo.bmiHeader);
int nTotalSize = nInfoSize + GetDIBPixelSize(dibinfo.bmiHeader); BYTE * pDIB = new BYTE[nTotalSize]; if ( pDIB )
{
memcpy(pDIB, & dibinfo, nInfoSize);
if ( ddbinfo.bmHeight != GetDIBits(hDC, hBmp, 0, ddbinfo.bmHeight, pDIB + nInfoSize, (BITMAPINFO *) pDIB, DIB_RGB_COLORS) )
{
delete [] pDIB;
pDIB = NULL;
}
} if ( hpalOld )
SelectObject(hDC, hpalOld); ReleaseDC(NULL, hDC); return (BITMAPINFO *) pDIB;
}
HBITMAP CaptureWindow(HWND hWnd)
{
RECT wnd; if ( ! GetWindowRect(hWnd, & wnd) )
return NULL; HDC hDC = GetWindowDC(hWnd); HBITMAP hBmp = CreateCompatibleBitmap(hDC, wnd.right - wnd.left, wnd.bottom - wnd.top); if ( hBmp )
{
HDC hMemDC = CreateCompatibleDC(hDC);
HGDIOBJ hOld = SelectObject(hMemDC, hBmp); BitBlt(hMemDC, 0, 0, wnd.right - wnd.left, wnd.bottom - wnd.top,
hDC, 0, 0, SRCCOPY); SelectObject(hMemDC, hOld);
DeleteObject(hMemDC);
}
ReleaseDC(hWnd, hDC); return hBmp;
}void SaveWindowToFile(HWND hWnd, const char *filename, int nBitCount, int nCompression)
{
HBITMAP hBmp = CaptureWindow(hWnd); if(hBmp)
{
BITMAPINFO * pDIB = BitmapToDIB(NULL, hBmp, nBitCount, nCompression);
if(pDIB)
{
SaveDIBToBmp(filename, pDIB, NULL);
delete [](BYTE *) pDIB;
}
DeleteObject(hBmp);
}
}