Hej,
W moim programie potrzebuję robić screenshoty z gry Medal of Honor Allied Assault, która chodzi na Open/3dfx/MiniGL. Napisałem taki kod, jednak wyskakuje błąd access violation i "Canvas does not allow drawing"... Czytałem, że jest to spowodowane małymi zasobami GDI. Jak ich trochę zwolnić? Ewentualnie w jaki inny sposób można programowo zrobić screenshota aplikacji na OGLu?
procedure TForm1.Timer1Timer(Sender: TObject);
var
wHandle,procHandle : tHandle;
process : tProcessEntry32;
pid : integer;
procFileName, MoHAAFileName : string;
begin
wHandle := CreateToolHelp32SnapShot(TH32CS_SNAPALL,0);
process.dwSize := SizeOf(process);
if integer(Process32First(wHandle,process))<>0 then
repeat
pid := process.th32ProcessID;
procHandle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,FALSE,process.th32ProcessID);
procFileName := lowerCase(process.szExeFile);
MoHAAFileName := lowerCase(GetMoHAAPath + '\MOHAA.EXE');
if (procFileName = MoHAAFileName) then doScreenshot(procHandle);
until integer(Process32Next(wHandle,process)) = 0;
CloseHandle(wHandle);
end;
procedure TForm1.doScreenshot(windowHandle : THandle);
var
Can : TCanvas;
B : TBitmap;
J : TJPEGImage;
begin
try
Can := TCanvas.Create;
Can.Handle := GetWindowDC(windowHandle);
B := TBitmap.Create;
B.Width := Screen.Width;
B.Height := Screen.Height;
B.Canvas.CopyRect(Rect(0, 0, Screen.Width, Screen.Height), Can, Rect(0, 0, Screen.Width, Screen.Height));
J.Assign(B);
try
J.SaveToFile('C:\plik.jpg');
except
raise Exception.Create('Bład w zapisie pliku...');
end;
finally
Can.Free;
B.Free;
J.Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Timer1.Enabled := False;
end;
function TForm1.GetMoHAAPath : string;
var Reg : TRegistry;
begin
Reg := TRegistry.Create;
Reg.RootKey := HKEY_CURRENT_USER;
Reg.OpenKey('SOFTWARE\2015\MOHAA',True);
Result := Reg.ReadString('basepath');
end;
Z góry dzięki,
Rookie One