请问如何抓屏

解决方案 »

  1.   

    var
      RectWidth,RectHeight:integer;
      SourceDC,DestDC,Bhandle:integer;
      Bitmap:TBitmap;
    begin
      RectWidth:=RightPos-LeftPos;
      RectHeight:=BottomPos-TopPos;
      SourceDC:=CreateDC('DISPLAY','','',nil);
      DestDC:=CreateCompatibleDC(SourceDC);
      Bhandle:=CreateCompatibleBitmap(SourceDC,RectWidth,RectHeight);
      SelectObject(DestDC,Bhandle);
      BitBlt(DestDC,0,0,RectWidth,RectHeight,SourceDC,LeftPos,TopPos,SRCCOPY);
      Bitmap:=TBitmap.Create;
      Bitmap.Handle:=BHandle;
      BitMap.SaveToFile(FileName);
    end;
      

  2.   

    function CaptureScreen(): TBitmap;
    var
     DC : HDC;
     ABitmap  : TBitmap;
     CI: TCursorInfo;
    begin
     DC := GetDC(GetDesktopWindow);
     ABitmap := TBitmap.Create;
     try
        ABitmap.Width := GetDeviceCaps(DC,HORZRES);
        ABitmap.Height := GetDeviceCaps(DC,VERTRES);    BitBlt(ABitmap.Canvas.Handle,
               0,
               0,
               ABitmap.Width,
               ABitmap.Height,
               DC,
               0,
               0,
               SRCCOPY);
        ZeroMemory(@CI,SizeOf(CI));
        CI.cbSize := SizeOf(CI);
        if GetCursorInfo(CI) then
        DrawIconEx(ABitmap.Canvas.Handle,
                   CI.ptScreenPos.X,
                   CI.ptScreenPos.Y,
                   CI.hCursor,
                   16,
                   16,
                   0,
                   0,
                   DI_DEFAULTSIZE OR DI_NORMAL); finally
        ReleaseDC(GetDesktopWindow,DC);
     end;
     Result := ABitmap;
    end;
    转贴