Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[TUT-Delphi] BitBlt/Print Screen/GetPixel! (1/5 easy)

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
compactwater
I post too much
Reputation: 8

Joined: 02 Aug 2006
Posts: 3923

PostPosted: Thu Jun 21, 2007 12:46 am    Post subject: [TUT-Delphi] BitBlt/Print Screen/GetPixel! (1/5 easy) Reply with quote

I got bored because of the server check + website maintenance, so I'm writing this to (maybe) enlighten someone.
I've taken the agonizing 5 minutes to write this, so I hope you like it. Wink
I rated this 1/5, because it's just so easy. Theres really nothing, at all, what-so-ever, that you would have to know about Pascal to make this work. You can even read it, like a book, and understand what's going on, and what it's doing.

BitBlt!

Now then, first off, add this anywhere under implementation:
Note: This isn't required, it just makes things alot easier to read...
Code:
function ShortBitBlt: TBitmap;
var
  Desktop: HDC;
begin
  Result  := TBitmap.Create;
  Desktop := GetDC(0);
  try
    try
      Result.PixelFormat := pf32bit;
      Result.Width := Screen.Width;
      Result.Height := Screen.Height;
      BitBlt(Result.Canvas.Handle, 0, 0, Result.Width, Result.Height, Desktop, 0, 0, SRCCOPY);
      Result.Modified := True;
    finally
      ReleaseDC(0, Desktop);
    end;
  except
    Result.Free;
    Result := nil;
  end;
end;


Now, make a button, and an image. Make the image whatever size, as long as you can see it.
Doubleclick on the button, it should take you to "procedure TForm1.Button1Click(Sender: TObject);"
After "Begin" write this:
Code:
Image1.Picture.Bitmap:=ShortBitBlt;

(See, much easier to read!)

That will use BitBlt and get the screen, then put it on "Image1".

Print Screen!

There are two ways you can do this, emulating the "Print Screen" button, then pasting it into an image, or using this simple code, that won't require anything extra for a "protected" window.
Code:
procedure ScreenShot(Bild: TBitMap);
var
  c: TCanvas;
  r: TRect;
begin
  c := TCanvas.Create;
  c.Handle := GetWindowDC(GetDesktopWindow);
  try
    r := Rect(0, 0, Screen.Width, Screen.Height);
    Bild.Width := Screen.Width;
    Bild.Height := Screen.Height;
    Bild.Canvas.CopyRect(r, c, r);
  finally
    ReleaseDC(0, c.Handle);
    c.Free;
  end;
end;


Add that anywhere under implementation.

Now, make a button, doubleclick on it, and write this:
Code:
ScreenShot(Image1.Picture.BitMap);

Very simple, right? Wink

GetPixel!
(This will only work on non-protected processes)

Add a button, doubleclick on it, and add this:
Code:
var
  MousePos: TPoint;
  ScreenDC: HDC;
begin
GetCursorPos(MousePos);
ScreenDC:=GetDC(0);
Shape1.Brush.Color:=GetPixel(ScreenDC, MousePos.X, MousePos.Y);
ReleaseDC(0, ScreenDC);

Make sure you overwrite it from the old "begin"!

Bonus!
Getting colours from pixels, it's easier than you think!

Code:
GetRValue(image1.Picture.Bitmap.Canvas.Pixels[MousePos.X,MousePos.Y]);
GetGValue(image1.Picture.Bitmap.Canvas.Pixels[MousePos.X,MousePos.Y]);
GetBValue(image1.Picture.Bitmap.Canvas.Pixels[MousePos.X,MousePos.Y]);


That'll snatch the colour from your mouse (Translated onto "Image1")
Back to top
View user's profile Send private message
Maverick
Master Cheater
Reputation: 0

Joined: 24 Dec 2006
Posts: 451

PostPosted: Thu Jun 21, 2007 1:59 am    Post subject: Reply with quote

Upload Delphi please? x.x
Back to top
View user's profile Send private message
Icos
Grandmaster Cheater
Reputation: 0

Joined: 12 May 2007
Posts: 524

PostPosted: Thu Jun 21, 2007 2:08 am    Post subject: Reply with quote

Why do people rarely use C/C++? *cries*
Anyway it looks neat. Nice job.
Back to top
View user's profile Send private message
ravicus
Master Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 464

PostPosted: Thu Jun 21, 2007 9:21 am    Post subject: Reply with quote

Delphi that I uploaded:
http://fileho.com/download/09ed66864237/Delphi7enterprise.exe.html

_________________
Back to top
View user's profile Send private message
compactwater
I post too much
Reputation: 8

Joined: 02 Aug 2006
Posts: 3923

PostPosted: Thu Jun 21, 2007 12:40 pm    Post subject: Reply with quote

Icos wrote:
Why do people rarely use C/C++? *cries*
Anyway it looks neat. Nice job.

Thanks. Razz

If anyone has any suggestions... Just post or PM me!
Back to top
View user's profile Send private message
Simsgy
Grandmaster Cheater
Reputation: 0

Joined: 07 May 2007
Posts: 581
Location: My new avatar <3

PostPosted: Sun Jun 24, 2007 4:38 am    Post subject: Reply with quote

Nice work, I will use it for the project I am working at.
P.S, GetPixel! is working on MapleStory?

_________________

Designer, WebMaster and a Delphi programmer.
TrPlayer, my biggest Delphi project hosted on SourceForge.net
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
compactwater
I post too much
Reputation: 8

Joined: 02 Aug 2006
Posts: 3923

PostPosted: Sun Jun 24, 2007 5:05 am    Post subject: Reply with quote

Actually, GetPixel is the only method that doesn't work. I was surprised that BitBlt worked, but knew that Print Screen would work.
Back to top
View user's profile Send private message
Simsgy
Grandmaster Cheater
Reputation: 0

Joined: 07 May 2007
Posts: 581
Location: My new avatar <3

PostPosted: Sun Jun 24, 2007 5:37 am    Post subject: Reply with quote

Alright, what is BitBlt doing?
P.S, is the bonus working on MapleStory?

_________________

Designer, WebMaster and a Delphi programmer.
TrPlayer, my biggest Delphi project hosted on SourceForge.net
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites