473,407 Members | 2,315 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Getting CF_ENHMETAFILE from clipboard


Hi all!

Did anyone try the subj?

I use extern IsClipboardFormatAvailable and GetClipboardData from
user32.dll. IsClipboardFormatAvailable(14) returns true, but
GetClipboardData(14) returns null-pointer after that.

I found working source codes that can get CF_ENHMETAFILE from clipboard,
but they are C++ WinAPI applications. Maybe there's some ruse, but I can't
see the difference in method using.

Thank you in advance for any advices.

Best regards,
A. Dzizenko
May 31 '06 #1
11 6911
Andrey,

Why not just use the GetData method on the IDataObject implementation
passed to you? You can pass DataFormats.EnhancedMetafile to get what you
want.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Andrey Dzizenko" <A.********@logicexplorers.com> wrote in message
news:op***************@dzizenko.lei.com...

Hi all!

Did anyone try the subj?

I use extern IsClipboardFormatAvailable and GetClipboardData from
user32.dll. IsClipboardFormatAvailable(14) returns true, but
GetClipboardData(14) returns null-pointer after that.

I found working source codes that can get CF_ENHMETAFILE from clipboard,
but they are C++ WinAPI applications. Maybe there's some ruse, but I can't
see the difference in method using.

Thank you in advance for any advices.

Best regards,
A. Dzizenko
May 31 '06 #2
In c# you may use P-Invoke, with the following calls:
1) OpenClipboard
2) IsClipboardFormatAvailable(CF_ENHMETAFILE)
3) If true, then use GetClipboardData(CF_ENHMETAFILE) to get an IntPtr to
the EnhancedMetafile handle
4) Use CopyEnhMetaFile to make a copy for your use as the clipboard retains
ownership of the handle.
5) CloseClipboard

Make sure you use the correct P-Invoke signatures. Copy them from
http://www.pinvoke.net

"Andrey Dzizenko" <A.********@logicexplorers.com> wrote in message
news:op***************@dzizenko.lei.com...

Hi all!

Did anyone try the subj?

I use extern IsClipboardFormatAvailable and GetClipboardData from
user32.dll. IsClipboardFormatAvailable(14) returns true, but
GetClipboardData(14) returns null-pointer after that.

I found working source codes that can get CF_ENHMETAFILE from clipboard,
but they are C++ WinAPI applications. Maybe there's some ruse, but I can't
see the difference in method using.

Thank you in advance for any advices.

Best regards,
A. Dzizenko
May 31 '06 #3
Oh... Sorry, I forgot to mention that...

Clipboard.ContainsData(DataFormats.EnhancedMetafil e) returns false. And
all other formats too.
..NET Clipboard can't see the data (it's MSWord's picture). Explained at
http://support.microsoft.com/?id=323530

Best regards,
A. Dzizenko.
Jun 1 '06 #4
If you enumerate all clipboard formats in c# using the GetFormats methods,
you will see that the clipboard contains the "EnhancedMetafile" custom
clipboard format which cannot be retrieved. However the canonical
CF_ENHMETAFILE clipboard format can be retrieved using the calls in my post
provided that GetFormats presents the "EnhancedMetafile" format as an
available clipboard format.

If you use GetFormats, you will see that Office also places the
"MetaFilePict" custom .Net format on the clipboard. You may retrieve this
clipboard format using the same p-invoke code with CF_METAFILEPICT
substituted for CF_ENHMETAFILE.

The clipboard will synthesize the missing format for you if the application
places only one of them on the clipboard(i.e., "EnhancedMetafile",
"MetafilePict").
"Andrey Dzizenko" <A.********@logicexplorers.com> wrote in message
news:op***************@dzizenko.lei.com...
Oh... Sorry, I forgot to mention that...

Clipboard.ContainsData(DataFormats.EnhancedMetafil e) returns false. And
all other formats too.
..NET Clipboard can't see the data (it's MSWord's picture). Explained at
http://support.microsoft.com/?id=323530

Best regards,
A. Dzizenko.
Jun 1 '06 #5
If I understand you correctly...

<<Immediate window>>
selection.CopyAsPicture()
Expression has been evaluated and has no value
Clipboard.ContainsData(DataFormats.EnhancedMetafil e)
false

Best regards,
A. Dzizenko
Jun 1 '06 #6
To be clear, "EnhancedMetafile" is a custom clipboard format that the .Net
clr registered with the function RegisterClipboardFormat.

It contains no data because Office does not know how to present the custom
clipboard format.

However, the clipboard knows how to synthesize the 17 canonical clipboard
formats. If you ask for CF_ENHMETAFILE and the clipboard is able to make
this format available to you, then you can retrieve it.

"Andrey Dzizenko" <A.********@logicexplorers.com> wrote in message
news:op***************@dzizenko.lei.com...
If I understand you correctly...

<<Immediate window>>
selection.CopyAsPicture()
Expression has been evaluated and has no value
Clipboard.ContainsData(DataFormats.EnhancedMetafil e)
false

Best regards,
A. Dzizenko

Jun 1 '06 #7
It contains no data because Office does not know how to present the
custom
clipboard format.


But it contains data. As I said the method
IsClipboardFormatAvailable(CF_ENHMETAFILE) of the user32.dll library
returns true. So Office knows how to present the format.
http://www.codeguru.com/cpp/w-p/clip...cle.php/c9155/
There's source code of the clipboard viewer that can view CF_ENHMETAFILE
copied by Office. With no intricate movements.

It's possible. We don't know how - that's the question.
Jun 1 '06 #8
I wrote my own clipboard viewer in c# to experiment with all the new .Net
custom clipboard formats as well as all of the canonical clipboard formats.

I retrieve CF_ENHMETAFILE using the method that I posted. I tested my
clipboard viewer with Office. It works!

"Andrey Dzizenko" <A.********@logicexplorers.com> wrote in message
news:op***************@dzizenko.lei.com...
It contains no data because Office does not know how to present the
custom
clipboard format.


But it contains data. As I said the method
IsClipboardFormatAvailable(CF_ENHMETAFILE) of the user32.dll library
returns true. So Office knows how to present the format.
http://www.codeguru.com/cpp/w-p/clip...cle.php/c9155/
There's source code of the clipboard viewer that can view CF_ENHMETAFILE
copied by Office. With no intricate movements.

It's possible. We don't know how - that's the question.
Jun 1 '06 #9
If not inconvenient to you would you please send your code to
A.********@LogicExplorers.com
Maybe I'm just stupid a little :)
Jun 2 '06 #10
For the benefit of others, here is a code snippet:

// Must use a windows handle...I used the form's window handle
if ( true == OpenClipboard(this.Handle) )
{
if ( true ==
IsClipboardFormatAvailable((uint)CLIPFORMAT.CF_ENH METAFILE) )
{
IntPtr hEmfClp = GetClipboardData((uint)CLIPFORMAT.CF_ENHMETAFILE);

if ( IntPtr.Zero != hEmfClp )
{
// Must make a copy. Clipboard retains ownership of the
original handle
IntPtr hEmfCopy = CopyEnhMetaFile(hEmfClp, null);

if ( IntPtr.Zero != hEmfCopy )
{
Metafile metafile = new Metafile(hEmfCopy, true);

// do something with this metafile
...

}
}
}

CloseClipboard();
}
"Andrey Dzizenko" <A.********@logicexplorers.com> wrote in message
news:op***************@dzizenko.lei.com...
If not inconvenient to you would you please send your code to
A.********@LogicExplorers.com
Maybe I'm just stupid a little :)

Jun 2 '06 #11
I understood.

In my project there's a class, which works in another thread. Don't know
why but the Clipboard is unavailable in this thread.
I found an information that the thread must be STA for using clipboard. My
application is STA and I don't know what to do any more.

I wrote the delegate method which gets clipboard from the main thread.
This scheme works.

Best regards,
A. Dzizenko.
Jun 9 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: xyz | last post by:
I have a menu item to handle clipboard actions (cut, copy, paste). When I paste text that I copied from a Hungarian web page, the display looks normal on my RichTextBox, but the text retrieved from...
8
by: LG | last post by:
Just have a question with regards to the clipboard, and how to read what other applications (Adobe InDesignCS) place in the clipboard. I am currently in the process of creating a booklet from a...
6
by: Roohi | last post by:
hi I am trying to copy an image to a clipboard and then get a handle to the clipboard using API calls GetClipboardData(). Following is the snippet of our code. Could any one please point out...
3
by: | last post by:
I wrote a class in VB.NET to export the contents of a datagrid to Excel. It works perfectly on my machine, but it fails on my customers' PCs that have identical versions of Win XP (SP1) and Excel...
7
by: Newbie | last post by:
How do I clear the clipboard in VB.NET 2003? TIA Newbie
1
by: Figmo | last post by:
Wow.....this is darned odd.... I have an app that integrates with other applications. It registers a global hotkey with Windows. When the hotkey executes it sends a CTRL-C to the active...
8
by: active | last post by:
Guess I'm looking for someone who likes to work difficult puzzles. I can't seem to ever retrieve a palette handle from the clipboard. Below is a simple test program that demonstrates the...
13
by: Neil | last post by:
Can I get the name of a procedure from within the procedure? In my error handler, I write the error to an error table. I'd like to write the name of the procedure that's writing the error. But,...
20
by: Joe Duchtel | last post by:
Hello - I have the following code to get a bitmap from the clipboard and to save it to a *.png file ... Dim lData As IDataObject = Clipboard.GetDataObject() If...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.