Article View: borland.public.cppbuilder.nativeapi
Article #14548Working With Clipboard !!
From: DRE
Date: Mon, 11 Aug 2003 11:55
Date: Mon, 11 Aug 2003 11:55
74 lines
3038 bytes
3038 bytes
Good Day,
I need to get the text in clipboard everytime it is changed by any
application, I found an old thread which was about setting my window as a
ClipboardViewer and receive the messges that will inform my app. with the
new values add to the clipboard
the code that was fixed by Gambit and which I tried to use was like the
following
===============================================================
Unit1.h file
-----------
private: // User declarations
HWND HwNd;
public: // User declarations
MESSAGE void __fastcall ChangeChain(TMessage &);
MESSAGE void __fastcall MyNotify(TMessage &);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_CHANGECBCHAIN,TMessage,ChangeChain)
MESSAGE_HANDLER(WM_DRAWCLIPBOARD,TMessage,MyNotify)
END_MESSAGE_MAP(TForm)
...
Unit1.cpp file
---------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
HwNd = SetClipboardViewer(Application->Handle);
}
file://-------------------------------------------------------------
void __fastcall TForm1::ChangeChain(TMessage& Msg)
{
if((HWND)Msg.WParam == HwNd)
HwNd = (HWND)Msg.LParam;
PostMessage(HwNd, WM_CHANGECBCHAIN, (WPARAM)Msg.WParam,
(LPARAM)Msg.LParam);
}
file://---------------------------------------------------------------------
------
void __fastcall TForm1::MyNotify(TMessage& Msg)
{
// you only want to add text if there is actually text available
if(IsClipboardFormatAvailable(CF_TEXT))
{
if(OpenClipboard(Handle))
{
HANDLE cbh = GetClipboardData(CF_TEXT);
if(cbh != NULL)
{
AnsiString text = AnsiString((char*)GlobalLock(cbh));
GlobalUnlock(cbh);
Memo1->Text = text;
}
}
CloseClipboard();
}
}
file://---------------------------------------------------------------------
------
===============================================================
the problem is that when I run the application it does nothing after I
execute the SetClipboardViewer(). Do I need to call something or do I need
to add anything else
I just don't know what is wrong with this ?
Thanks in advance
Technical Details
Message-ID:
<3f378281@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-05!sn-xit-09!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,2a65053854a29683,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-08-11 04:52:02 PST From: "DRE" <dre00x@yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Working With Clipboard !! Date: Mon, 11 Aug 2003 14:55:02 +0300 Lines: 76 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2919.6600 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 NNTP-Posting-Host: 62.135.27.10 Message-ID: <3f378281@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1060602497 62.135.27.10 (11 Aug 2003 04:48:17 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-05!sn-xit-09!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail