Article View: borland.public.cppbuilder.nativeapi
Article #1950Re: Clipbored and Unicode
From: Jos�
Date: Mon, 14 May 2007 15:58
Date: Mon, 14 May 2007 15:58
53 lines
2958 bytes
2958 bytes
On Sun, 13 May 2007 18:04:22 -0700, Bob Gonder
<notbg@notmindspring.invalid> wrote in
borland.public.cppbuilder.nativeapi:
>> TClipboard *cb=Clipboard();
>> cb->Open();
>> int TextHandle = cb->GetAsHandle(CF_TEXT);
>
>You want CF_UNICODETEXT for unicode text.
>Since that is not a listed format for TClipboard, you might want to
>write your own clipboard functions with the WinApi. It's not hard.
CF_UNICODETEXT is not in the help file, so how was I to know? It is
accepted though, and it works with wchar_t. However, there are more
than a million Unicode characters, which means that wchar_t, which is
only 16 bits, is insufficient. However, I guess that it will seldon
happen that I need more than 16 bits.
>You might try this from thr help:
>void __fastcall TMainForm::EditPasteClick(TObject* Sender)
>{ RichEdit1->PasteFromClipboard();
>}
That won't do. RichEdit does not accept Unicode. That was where the
problem started: I used to enter data in my program by type ^V in a
TMemo, or a TRichEdit. That was satisfactory as long as there were no
Uni characters in the clipboard.
>>To write into the clipboard, I found that SetAsHandle (the obvious
>>opposite of GetAsHandle) is unusable. It takes an int as second
>>parameter, and I want to store a lot more.
>
>It takes a Handle. That is, the same kind of thing you got above:
> HGLOBAL h = GlobalAlloc( size, flags );
> char * data = GlobalLock( h );
> lstrcpy( data, "This goes to the clipboard" );
> GlobalUnlock( h );
> SetAsHandle( CF_TEXT, h );
> // -Do-not- GlobalFree because clipboard owns it.
>(You are going to be doing the same thing if you use the WinApi.)
Some changes are obviously needed:
1. char must be wchar_t of course. Or even something with 32 bits
2. I swapped the parameters of GlobalAlloc.
3. I found that HGLOBAL equals void* (I hate those enigmatic type
names).
4. The 2nd parameter of SetAsHandle must be an int, so your example
doesn't work. I can write (int)h, but this write unexpected stuff to
the clipboard.
So I can read the clipboard now, but I cannot write yet.
--
Jos�
Technical Details
Message-ID:
<va0h43tjrindd9a4jt1p4c10kkl5mi2bgg@4ax.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<qdde43trid2dep05rjl9pu2k2ohufnguf1@4ax.com> <nqaf43pcont3pe8bdgburrnitj9jiinr68@4ax.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,eee29c0be9200ce9 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII From: Jos� <jose@127.0.0.1> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Clipbored and Unicode Date: Mon, 14 May 2007 17:58:15 +0200 Message-ID: <va0h43tjrindd9a4jt1p4c10kkl5mi2bgg@4ax.com> References: <qdde43trid2dep05rjl9pu2k2ohufnguf1@4ax.com> <nqaf43pcont3pe8bdgburrnitj9jiinr68@4ax.com> X-Newsreader: Forte Agent 4.2/32.1117 MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit NNTP-Posting-Host: 82.75.32.109 X-Trace: newsgroups.borland.com 1179158298 82.75.32.109 (14 May 2007 08:58:18 -0700) Lines: 53 Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail