Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Screen capture

Posted on 2001-08-12
6
Medium Priority
?
226 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 400 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
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!

 
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

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

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…
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…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

886 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