Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem with Clipboard and Unicode

171 views
Skip to first unread message

Alexander Kamburov

unread,
Feb 19, 2003, 2:46:47 AM2/19/03
to
Hi there :-)
I have a problem with the Clipboard and especially with defining if I should
get the data under CF_TEXT or CF_UNICODETEXT. When you copy some text to the
Clipboard Windows provides it to you in the two formats because they are
"Synthesized Clipboard Formats". I don't know which was the original format
copied to the Clipboard and I can't get the text as it was in the source
control.

My question is, do functions like EnumClipboardFormats or
GetPriorityClipboardFormat give me in first place exactly the format in
which the text originated?

--
Regards,
Alexander Kamburov

wise_...@yahoo.com


Mihai N.

unread,
Feb 19, 2003, 3:58:07 AM2/19/03
to
> My question is, do functions like EnumClipboardFormats or
> GetPriorityClipboardFormat give me in first place exactly the format
> in which the text originated?

Short: No.

Long: ther is no direct link between the the clipboard format and the
"original format." In many cases the original format is proprietary and you
will have no way to understand it.
When I copy some text from Corel Draw I get the following formats:
1 Object Descriptor CF_TEXT
2 Ole Private Data CF_BITMAP
3 Corel 32-bit Presentation Exchange Data CF_METAFILEPICT
7 Ole Private Data CF_OEMTEXT
8 Corel 32-bit Presentation Exchange Data CF_DIB
13 Ole Private Data CF_UNICODETEXT
14 Corel 32-bit Presentation Exchange Data CF_ENHMETAFILE
16 Ole Private Data CF_LOCALE
17 Ole Private Data CF_MAX
49161 DataObject <UNKNOWN>
49163 Embed Source <UNKNOWN>
49156 Native <UNKNOWN>
49155 OwnerLink <UNKNOWN>
49166 Object Descriptor <UNKNOWN>
49687 Corel 32-bit Presentation Exchange Data <UNKNOWN>
49689 Corel Presentation Exchange Data <UNKNOWN>
49171 Ole Private Data <UNKNOWN>
I assume the "original format" is 49156 (Native). But this is not a rule.
And since I don't know the native Corel format, this is useless.

To increase compatibility the applictions try to put into the clipboard as
many formats as possible.
Just take the one with max. information that you can still understand (in
your case is probable CF_UNICODETEXT). If you can can use RTF, then you
also get font information etc.

Mihai

Alexander Kamburov

unread,
Feb 19, 2003, 5:59:12 AM2/19/03
to
> Just take the one with max. information that you can still understand (in
> your case is probable CF_UNICODETEXT). If you can can use RTF, then you
> also get font information etc.

When I copy an AnsiString to clipboard the CF_UNICODETEXT returns it as
WideString. I mean it doesn't convert it but passes it as if it is Unicode.
Doing so the WideString is half the length of the original and of course it
is totally not what I want.

When I copy a WideString to clipboard the CF_TEXT returns a normal string
and in the place of spec chars I get question marks. I made my program check
if there are any question marks in the AnsiString and if found to use
CF_UNICODETEXT. This is the only solution I was able to come out with and as
you can see it's not the most robust.

Reading my current posting again I see that there is a possiblility that I
have a bug in my function that takes the text under CF_UNICODETEXT but I
don't have acces to my source code at this moment.

--
Regards,
Alexander Kamburov

wise_...@yahoo.com
"Mihai N." <nmiha...@yahoo.com> wrote in message
news:Xns93279DA...@63.240.76.16...

Alexander Kamburov

unread,
Feb 19, 2003, 6:06:12 AM2/19/03
to
Oh and one more thing...
Getting the clipboard formats using EnumClipboardFormats returns a different
sequence of formats i.e. when I copy text the first format is CF_TEXT and
when I copy Unicode the first format is CF_UNICODETEXT. This is why I asked
if I could rely on this priority list...

--
Regards,
Alexander Kamburov


Michael (michka) Kaplan [MS]

unread,
Feb 19, 2003, 6:41:38 AM2/19/03
to
You cannot. You should ask for whatever format you need.


--
MichKa [MS]

This posting is provided "AS IS" with
no warranties, and confers no rights.


"Alexander Kamburov" <wise_...@yahoo.com> wrote in message
news:e3ZFebA2CHA.1560@TK2MSFTNGP09...

Alexander Kamburov

unread,
Feb 24, 2003, 2:03:38 AM2/24/03
to
I have made my form a Clipboard Viewer so I could monitor the copied text. I
really need to know if the text was originally in Unicode or Ansi.

> You cannot. You should ask for whatever format you need.

Well then how come the first format returned by EnumClipboardFormats is
changing according to the text encoding. I tryed it under XP. When I copy
Ansi the main format is CF_TEXT when I copy Unicode the EnumClipboardFormats
returns CF_UNICODETEXT in first place. It's true that the MSDN doesn't tell
you nothing about this functionality but may be the code used for this
operations does this by himself.

Quote from help on EnumClipboardFormats: "When format is zero, the function
retrieves the first available clipboard format". May be this is why the
first format when copying text is the right one. Anyway, if this isn't so
and I'm mistaking the I think this is some type of bug in the Clipboard
functions.

--
Regards,
Alexander Kamburov

wise_...@yahoo.com
"Michael (michka) Kaplan [MS]" <mic...@online.microsoft.com> wrote in
message news:u#4FjvA2C...@TK2MSFTNGP11.phx.gbl...

Michael (michka) Kaplan [MS]

unread,
Feb 24, 2003, 8:05:26 AM2/24/03
to
The function is not guaranteed to be deterministic about its ordering
and is certainly not documented as working the way you want it to for
all versions (or for all future versions).


--
MichKa [MS]

This posting is provided "AS IS" with
no warranties, and confers no rights.


"Alexander Kamburov" <wise_...@yahoo.com> wrote in message

news:OqpeeL92...@TK2MSFTNGP11.phx.gbl...

Michael Lippert

unread,
Jun 2, 2003, 7:47:06 PM6/2/03
to
Hmm, the docs imply otherwise:

Synthesized Clipboard Formats

The system implicitly converts data between certain clipboard formats: if
a window requests data in a format that is not on the clipboard, the
system converts an available format to the requested format. The system
can convert data as indicated in the following table.

...

If the system provides an automatic type conversion for a particular
clipboard format, and you call EnumClipboardFormats to enumerate the
clipboard data formats, the system first enumerates the format that is on
the clipboard, followed by the formats to which it can be converted.

from http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/winui/winui/windowsuserinterface/dataexchange/clipboard/clipboardforma
ts.asp

Mike

My guess is that if unicode text is put on the clipboard, the conversion
uses the system code page to convert it to CF_TEXT and I think it puts
?'s in for unicode characters that can't be represented by that code
page. There isn't much else it could do.

I am surprised that there is ever a problem getting the CF_UNICODETEXT
though, but that's based just on how I think this should work, not any
experience with it.

"Michael \(michka\) Kaplan [MS]" <mic...@online.microsoft.com> wrote in
news:et8inVA3...@TK2MSFTNGP10.phx.gbl:

> The function is not guaranteed to be deterministic about its ordering
> and is certainly not documented as working the way you want it to for
> all versions (or for all future versions).
>
>

Michael (michka) Kaplan [MS]

unread,
Jun 2, 2003, 11:23:58 PM6/2/03
to
If you want to assume this it will not kill anyone. I think you will find it
may not always be true (regardless of the docs, which do not promise to be
speaking about all versions), but since it really does not matter its hard
to really advise....:-)


--
MichKa [MS]

This posting is provided "AS IS" with
no warranties, and confers no rights.


"Michael Lippert" <mlipp...@yahoo.com> wrote in message
news:Xns938EC943CA7F0An...@207.46.248.16...

0 new messages