Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

auto print screen

Posted on 2011-02-22
6
Medium Priority
?
256 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 336 total points
ID: 34955732
0
 
LVL 19

Assisted Solution

by:Thommy
Thommy earned 1000 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 1000 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 1000 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 332 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 332 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

636 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