Solved

Screen capture

Posted on 2001-08-12
6
217 Views
Last Modified: 2010-04-06
I am currently involved in software testing and wish to capture the current screen and paste into a word document.  I have this code below that is used in VB, but I now wish to be able to acheive the same with Delphi.  Any help would be greatly appreciated.

Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal _
  bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Sub CopyScreenToWord()
 Static wd As Word.Application
 Static doc As Word.Document
 
 'Start word and create a document if necessary
 If wd Is Nothing Then
   Set wd = GetObject(, "word.application")
   If wd Is Nothing Then
     Set wd = CreateObject("word.application")
   End If
   wd.Visible = True
   Set doc = Word.Documents.Add
 End If
 keybd_event &H2C, 0, 0, 0
 DoEvents
 wd.Selection.EndKey unit:=wdStory
 wd.Selection.Paste
End Sub

Sub StartUp()
 'Capture F10 key
 Application.OnKey "{F10}", "CopyScreenToWord"
End Sub

Sub CloseDown()
 'Stop capturing F10 key
 Application.OnKey "{F10}", ""
End Sub
0
Comment
Question by:Cliff100699
6 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 200 total points
ID: 6377137
something like this?

unit word_screen_capture_u;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, comObj;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormCreate(Sender: TObject);
  private
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}



procedure TForm1.Button1Click(Sender: TObject);
var
  FWord : Variant;
  FDoc  : Variant;
begin
  try
    FWord := GetActiveOleObject('word.Application');
  except
    FWord := CreateOleObject('word.Application');
  end;
  FDoc := FWord.Documents.Add;
  FWord.Visible := True;
  Keybd_Event(VK_SnapShot,0,0,0);
  FWord.Selection.EndKey;
  FWord.Selection.Paste;
end;

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  If Key = VK_F10 then
    Button1.Click;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  KeyPreview := True;
end;

end.


just experimental

meikl ;-)
0
 
LVL 3

Expert Comment

by:lopem
ID: 6377427
listening...
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6377602
Good work meikl :)

I just want to to change the line  FWord.Visible := True;
 to be the last line, like this :

 FDoc := FWord.Documents.Add;
 Keybd_Event(VK_SnapShot,0,0,0);
 FWord.Selection.EndKey;
 FWord.Selection.Paste;
 FWord.Visible := True;
end;

that's to take the snapshot before word open

also you can u add

Application.ProcessMessages;
it's the equivalent in delphi for Doevents in vb

Best regards :)
Mohammed
0
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
LVL 1

Expert Comment

by:Madmarlin
ID: 6440983
Capturing the screen is a doddle..



function CaptureScreen:TBitmap;
var
  DC : HDC;
  ABitmap:TBitmap;
begin
  DC := GetDC (GetDesktopWindow);
  ABitmap:=TBitmap.Create;
  try
    ABitmap.Width  := GetDeviceCaps (DC, HORZRES);
    ABitmap.Height := GetDeviceCaps (DC, VERTRES);
    BitBlt(ABitmap.Canvas.Handle, 0, 0, ABitmap.Width,
           ABitmap.Height,DC, 0, 0, SRCCOPY);
  finally
    ReleaseDC (GetDesktopWindow, DC);
  end;
Result:=ABitmap;
end;




Madmarlin
0
 

Author Comment

by:Cliff100699
ID: 6532144
Will these work with delphi one.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6857763
Question(s) below appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you. You must tell the participants why you wish to do this, and allow for Expert response.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question. Again, please comment to advise the other participants why you wish to do this.

For special handling needs, please post a zero point question in the link below and include the question QID/link(s) that it regards.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click the Help Desk link on the left for Member Guidelines, Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Please click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues, to track all your open and locked questions at this site.  If you are an EE Pro user, use the Power Search option to find them.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20167147.html




PLEASE DO NOT AWARD THE POINTS TO ME.  
 
------------>  EXPERTS:  Please leave any comments regarding your closing recommendations if this item remains inactive another seven (7) days.  Also, if you are interested in the cleanup effort, please click this link http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange

P.S.  For any year 2000 questions, special attention is needed to ensure the first correct response is awarded, since they are not in the comment date order, but rather in Member ID order.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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