c:=TBitmap.Create;
  c.Canvas.Handle:=GetDC(0);  d:=TBitmap.Create;
  d.Canvas.CopyRect(rect(0,0,self.ClientWidth,self.ClientHeight),c.Canvas,rect(left,top,left+clientwidth,top+clientheight));  ReleaseDC(0, c.handle);  d.SaveToFile('c:\xx.bmp');怎么d里面什么都没有?

解决方案 »

  1.   

    procedure CopyCurrentDesktop(IncludeCur:Boolean);(为True时有鼠标指针,为Flase时没有鼠标指针)
    var 
     DesktophWnd:hWnd;
     DesktopDC:hWnd;
     CursorhWnd:hWnd;
     CurPos:Tpoint;
     Rect:TRect; 
     Bitmap:TBitmap;
    begin
     DesktophWnd := GetDesktopWindow();
     DesktopDC := GetDC(DesktophWnd);
     GetWindowRect(DesktophWnd, Rect);
     if IncludeCur then
      begin
       CursorhWnd:=GetCursor();            //捕获当前鼠标指针句柄
       GetCursorPos(CurPos);
      end;                  //获取当前鼠标指针的位置坐标
     Bitmap := TBitmap.Create;//生成一个Tbitmap类型的实例对象
     Bitmap.Width := Rect.Right-Rect.Left; 
     Bitmap.Height := Rect.Bottom-Rect.Top; 
     BitBlt(Bitmap.Canvas.Handle, 0, 0,
     Bitmap.Width, Bitmap.Height, DesktopDC, 0, 0, SRCCOPY);//在抓取到的位图对象上绘制鼠标
     if IncludeCur then
      DrawIcon(Bitmap.Canvas.Handle, CurPos.X, CurPos.Y, CursorhWnd);
     ReleaseDC(DesktophWnd, DesktopDC); 
     Bitmap.SaveToFile('C:\Desktop.bmp'); //使用类方法SaveToFile保存文件
     Bitmap.Free;
     ShowMessage('成功抓取屏幕并保存图像至C:\Desktop.bmp文件!');
    end;
      

  2.   

    c.Canvas.Handle:=GetDC('DISPLAY');
    或者是CreateDC('DISPLAY', ...);年代久远,记不清了。
      

  3.   

    unit Unit1;interfaceuses
       Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
       Dialogs, StdCtrls, Buttons, ExtCtrls;type
       TForm1 = class(TForm)
          Image1: TImage;
          BitBtn1: TBitBtn;
          procedure BitBtn1Click(Sender: TObject);
       private
          { Private declarations }
       public
          { Public declarations }
       end;var
       Form1: TForm1;implementation{$R *.dfm}procedure ScreenCapture(Bmp: TBitmap);
    var
       DeskWnd: HWnd;
       DeskDC: HDC;
       DeskCv: TCanvas;
       R: TRect;
       W, H: Integer;
    begin
       if Bmp = nil then Exit;
       DeskWnd := GetDesktopWindow;
       DeskDC := GetWindowDC(DeskWnd);
       DeskCv := TCanvas.Create;
       DeskCv.Handle := DeskDC;
       W := Screen.Width;
       H := Screen.Height;
       R := Bounds(0, 0, W, H);
       try
          Bmp.HandleType := bmDIB;
          Bmp.PixelFormat := pf24Bit;
          Bmp.Width := W;
          Bmp.Height := H;
          Bmp.Canvas.CopyMode := cmSrcCopy;
          Bmp.Canvas.CopyRect(R, DeskCv, R);
       finally
          DeskCv.Free;
          ReleaseDC(DeskWnd, DeskDC);
       end;
    end; {Marco Lange}procedure TForm1.BitBtn1Click(Sender: TObject);
    begin
       ScreenCapture(image1.Picture.Bitmap);
    end;end.