Solved

Clipboard Scan / Callback

Posted on 2003-11-26
1
236 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 33

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

12 Experts available now in Live!

Get 1:1 Help Now