var
Bit:TBitMap;
begin
  Bit:=TBitMap.Create;
  Bit.Canvas.Handle:=GetWindowDc(0);
  Bit.SaveToFile('D:\B.Bmp');
end怎么保存的图片是一个空图片啊。郁闷,请帮我解决
还有Bitblt这个函数是干什么的啊
TCanvas的pie是干什么的啊?
最好能举个例子

解决方案 »

  1.   

    procedure CopyCurrentDesktop(IncludeCur:Boolean);
    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;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
     Button2.Enabled:=False;
     if RadioButton1.Checked then
      CopyCurrentDesktop(True)
     else
      CopyCurrentDesktop(False);
     Button2.Enabled:=True; 
    end;
      

  2.   

    Bit.Canvas.Handle被赋值没什么意义,你应该将GetWindowDc(0)复制到Bit.Canvas上。BitBlt在帮助里应该有说明。就是将一个位图绘制在一个画布上。TCancas.pie也有说明,就是绘制椭圆(按照其被包围的矩形)。