Solved

How do I trap an event  in another application?

Posted on 2001-08-01
6
224 Views
Last Modified: 2010-04-06
I would like to detect when the user executes e.g. a CTRL-C (Copy) command in another application.

When this happens I would like my Delphi application to take control and allow the user to Paste the
information into a Delphi Edit field.
0
Comment
Question by:bjornborg
6 Comments
 

Accepted Solution

by:
GoodTimes earned 100 total points
ID: 6342597
What you need to do is set a Hook (look into Win32.hlp under SetWindowsHookEx and using the WH_CBT and WH_KEYBOARD Hooks.

Omri
0
 

Expert Comment

by:GoodTimes
ID: 6342605
oops, sorry, forget the WH_CBT. Only use WH_KEYBOARD.

Omri
0
 
LVL 3

Expert Comment

by:rondi
ID: 6343648
Don't forget to put all your hookin code in a DLL
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 22

Expert Comment

by:mnasman
ID: 6345194
Hello

  do you want to hook the events or the clipboard, if you want to spy the clipboard, so if any one press ctrl+c or press copy from the menu, you will get that in ur delphi application, here's a program


unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    procedure WMDrawClipboard(var Msg: TMessage);
      message WM_DRAWCLIPBOARD;
 procedure WMChangeCBChain(var Msg: TMessage);
      message WM_CHANGECBCHAIN;

  public
  end;

var
  Form1: TForm1;
  NextInChain : THandle;

implementation

uses ClipBrd;

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
NextInChain := SetClipboardViewer(Handle);
end;

procedure TForm1.WMDrawClipboard(var Msg:TMessage);
begin
 if Clipboard.HasFormat(cf_text) then begin
  Memo1.Lines.Clear;
  Memo1.PasteFromClipboard
 end else begin
  //do something with other clipboard formats
 end;
 //pass the message on to the next window
 if NextInChain <> 0 then
  SendMessage(NextInChain, WM_DrawClipboard, 0, 0)
end;

procedure TForm1.WMChangeCBChain(var Msg: TMessage);
var
  Remove, Next: THandle;
begin
  Remove := Msg.WParam;
  Next := Msg.LParam;
 with Msg do
  if NextInChain = Remove then
   NextInChain := Next
  else if NextInChain <> 0 then
   SendMessage(NextInChain, WM_ChangeCBChain,
               Remove, Next)
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  ChangeClipboardChain(Handle, NextInChain);
end;

end.


I hope that what u need

Mohammed
0
 

Author Comment

by:bjornborg
ID: 6355994
Thank you Mohammed,
Your example works fine, but I guess I have to use the SetWindowsHookEx within a DLL as Omri suggested in order to "stop" the current application and transfer the control to the Delphi application.

After having seen the comment/answer from Omri, I have searched for more information about "SetWindowsHookEx" and have found the answer to "Global hooks" which has a detailed and long answer with example application and DLL.

Thanks
Bj?rn
0
 

Author Comment

by:bjornborg
ID: 6356044
The answer points to the routine that must be used, but does not provide solution example (and/or could have pointed to existing example in database)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

705 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

20 Experts available now in Live!

Get 1:1 Help Now