Solved

auto print screen

Posted on 2011-02-22
6
245 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

724 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