Solved

Taking a shot of the screen?

Posted on 2000-05-13
13
225 Views
Last Modified: 2010-04-04
How can I take a shot of the screen (by not using a tbitmap component)? I need to do this in a console application where exe size is critical so i am not using and graphic libraries or forms.pas

--Olympus
0
Comment
Question by:Olympus
13 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 2807633
hi,
as you are a new user you should probably read here:

http://www.experts-exchange.com/info/howto.htm#20
0
 

Author Comment

by:Olympus
ID: 2807680
i know, unfortunately i have no points to offer as of yet.
0
 

Author Comment

by:Olympus
ID: 2807688
Adjusted points from 0 to 50
0
 

Author Comment

by:Olympus
ID: 2807689
k i just got more, here...
0
 

Expert Comment

by:alexdg
ID: 2807733
0
 
LVL 15

Expert Comment

by:simonet
ID: 2807754
Here's a much better approach than the one suggested:

procedure ScreenShot(x : integer;
                     y : integer;
                     Width : integer;
                     Height : integer;
                     bm : TBitMap);
var
  dc: HDC;
  lpPal : PLOGPALETTE;
begin
 {test width and height}
  if ((Width = 0) OR (Height = 0)) then begin
    exit;
  end;
  bm.Width := Width;
  bm.Height := Height;
 {get the screen dc}
  dc := GetDc(0);
  if (dc = 0) then begin
    exit;
  end;
 {do we have a palette device?}
  if (GetDeviceCaps(dc, RASTERCAPS) AND
      RC_PALETTE = RC_PALETTE) then begin
   {allocate memory for a logical palette}
    GetMem(lpPal,
           sizeof(TLOGPALETTE) +
           (255 * sizeof(TPALETTEENTRY)));
   {zero it out to be neat}
    FillChar(lpPal^,
             sizeof(TLOGPALETTE) +
             (255 * sizeof(TPALETTEENTRY)),
             #0);
   {fill in the palette version}
    lpPal^.palVersion := $300;
   {grab the system palette entries}
    lpPal^.palNumEntries :=
      GetSystemPaletteEntries(dc,
                              0,
                              256,
                              lpPal^.palPalEntry);
    if (lpPal^.PalNumEntries <> 0) then begin
     {create the palette}
      bm.Palette := CreatePalette(lpPal^);
    end;
    FreeMem(lpPal, sizeof(TLOGPALETTE) +
            (255 * sizeof(TPALETTEENTRY)));
  end;
 {copy from the screen to the bitmap}
  BitBlt(bm.Canvas.Handle,
         0,
         0,
         Width,
         Height,
         Dc,
         x,
         y,
         SRCCOPY);
 {release the screen dc}
  ReleaseDc(0, dc);
end;



This one handles palette entries in a much better fashion than simply capturing HDC(0).

Alex
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 3

Expert Comment

by:bryan7
ID: 2807785
listenning
0
 

Author Comment

by:Olympus
ID: 2807797
"(by not using a tbitmap component)"
0
 
LVL 15

Expert Comment

by:simonet
ID: 2807898
Where do you want to store the resulting image then? It must be stored somewhere.

Alex
0
 

Author Comment

by:Olympus
ID: 2808561
it can be stored anywhere as long as it doesnt use Forms.Pas or Graphics.pas, my console app cant increase much more in size (its already 119kb)
0
 
LVL 15

Accepted Solution

by:
simonet earned 50 total points
ID: 2808804
Use the code I sent you with a Windows TBitmap class:

var
   bmp : Windows.TBitmap;


It doesn't add all the overhead of a Delphi Bitmap class, so your application will remain just as light.

Alex
0
 

Author Comment

by:Olympus
ID: 2808879
as  a followup question, how would i do jpeg compression or some sort of bmp compression without using the delphi classes again?
0
 

Author Comment

by:Olympus
ID: 2808996
and how would i use BitBlt with the windows bitmap?
the first value of it is a handle, what can i put there?

BitBlt(<whatgoeshere?>, 0, 0, bm.bmWidth, bm.bmHeight, hDC, 0, 0, SRCCOPY);
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now