1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107:
| unit Main;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, pngimage, StdCtrls, ExtCtrls, XPMan, FileCtrl, ComCtrls, HookDllInterface, SelectKey;
[...]
var MainForm: TMainForm;
Const Title = 'Paint';
implementation
{$R *.dfm}
procedure TMainForm.StartStopBtnClick(Sender: TObject); begin Catching := not Catching; if not Catching then begin StartStopBtn.Caption := 'Start Catching'; EndCatching; end else begin StartStopBtn.Caption := 'End Catching'; BeginCatching; end; end;
procedure TMainForm.FormCreate(Sender: TObject); begin UpdateOptions(self); Catching := false; HookKeyEChange(self); UpdateCatchFunction(self.CatchScreenshoot); end;
procedure TMainForm.HookKeyEChange(Sender: TObject); begin UpdateCatchKey(strtoint(HookKeyE.Text)); end;
procedure TMainForm.BeginCatching; begin WindowID := FindWindow(nil,Title); if WindowID = 0 then begin ShowMessage('Please start Paint before starting to catch Screenshoots'); StartStopBtn.Caption := 'Start Catching'; Catching := false; exit; end; InstallHook; end;
procedure TMainForm.EndCatching; begin UninstallHook; end;
function FormularSaveScreenShot(FileName: String; h : hWnd): Boolean; var Rec: TRect; iWidth, iHeight: Integer; begin with TBitmap.Create do try GetWindowRect(h, Rec);
iWidth := Rec.Right - Rec.Left; iHeight := Rec.Bottom - Rec.Top;
Width := iWidth; Height := iHeight;
BitBlt(Canvas.Handle, 0, 0, iWidth, iHeight, GetWindowDC(h), 0, 0, SRCCOPY);
Result := True;
try SaveToFile(Filename) except Result := False end; finally ReleaseDC(h, GetWindowDC(h)); Free; end; end;
procedure TMainForm.CatchScreenshoot; begin FormularSaveScreenShot('test.bmp', WindowID); end;
procedure TMainForm.Button1Click(Sender: TObject); var tmp: word; begin SelectKeyF.ShowModal; tmp := SelectKeyF.PressedKey; HookKeyE.Text := inttostr(tmp); end;
end. |