mainunit.pas
上传用户:psxgmh
上传日期:2013-04-08
资源大小:15112k
文件大小:2k
- unit mainunit;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls,ShellApi;
- type
- TForm1 = class(TForm)
- GroupBox1: TGroupBox;
- RadioButton1: TRadioButton;
- RadioButton2: TRadioButton;
- Button1: TButton;
- Button2: TButton;
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- 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;
- procedure TForm1.Button2Click(Sender: TObject);
- begin
- ShellExecute(handle,'open','C:Desktop.bmp',nil,nil,SW_Normal);
- end;
- end.