Solved

auto print screen

Posted on 2011-02-22
6
231 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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:ewangoya
ewangoya 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

914 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

23 Experts available now in Live!

Get 1:1 Help Now