写一个简单抓屏函数的来测试下,以下采用Win32 API方式编写: HBITMAP Cap Screen() { HDC hDisp DC,hMem DC; // 获取屏幕DC hDisp DC = Create DC("DISPLAY",NULL,NULL,NULL); hMem DC = Create Compatible DC(hDisp DC); int cx,cy; cx = Get System Metrics(SM CXSCREEN); cy = Get System Metrics(SM CYSCREEN); HBITMAP hSnap Bt,hOld Bt; hSnap Bt = Create Compatible Bitmap(hDisp DC,cx,cy); hOld Bt = (HBITMAP)Select Object(hMem DC,hSnap Bt); Bit Blt(hMem DC,0,0,cx,cy,hDisp DC,0,0,SRCCOPY); // cleanup Select Object(hMem DC,hOld Bt); Delete DC(hMem DC); Delete DC(hDisp DC); return hSnap Bt; } 测试发现果然无法截取到使用Window Blinds模拟vista半透明主题的窗口栏,还有所有半透明的窗口! 利用Spy++对以上无法截取到的窗口进行抓捕,发现这些窗口都具有WS EX LAYERED这个扩展属性,又仔细看了下MSDN中关于Bit Blt的说明,原型如下: BOOL Bit Blt( HDC hdc Dest, // 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 hdc Src, // handle to source DC int nXSrc, // x-coordinate of source upper-left corner int nYSrc, // y-coordinate of source upper-left corner DWORD dw Rop // raster operation code ); 对于其他参数我们并不用关心,主要该注意下最后这个参数dw Rop: [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 然后试着再调用Bit Blt时组合上这个参数,结果果然可以截获半透明窗口了! 上述截屏函数也可以用MFC方式来写: HBITMAP Cap Screen() { CDC disp DC,mem DC; disp DC.Create DC("DISPLAY",NULL,NULL,NULL); mem DC.Create Compatible DC(&disp DC); int cx,cy; cx = Get System Metrics(SM CXSCREEN); cy = Get System Metrics(SM CYSCREEN); CBitmap snap Bt,*pOld Bt; snap Bt.Create Compatible Bitmap(&disp DC,cx,cy); pOld Bt = mem DC.Select Object(&snap Bt); // Bit Blt使用CAPTUREBLT参数 mem DC.Bit Blt(0,0,cx,cy,&disp DC,0,0,SRCCOPY | CAPTUREBLT); // cleanup mem DC.Select Object(pOld Bt); // 不能返回snap Bt.m h Object或snap Bt.Get Safe Handle() // 因为CBitmap对象在析构时会调用Delete Object来释放位图句柄 return (HBITMAP)snap Bt.Detach(); }