Solved

Clipboard Scan / Callback

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

Industry Leaders: 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…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

728 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