Solved

Clipboard Scan / Callback

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month10 days, 19 hours left to enroll

628 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