透明窗口截屏无效解决方法
来源:互联网 发布:sql sum函数 group by 编辑:程序博客网 时间:2024/05/10 18:34
最近试过几套截图软件,发现其中有些无法实现对半透明窗口或主题的图片截取,包括早期版本的QQ截图工具也无法截取,于是打算写一个简单抓屏函数的来测试下,以下采用Win32 API方式编写:
HBITMAP CapScreen()
{
HDC hDispDC,hMemDC;
// 获取屏幕DC
hDispDC = CreateDC("DISPLAY",NULL,NULL,NULL);
hMemDC = CreateCompatibleDC(hDispDC);
int cx,cy;
cx = GetSystemMetrics(SM_CXSCREEN);
cy = GetSystemMetrics(SM_CYSCREEN);
HBITMAP hSnapBt,hOldBt;
hSnapBt = CreateCompatibleBitmap(hDispDC,cx,cy);
hOldBt = (HBITMAP)SelectObject(hMemDC,hSnapBt);
BitBlt(hMemDC,0,0,cx,cy,hDispDC,0,0,SRCCOPY);
// cleanup
SelectObject(hMemDC,hOldBt);
DeleteDC(hMemDC);
DeleteDC(hDispDC);
return hSnapBt;
}
测试发现果然无法截取到使用WindowBlinds模拟vista半透明主题的窗口栏,还有所有半透明的窗口!
利用Spy++对以上无法截取到的窗口进行抓捕,发现这些窗口都具有WS_EX_LAYERED这个扩展属性,又仔细看了下MSDN中关于BitBlt的说明,原型如下:
BOOL BitBlt(
HDC hdcDest, // handle to destination DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
HDC hdcSrc, // handle to source DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
DWORD dwRop // raster operation code
);
对于其他参数我们并不用关心,主要该注意下最后这个参数dwRop:
[in] Specifies a raster-operation code. These codes define how the color data for the source rectangle is to be combined with the color data for the destination rectangle to achieve the final color. The following list shows some common raster operation codes.
反复看过几次所有参数的含义后发现对于参数CAPTUREBLT,有如下描述:
Windows 98, Windows 2000: Includes any windows that are layered on top of your window in the resulting image. By default, the image only contains your window.
猜想大概就是这个了,不过在引用这个参数时貌似要先更新vc6的SDK,否则会提示CAPTUREBLT未定义,不过也可以手工来给它作个宏定义:
#ifndef CAPTUREBLT
#define CAPTUREBLT 0x40000000
#endif
然后试着再调用BitBlt时组合上这个参数,结果果然可以截获半透明窗口了!
上述截屏函数也可以用MFC方式来写:
HBITMAP CapScreen()
{
CDC dispDC,memDC;
dispDC.CreateDC("DISPLAY",NULL,NULL,NULL);
memDC.CreateCompatibleDC(&dispDC);
int cx,cy;
cx = GetSystemMetrics(SM_CXSCREEN);
cy = GetSystemMetrics(SM_CYSCREEN);
CBitmap snapBt,*pOldBt;
snapBt.CreateCompatibleBitmap(&dispDC,cx,cy);
pOldBt = memDC.SelectObject(&snapBt);
// BitBlt使用CAPTUREBLT参数
memDC.BitBlt(0,0,cx,cy,&dispDC,0,0,SRCCOPY | CAPTUREBLT);
// cleanup
memDC.SelectObject(pOldBt);
// 不能返回snapBt.m_hObject或snapBt.GetSafeHandle()
// 因为CBitmap对象在析构时会调用DeleteObject来释放位图句柄
return (HBITMAP)snapBt.Detach();
}
- 透明窗口截屏无效解决方法
- 透明窗口截屏无效解决方法
- 透明窗口截屏无效解决方法
- QWidget子窗口中setStyleSheet无效,解决方法
- Dialog设置背景透明无效,在安卓5.0系统上无效解决方法!
- 关于截屏截取不到透明窗口的问题
- JFrame.paint(Graghics g) 方法重绘 窗口透明 解决方法
- 透明窗口
- 透明窗口
- 透明窗口
- 透明窗口
- 透明窗口
- flash透明\flash置底无效\flash遮挡div的解决方法 兼容Firefox ,IE,chrome浏览器
- 透明窗口. 顶层窗口.总结
- 透明窗口和窗口阴影
- 使窗口透明
- 创建透明窗口
- MyGUI支持透明窗口
- 1227等值数目
- 上传文件form表单enctype="multipart/form-data"传值解决办法(代原代码)
- Ubuntu 12.04安装firefox 26中的flash plugin方法
- 1229求奇数的乘积
- STL
- 透明窗口截屏无效解决方法
- 1231绝对值排序
- java.lang.NoClassDefFoundError: Lorg/hibernate/cache/CacheProvider;
- 3Sum
- 【cocos2d-x IOS游戏开发-城市跑酷10】完善繁荣的城市街区及地形图类
- 处理机调度算法(时间调度)
- shell 中比较多碰见的符号
- Find命令大全
- CvArr、Mat、CvMat、IplImage、BYTE转换