Solved

auto print screen

Posted on 2011-02-22
6
236 Views
Last Modified: 2012-05-11
hi how do I auto print screen?

keybd_event(VK_SNAPSHOT, 1, 0, 0);
?????
0
Comment
Question by:eNarc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 9

Accepted Solution

by:
rawinnlnx9 earned 84 total points
ID: 34955732
0
 
LVL 19

Assisted Solution

by:Thommy
Thommy earned 250 total points
ID: 34956258
Make a screenshot of a form...
function FormularScreenShot(Bmp: TBitmap; h : hWnd): Boolean;  
var  
  TheRect: TRect;  
  TheWidth, TheHeight: Integer;  
begin  
  with Bmp do try  
    GetWindowRect(h, TheRect);  
    TheWidth  := TheRect.Right - TheRect.Left;  
    TheHeight := TheRect.Bottom - TheRect.Top;  
    Width := TheWidth;  
    Height := TheHeight;  
    BitBlt(Canvas.Handle, 0, 0, TheWidth, TheHeight, GetWindowDC(h), 0, 0, SRCCOPY);  
    Result := True;  
  finally  
    ReleaseDC(h, GetWindowDC(h));  
  end;  
end;

Open in new window

0
 
LVL 19

Assisted Solution

by:Thommy
Thommy earned 250 total points
ID: 34956277
Saves form screenshot into a file...
function FormularSaveScreenShotToFile(FileName: String; h : hWnd): Boolean;  
var  
  TheRect: TRect;  
  TheWidth, TheHeight: Integer;  
begin  
  with TBitmap.Create do try  
    GetWindowRect(h, TheRect);  

 
    TheWidth  := TheRect.Right - TheRect.Left;  
    TheHeight := TheRect.Bottom - TheRect.Top;  

 
    Width := TheWidth;  
    Height := TheHeight;  

 
    BitBlt(Canvas.Handle, 0, 0, TheWidth, TheHeight, GetWindowDC(h), 0, 0, SRCCOPY);  

 
    Result := True;  

 
    try SaveToFile(Filename) except Result := False end;  
  finally  
    ReleaseDC(h, GetWindowDC(h));  
    Free;  
  end;  
end;

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Assisted Solution

by:Thommy
Thommy earned 250 total points
ID: 34956285
And also have a look at this...

How to Capture the Screen Shot of the Active Window
http://delphi.about.com/od/adptips2006/qt/captureactive.htm
0
 
LVL 32

Assisted Solution

by:Ephraim Wangoya
Ephraim Wangoya earned 83 total points
ID: 34957506
try this
uses
  Printers;

function CreateDesktopBitmap: TBitmap;
var
  DC: HDC;
  GDW: Cardinal;
  R: TRect;
begin
  GDW := GetDesktopWindow;
  DC := GetDC(GDW);
  try
    R := Rect(0, 0, GetDeviceCaps(DC, HORZRES), GetDeviceCaps(DC, VERTRES));

    Result := TBitmap.Create;
    try
      Result.Width := R.Right - R.Left;
      Result.Height := R.Bottom - R.Top;
      //copy desktop image to bitmap
      BitBlt(Result.Canvas.Handle, R.Left, R.Top, R.Right, R.Bottom, DC, 0, 0, SRCCOPY);
    except
      FreeAndNil(Result);
    end;
  finally
    ReleaseDC(GDW, DC);
  end;
end;

procedure PrintBitmap(ABitmap: TBitmap; const ARect: TRect);
var
  PInfo: PBitmapInfo;
  InfoSize, ImageSize: DWORD;
  PImage: Pointer;
  Bits: HBITMAP;
begin
  Printer.BeginDoc;
  try
    Bits := ABitmap.Handle;
    GetDIBSizes(Bits, InfoSize, ImageSize);
    PInfo := AllocMem(InfoSize);
    try
      PImage := AllocMem(ImageSize);
      try
        GetDIB(Bits, 0, PInfo^, PImage^);

        StretchDIBits(Printer.Canvas.Handle,
          ARect.Left, ARect.Top, ARect.Right, ARect.Bottom,
          0, 0, ABitmap.Width, ABitmap.Height,
          PImage, PInfo^, DIB_RGB_COLORS, SRCCOPY);
      finally
        FreeMem(PImage, ImageSize);
      end;
    finally
     FreeMem(PInfo, InfoSize);
    end;
  finally
    Printer.EndDoc;
  end;
end;

procedure TForm3.Button1Click(Sender: TObject);
var
  Bitmap: TBitmap;
  R: TRect;
  ScaleX, ScaleY: Integer;
begin
  Bitmap := CreateDesktopBitmap;
  try
    if Assigned(Bitmap) then
    begin
      R.Left := 0;
      ScaleX := GetDeviceCaps(Handle, logPixelsX) div PixelsPerInch;
      R.Right := Bitmap.Width * ScaleX;

      R.Top := 0;
      ScaleY := GetDeviceCaps(Handle, logPixelsY) div PixelsPerInch;
      R.Bottom := Bitmap.Height * ScaleY;

      PrintBitmap(Bitmap, R);
    end;
  finally
    FreeAndNil(Bitmap);
  end;
end;

Open in new window

0
 
LVL 24

Assisted Solution

by:jimyX
jimyX earned 83 total points
ID: 34957747
If you set bScan value to "1" you get the active window. To get the whole screen set it to "0":
keybd_event(VK_SNAPSHOT, 0, 0, 0);

Open in new window


VOID WINAPI keybd_event(
  __in  BYTE bVk,
  __in  BYTE bScan,
  __in  DWORD dwFlags,
  __in  ULONG_PTR dwExtraInfo
);

If that's not what you meant please could you explain you want.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 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