例如设置了AlphaBlend的窗体,或者其他半透明窗体,如何给它截图。
我是在做一个截图工具,不要告诉我使用XX截图软件。
我用传统方法(GetDC(0))截不到这种窗体。
还有不要破坏剪贴板数据。
请知道的朋友帮忙。

解决方案 »

  1.   

    不用顶了,答案来了。
    procedure CaptureScreenWithAlphaWnd(strFileName: string);
    const
        CAPTUREBLT = $40000000;
    var
        hdcScreen: HDC;
        hdcCompatible: HDC;
        bmp: TBitmap;
        hbmpScreen: HBITMAP;
    begin
        hdcScreen := CreateDC('DISPLAY', nil, nil, nil);
        hdcCompatible := CreateCompatibleDC(hdcScreen);    hbmpScreen := CreateCompatibleBitmap(hdcScreen,
                GetDeviceCaps(hdcScreen, HORZRES),
                GetDeviceCaps(hdcScreen, VERTRES));    bmp := TBitmap.Create;
        bmp.PixelFormat := pf24bit;    try
            SelectObject(hdcCompatible, hbmpScreen);        bmp.Handle := hbmpScreen;
            BitBlt(hdcCompatible,
                    0, 0,
                    bmp.Width, bmp.Height,
                    hdcScreen,
                    0, 0,
                    SRCCOPY or CAPTUREBLT);        bmp.SaveToFile(strFileName);
        finally
            bmp.Free;        DeleteDC(hdcScreen);
            DeleteDC(hdcCompatible);
            DeleteObject(hbmpScreen);
        end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
        CaptureScreenWithAlphaWnd('C:\ccrun\123.bmp');
    end;
    效果图在这里:
      

  2.   

    明白了,关键在于CAPTUREBLT,GetDC还是CreateDC无所谓的。
    可惜Delphi没有定义CAPTUREBLT这个光栅操作码,得自定义。
    多谢ccrun,以及lantianhf。