Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

Screen capture

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
Cliff100699
Asked:
Cliff100699
1 Solution
 
kretzschmarCommented:
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
 
lopemCommented:
listening...
0
 
Mohammed NasmanSoftware DeveloperCommented:
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
MadmarlinCommented:
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
 
Cliff100699Author Commented:
Will these work with delphi one.
0
 
MoondancerCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now