Solved

How do I trap an event  in another application?

Posted on 2001-08-01
6
232 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
[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
 

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
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 22

Expert Comment

by:Mohammed Nasman
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

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

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 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