?
Solved

Clipboard Scan / Callback

Posted on 2003-11-26
1
Medium Priority
?
248 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
[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
1 Comment
 
LVL 34

Accepted Solution

by:
Slick812 earned 1000 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

718 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