- unit unir_principal;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, jpeg,
- dglOpenGL, StdCtrls;
- type
- TForm1 = class(TForm)
- Button1: TButton;
- Button2: TButton;
- Button3: TButton;
- ListBox1: TListBox;
- Label1: TLabel;
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure Button3Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- private
- hotkey1 : Integer;
- procedure CaptureScreen2(const AFileName: string);
- procedure WMHotKey(var Msg : TWMHotKey); message WM_HOTKEY;
- { Private declarations }
- public
- RC : HGLRC;
- DC : HDC;
- FoundWindow : hwnd;
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- function AllWindows(wHnd: THandle; List: TStringList): Bool; stdcall;
- var
- Buffer: array[0..255] of char;
- begin
- SendMessage(wHnd, WM_GETTEXT, 255, LongInt(@Buffer[0]));
- if (Buffer <> '') and IsWindow(wHnd) then
- begin
- List.AddObject(Buffer, TObject(wHnd));
- end;
- Result := True;
- end;
- {$R *.dfm}
- procedure TForm1.CaptureScreen2(const AFileName: string);
- var
- hWin: HWND;
- MyDC: HDC;
- MyRC: HGLRC;
- pPixels: PIntegerArray;
- pLine: PIntegerArray;
- bmp: TBitmap;
- i, j, iWidth, iHeight: Integer;
- rgba: Cardinal;
- // ListIndex : Integer;
- begin
- InitOpenGL;
- iWidth := Screen.Width;
- iHeight := Screen.Height;
- // ListIndex := ListBox1.ItemIndex;
- // hWin := THandle(ListBox1.Items.Objects[ListIndex]);
- // hWin := GetDesktopWindow;
- // MyDC := GetDc(hWin);
- // MyRC := CreateRenderingContext(MyDC, [opDoubleBuffered], 24, 16, 0, 0, 0, 0);
- // ActivateRenderingContext(MyDC, MyRC);
- try
- bmp := TBitmap.Create;
- try
- GetMem(pPixels, iWidth * iHeight * 4);
- try
- bmp.PixelFormat := pf32bit;
- bmp.Height := iHeight;
- bmp.Width := iWidth;
- glPixelStorei(GL_PACK_ALIGNMENT, 1);
- glReadBuffer(GL_FRONT);
- glReadPixels(0, 0, iWidth, iHeight, GL_RGBA, GL_UNSIGNED_BYTE, pPixels);
- for i := 0 to iHeight-1 do
- begin
- pLine := bmp.ScanLine[i];
- for j := 0 to iWidth-1 do
- begin
- rgba := pPixels[(iHeight-1-i) * iWidth + j];
- pLine^[j] :=
- (rgba and $FF000000) or
- ((rgba shl 16) and $00FF0000) or
- (rgba and $0000FF00) or
- ((rgba shr 16) and $000000FF); //abgr -> argb
- end;
- end;
- bmp.SaveToFile(AFileName);
- finally
- FreeMem(pPixels);
- end;
- finally
- bmp.Free;
- end;
- finally
- DeactivateRenderingContext;
- wglDeleteContext(myRC);
- ReleaseDC(GetDesktopWindow, myDC);
- end;
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- const MOD_CONTROL = 2;
- VK_A = 65;
- begin
- hotkey1 := GlobalAddAtom('Hotkey1');
- RegisterHotKey(handle, hotkey1, MOD_CONTROL,VK_A);
- end;
- procedure TForm1.FormDestroy(Sender: TObject);
- begin
- UnRegisterHotKey(handle, hotkey1);
- end;
- procedure TForm1.WMHotKey(var Msg: TWMHotKey);
- begin
- if msg.HotKey = hotkey1 then button2.Click;
- end;
- procedure TForm1.Button1Click(Sender: TObject);
- Var
- ListIndex : Integer;
- begin
- InitOpenGL;
- ListIndex := ListBox1.ItemIndex;
- FoundWindow := THandle(ListBox1.Items.Objects[ListIndex]);
- if foundwindow > 0 then
- begin
- DC := GetDC(FoundWindow);
- RC := CreateRenderingContext(DC, [opDoubleBuffered], 32, 24, 0, 0, 0, 0);
- ActivateRenderingContext(DC, RC);
- glEnable(GL_DEPTH_TEST);
- glDepthFunc(GL_LESS);
- glClearColor(0,0,0,0);
- Form1.Caption := inttostr (FoundWindow);
- end
- else
- Form1.Caption := 'Game Not Found';
- end;
- procedure TForm1.Button2Click(Sender: TObject);
- begin
- CaptureScreen2(FormatDateTime('dd_mm_yyyy', now) + '_' + FormatDateTime('hh_mm_ss', now) + '.bmp');
- end;
- procedure TForm1.Button3Click(Sender: TObject);
- Var
- s: string;
- I: Integer;
- begin
- ListBox1.Clear;
- EnumWindows(@AllWindows, LParam(ListBox1.Items));
- end;
- end.