Solved

Clipboard Scan / Callback

Posted on 2003-11-26
1
242 Views
Last Modified: 2010-04-05
I'm working on program that, in general, parses text. The text that should be parsed is coming from some webpages. To get the text, the user has to select-all and copy the text of the webpage. So the text to be parsed is copied to the clipboard.
If a text with a certain pattern is copied to the clipboard, the program should/will recognize this and will popup to show the formatted text.

my question is now, how can i scan the clipboard? Are there callback functions I can use to react on a copy operation, or do i have to let the program look through the clipboard periodically i.e. every 10th second ?
0
Comment
Question by:SiNeR
1 Comment
 
LVL 34

Accepted Solution

by:
Slick812 earned 250 total points
ID: 9828306
hello SiNeR, The windows system has a deal called a clipboard viewer, where a program can make it's self a clipboard viewe,r so the system will send it a message, whenever the content of the clipboard changes, the system sends a WM_DRAWCLIPBOARD message to your window, so you will know the clipboard is new. You will also need to monitor the WM_CHANGECBCHAIN message, because a clipboard viewer is in a chain, so you will need to pass the message of this "Chain" changing to the next window in the chain. . .

here is some code to get your program to be a clipboard viewer


  private
    { Private declarations }
    NextHwnd: Integer;
    procedure DrawClip(var mess: TMessage); message WM_DRAWCLIPBOARD;
    procedure ChangeViewer(var Msg: TMessage); message WM_CHANGECBCHAIN;


implementation

{$R *.DFM}

procedure TForm1.DrawClip(var mess: TMessage);
begin
// whenever the clipboard contents change, you get this message
// you Must send this message to the next window in the viewer chain
if NextHwnd <> 0 then
Sendmessage(NextHwnd, mess.Msg, mess.WParam, mess.LParam);
// I just have a Memo here to get clipboard text, but you will need to
//do whatever code you need to test or get the Clipboard contents
Memo1.Text := Clipboard.AsText;
end;

procedure TForm1.ChangeViewer(var Msg: TMessage);
begin
// you Must send this message to the next window in the viewer chain
if Msg.WParam = NextHwnd then
NextHwnd := Msg.LParam else
if NextHwnd <> 0 then
SendMessage(NextHwnd, Msg.Msg, Msg.wParam, Msg.lParam);
end;

//the next procedure is a button Click, which sets up your Form1.Handle as a clipboard viewer

procedure TForm1.button_ClipViewerClick(Sender: TObject);
begin
Clipboard.SetTextBuf('Clip Viewer Text');
NextHwnd := SetClipboardViewer(Handle);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
// be sure to remove your window from the chain as Soon as you do not need to be a clipboard viewer
ChangeClipboardChain(Handle,NextHwnd);
end;


 - - - - - - - - - - - - - - - - - - - - - - - - - - - -
I hope this helps,
ask questions if you need more information
0

Featured Post

Technology Partners: 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

Title # Comments Views Activity
Printing problem 2 110
Delphi IDE crash without error message ... 7 113
Dev Express grid collapse 2 47
how to send memory stream from ics Client To ics server ? 11 173
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…

685 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