Advertisement
rikokurniawan

Aplikasi Print Screen

Jan 17th, 2013
625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.75 KB | None | 0 0
  1. unit USS;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, StdCtrls, ExtCtrls, ExtDlgs, jpeg ;
  8.  
  9. type
  10.   TFPS = class(TForm)
  11.     Bevel1: TBevel;
  12.     Image1: TImage;
  13.     Button1: TButton;
  14.     SavePictureDialog1: TSavePictureDialog;
  15.     Button2: TButton;
  16.     Label1: TLabel;
  17.     procedure Button1Click(Sender: TObject);
  18.     procedure Button2Click(Sender: TObject);
  19.     procedure FormCreate(Sender: TObject);
  20.   private
  21.     { Private declarations }
  22.     procedure TakeShot(activeWindow : boolean);
  23.   public
  24.     { Public declarations }
  25.   end;
  26.  
  27. var
  28.   FPS: TFPS;
  29.  
  30. implementation
  31.  
  32. {$R *.dfm}
  33.  
  34. procedure ScreenShot(activeWindow: bool; destBitmap : TBitmap) ;
  35. var
  36.   w,h : integer;
  37.   DC : HDC;
  38.   hWin : Cardinal;
  39.   r : TRect;
  40. begin
  41.   if activeWindow then
  42.   begin
  43.     hWin := GetForegroundWindow;
  44.     dc := GetWindowDC(hWin);
  45.     GetWindowRect(hWin,r);
  46.     w := r.Right - r.Left;
  47.     h := r.Bottom - r.Top;
  48.   end
  49.   else
  50.   begin
  51.     hWin := GetDesktopWindow;
  52.     dc := GetDC(hWin);
  53.     w := GetDeviceCaps (DC, HORZRES);
  54.     h := GetDeviceCaps (DC, VERTRES);
  55.   end;
  56.  
  57.   try
  58.    destBitmap.Width := w;
  59.    destBitmap.Height := h;
  60.    BitBlt(destBitmap.Canvas.Handle,
  61.           0,
  62.           0,
  63.           destBitmap.Width,
  64.           destBitmap.Height,
  65.           DC,
  66.           0,
  67.           0,
  68.           SRCCOPY) ;
  69.   finally
  70.    ReleaseDC(hWin, DC) ;
  71.   end;
  72. end;
  73.  
  74. procedure TFPS.TakeShot(activeWindow : boolean);
  75. var
  76.   b:TBitmap;
  77. begin
  78.   b := TBitmap.Create;
  79.   try
  80.     ScreenShot(activeWindow, b);
  81.     Image1.Picture.Bitmap.Assign(b);
  82.   finally
  83.     b.FreeImage;
  84.     FreeAndNil(b);
  85.   end;
  86. end;
  87.  
  88. procedure TFPS.Button1Click(Sender: TObject);
  89. begin
  90. {
  91. if result = mrYes then
  92.     TakeShot(false)
  93.   else if result=mrNo then
  94.     TakeShot(true);
  95. }
  96.   if Button1.Caption='Jepreet' then Begin
  97.     TakeShot(false);
  98.     Button1.Caption:='Lagi';
  99.     Button2.Enabled:=True;
  100.     Label1.Visible:=False;
  101.   end
  102.   else if Button1.Caption='Lagi' then Begin
  103.     Image1.Picture:=NIL;
  104.     Button1.Caption:='Jepreet';
  105.     Button2.Enabled:=False;
  106.     Label1.Visible:=True;
  107.   End;
  108. end;
  109.  
  110. procedure TFPS.Button2Click(Sender: TObject);
  111. begin
  112.   If Image1.Picture <> nil then begin
  113.     If SavePictureDialog1.Execute then begin
  114.       if FileExists(SavePictureDialog1.FileName) = False then begin
  115.         Image1.Picture.SaveToFile(SavePictureDialog1.FileName);
  116.       end
  117.       else ShowMessage('Nama File Sudah ada, Silahkan Ganti yang lain');
  118.     end;
  119.   end;
  120. end;
  121.  
  122. procedure TFPS.FormCreate(Sender: TObject);
  123. begin
  124.   with SavePictureDialog1 do begin
  125.     InitialDir:=ExtractFilePath(Application.ExeName);
  126.     Filter:='JPEG Image File (*.jpg)|*.jpg';
  127.   end;
  128.   Button2.Enabled:=False;
  129. end;
  130.  
  131. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement