关于截图不能成功,该怎么解决
关于截图不能成功
//拷贝截图到文件,lpRect 代表选定区域
HBITMAP CIECaptureDlg::CopyScreenToBitmap(LPRECT lpRect,BOOL bSave)
{
HDC hScrDC, hMemDC;
// 屏幕和内存设备描述表
HBITMAP hBitmap, hOldBitmap;
// 位图句柄
int nX, nY, nX2, nY2;
// 选定区域坐标
int nWidth, nHeight;
//the pointer will save all pixel point 's color value
BYTE *lpBitmapBits = NULL;
// 确保选定区域不为空矩形
if ( IsRectEmpty( lpRect ) )
{
return NULL;
}
//为屏幕创建设备描述表
hScrDC = CreateDC( _T( "DISPLAY " ), NULL, NULL, NULL );
//为屏幕设备描述表创建兼容的内存设备描述表
hMemDC = CreateCompatibleDC( hScrDC );
// 获得选定区域坐标
nX = lpRect-> left;
nY = lpRect-> top;
nX2 = lpRect-> right;
nY2 = lpRect-> bottom;
//确保选定区域是可见的
if ( nX < 0 )
{
nX = 0;
}
if ( nY < 0 )
{
nY = 0;
}
if ( nX2 > m_xScreen )
{
nX2 = m_xScreen;
}
if ( nY2 > m_yScreen )
{
nY2 = m_yScreen;
}
nWidth = nX2 - nX;
nHeight = nY2 - nY;
//initialize the struct BITMAPINFO for the bitmap infomation,
//in order to use the function CreateDIBSection
//on wince os, each pixel stored by 24 bits(biBitCount=24)
//and no compressing(biCompression=0)
BITMAPINFO RGB24BitsBITMAPINFO;
memset( &RGB24BitsBITMAPINFO, 0, sizeof(BITMAPINFO) );
RGB24BitsBITMAPINFO.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
RGB24BitsBITMAPINFO.bmiHeader.biWidth = nWidth;
RGB24BitsBITMAPINFO.bmiHeader.biHeight = nHeight;
RGB24BitsBITMAPINFO.bmiHeader.biPlanes = 1;
RGB24BitsBITMAPINFO.bmiHeader.biBitCount = 24;
//use the function CreateDIBSection and SelectObject
//in order to get the bitmap pointer : lpBitmapBits
hBitmap = CreateDIBSection( hMemDC, (BITMAPINFO*)&RGB24BitsBITMAPINFO,
//拷贝截图到文件,lpRect 代表选定区域
HBITMAP CIECaptureDlg::CopyScreenToBitmap(LPRECT lpRect,BOOL bSave)
{
HDC hScrDC, hMemDC;
// 屏幕和内存设备描述表
HBITMAP hBitmap, hOldBitmap;
// 位图句柄
int nX, nY, nX2, nY2;
// 选定区域坐标
int nWidth, nHeight;
//the pointer will save all pixel point 's color value
BYTE *lpBitmapBits = NULL;
// 确保选定区域不为空矩形
if ( IsRectEmpty( lpRect ) )
{
return NULL;
}
//为屏幕创建设备描述表
hScrDC = CreateDC( _T( "DISPLAY " ), NULL, NULL, NULL );
//为屏幕设备描述表创建兼容的内存设备描述表
hMemDC = CreateCompatibleDC( hScrDC );
// 获得选定区域坐标
nX = lpRect-> left;
nY = lpRect-> top;
nX2 = lpRect-> right;
nY2 = lpRect-> bottom;
//确保选定区域是可见的
if ( nX < 0 )
{
nX = 0;
}
if ( nY < 0 )
{
nY = 0;
}
if ( nX2 > m_xScreen )
{
nX2 = m_xScreen;
}
if ( nY2 > m_yScreen )
{
nY2 = m_yScreen;
}
nWidth = nX2 - nX;
nHeight = nY2 - nY;
//initialize the struct BITMAPINFO for the bitmap infomation,
//in order to use the function CreateDIBSection
//on wince os, each pixel stored by 24 bits(biBitCount=24)
//and no compressing(biCompression=0)
BITMAPINFO RGB24BitsBITMAPINFO;
memset( &RGB24BitsBITMAPINFO, 0, sizeof(BITMAPINFO) );
RGB24BitsBITMAPINFO.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
RGB24BitsBITMAPINFO.bmiHeader.biWidth = nWidth;
RGB24BitsBITMAPINFO.bmiHeader.biHeight = nHeight;
RGB24BitsBITMAPINFO.bmiHeader.biPlanes = 1;
RGB24BitsBITMAPINFO.bmiHeader.biBitCount = 24;
//use the function CreateDIBSection and SelectObject
//in order to get the bitmap pointer : lpBitmapBits
hBitmap = CreateDIBSection( hMemDC, (BITMAPINFO*)&RGB24BitsBITMAPINFO,