能力值:
( LV2,RANK:10 )
|
-
-
2 楼
哎,还是没搞出来.......
|
能力值:
( LV2,RANK:10 )
|
-
-
3 楼
以前写过这方面代码,实现截屏。
BOOL _ScreenCapture(HBITMAP &_hBitmap,LPCSTR lpFileName)
{
HDC hDC = GetDC(GetDesktopWindow());
if (hDC == NULL){
return FALSE;
}
int BitPerPixel = GetDeviceCaps(hDC,BITSPIXEL);
int Width = GetDeviceCaps(hDC,HORZRES);
int Height = GetDeviceCaps(hDC,VERTRES);
HDC memDC = CreateCompatibleDC(hDC);
if (memDC == NULL){
return FALSE;
}
HBITMAP hBitmap = CreateCompatibleBitmap(hDC, Width, Height);
if (hBitmap == NULL){
DeleteDC(memDC);
return FALSE;
}
HBITMAP hOldBitmap = (HBITMAP)SelectObject(memDC,(HGDIOBJ)hBitmap);
if(hOldBitmap == NULL){
DeleteDC(memDC);
return FALSE;
}
if(BitBlt(memDC,0, 0, Width, Height, hDC, 0, 0, SRCCOPY) == 0){
DeleteDC(memDC);
return FALSE;
}
BITMAP bmp;
GetObject(hBitmap, sizeof(BITMAP), &bmp);
BITMAPINFOHEADER bih = {0};
bih.biBitCount = bmp.bmBitsPixel;
bih.biCompression = BI_RGB;
bih.biHeight = bmp.bmHeight;
bih.biPlanes = 1;
bih.biSize = sizeof(BITMAPINFOHEADER);
bih.biSizeImage = bmp.bmWidthBytes * bmp.bmHeight;
bih.biWidth = bmp.bmWidth;
BITMAPFILEHEADER bfh = {0};
bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bfh.bfSize = bfh.bfOffBits + bmp.bmWidthBytes * bmp.bmHeight;
bfh.bfType = (WORD)0x4D42;
UINT uHeadSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
UINT uSize = bmp.bmWidthBytes * bmp.bmHeight + uHeadSize;
char *pBuf = new char[uSize];
if (pBuf == NULL){
DeleteObject((HGDIOBJ)hBitmap);
DeleteDC(memDC);
return FALSE;
}
char *pTmp = pBuf;
memcpy(pTmp, &bfh, sizeof(BITMAPFILEHEADER));
pTmp += sizeof(BITMAPFILEHEADER);
memcpy(pTmp, &bih, sizeof(BITMAPINFOHEADER));
pTmp += sizeof(BITMAPINFOHEADER);
GetDIBits(memDC,hBitmap,0,Height,pTmp,(LPBITMAPINFO) &bih,DIB_RGB_COLORS);
if (lpFileName != NULL){
HANDLE hFile = CreateFileA( lpFileName,
GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if ( hFile == INVALID_HANDLE_VALUE ){
DeleteDC(memDC);
delete pBuf;
return FALSE;
}
DWORD dwWrite = 0;
if(!WriteFile(hFile,pBuf,uSize,&dwWrite,NULL)){
DeleteDC(memDC);
delete pBuf;
return FALSE;
}
CloseHandle(hFile);
}
SelectObject(memDC,(HGDIOBJ)hOldBitmap);
DeleteDC(memDC);
_hBitmap = hBitmap;
delete pBuf;
return TRUE;
}
BOOL _ScreenCaptureBitmap(HBITMAP &_hBitmap,LPCSTR lpFileName)
{
BOOL bFlag = FALSE;
_hBitmap = NULL;
HWINSTA hwinstaLsass = GetProcessWindowStation();
if(hwinstaLsass != NULL)
{
HDESK hdeskLsass = GetThreadDesktop( GetCurrentThreadId() );
if(hdeskLsass != NULL)
{
HWINSTA hwinstaUser = OpenWindowStationA("WinSta0", FALSE, MAXIMUM_ALLOWED);
if(hwinstaUser != NULL)
{
if(SetProcessWindowStation(hwinstaUser))
{
HDESK hdeskUser = OpenDesktopA("Default", 0, FALSE, MAXIMUM_ALLOWED);
if(hdeskUser != NULL)
{
if(SetThreadDesktop(hdeskUser))
{
bFlag = _ScreenCapture(_hBitmap,lpFileName);
SetThreadDesktop(hdeskLsass);
}
CloseDesktop(hdeskUser);
}
SetProcessWindowStation(hwinstaLsass);
}
CloseWindowStation(hwinstaUser);
}
}
}
return bFlag;
}
BOOL _FreeScreenBitmap(HBITMAP &_hBitmap)
{
if (_hBitmap != NULL && _hBitmap != (HBITMAP)0xCCCCCCCC){
DeleteObject((HGDIOBJ)_hBitmap);
_hBitmap = NULL;
return TRUE;
}
return FALSE;
}
|
能力值:
( LV2,RANK:10 )
|
-
-
4 楼
对了,之前还写过可以截屏 已经最小化的窗口。晚上回去给你找找。
|
能力值:
( LV2,RANK:10 )
|
-
-
5 楼
楼主貌似要的是窗口截图,楼上给的是桌面的吧
|
能力值:
( LV2,RANK:10 )
|
-
-
6 楼
m_pic.GetDC() 换成 m_pic.GetWindowDC() 试试
|
能力值:
( LV3,RANK:30 )
|
-
-
7 楼
最小化的无法截图,但是被挡住的是可以的。。
|
能力值:
( LV2,RANK:10 )
|
-
-
9 楼
8楼也是给的整个屏幕的方式,我和楼主想知道的是窗口的扑捉,printwindow不是不可以,要N次才能出一张,但是VB的基本一截就中,有没有了解这方面的呢
|
能力值:
( LV6,RANK:90 )
|
-
-
10 楼
|
能力值:
( LV2,RANK:10 )
|
-
-
11 楼
LeoSky,可以邮我一份参考一下么?我的邮箱是:szu_andy@126.com
|
能力值:
( LV2,RANK:10 )
|
-
-
12 楼
已经发送。请查收。
|
能力值:
( LV2,RANK:10 )
|
-
-
13 楼
LeoSky,谢谢大神,不习惯看论坛内的短信息,现在才看到,真对不起大神啊
|
能力值:
( LV2,RANK:10 )
|
-
-
14 楼
LeoSky,能不能也发我一份啊,我最近也在这方面资料:xilige9527@gmail.com
|
能力值:
( LV2,RANK:10 )
|
-
-
15 楼
请求帮助,遇到同样的问题。。最小化的窗口,怎么截图?
|
能力值:
( LV2,RANK:10 )
|
-
-
16 楼
刚好碰到这个问题,我用网上的PrintWindow的例子,截到的是黑屏
恳请大神指点,21cnchong@21cn.com
|
能力值:
( LV2,RANK:10 )
|
-
-
17 楼
http://www.codeproject.com/Articles/20651/Capturing-Minimized-Window-A-Kid-s-Trick/
|
能力值:
( LV2,RANK:10 )
|
-
-
18 楼
我下载了他的demo,测试其他窗口时可以截到的,但我想要的窗口他也是截到黑屏啊!!
|