Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1445
  • Last Modified:

Convert Enhanced Metafile into RTF

Given a Windows handle to an Enhanced Metafile, how can I convert it into RTF code which displays this metafile, e.g. when it is handed over to the TextRTF property of a Rich Text Box control, or copied to Clipboard and pasted into Word? The RTF (V1.5) specification tells me to use the \pict and \emfblip control words, and to supply the picture data in hexadecimal format. The spec does not tell me how to get those picture data. For Bitmaps, the spec suggests to use the GDI "GetBitmapBits" function. By analogy, I thought I might use the GDI "GetEnhMetafileBits" function for an Enhanced Metafile. But it does not work. This is my RTF code:

{\rtf1\ansi\ansicpg1252\deff0\deflang1031
{\pict\emfblip\picw3620\pich2718\picwgoal2052\pichgoal1541
data as hexadecimal string
}
\par }

The Rich Text Box control can be made to paste Enhanced Metafiles (by pressing Ctl-v at runtime), so by inspecting its TextRTF property it is possible to see what code it creates. Unexpectedly, it uses the \wmetafile8 keyword instead of \emfblip, and it produces hexadecimal data which include the result of GetEnhMetafileBits (converted to hexadecimal string), but has additional bytes before and after those. I'm puzzled.

Can anybody help?
0
RMatzka
Asked:
RMatzka
  • 4
  • 3
1 Solution
 
Richie_SimonettiIT OperationsCommented:
I don't understand, you already have proposed a possible solution. Paste the contents of clipboard to a RichtextBox control and save to a rtf file.
0
 
RMatzkaAuthor Commented:
Yes, that's a workaround for my problem, but one with an unwanted side effect, since it affords to clear the clipboard, and the user of my app may well want to keep the clipboard contents for other purposes. Another workaround I thought of was to programmatically simulate OLE-Drag-And-Drop, but funny enough, the Rich Text Box control accepts EMF from the Clipboard, but not through OLE-Drag-And-Drop.
I need a clean solution, without side effects, and I can't think of anything else but directly create the necessary RTF code.
0
 
SpideyModCommented:
Note:
Points increased to 500 to replace the points from the other questions and fix the re-route problem to this question.

SpideyMod
Community Support Moderator @Experts Exchange
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Richie_SimonettiIT OperationsCommented:
Well, could you send me an emf file to test with or where i could find one?
0
 
RMatzkaAuthor Commented:
Having done some research, I understand the problem a bit better now. The documentation of the Rich Text Box control that comes with VB6 does not list the /emfblip control word among the supported control words, but does list /wmetafile. I.e., this control can embed Windows Metafiles (.wmf), but not Enhanced Metafiles (.emf). I have observed that whenever an EMF picture is copied to the clipboard, the clipboard offers both EMF and WMF format, when asked for available formats. So when I try to copy an EMF and paste it to the Rich Text control, what the latter does is use the WMF offered by the clipboard, and not my original EMF. And, if I try to use the /emfblip control word directly and feed it to the Rich Text Control, it simply won't recognize this control word.
In my case, the WMF format will not do, I need some of the EMF features. So, the issue for me boils down to these questions:
1. how to create valid RTF code containing a given EMF picture, so that it can be pasted e.g. into Word (I didn't manage that so far, having no more information than what's in the RTF 1.5 specification)
2. to find a better Rich Text control which does support EMF embedding.
0
 
RMatzkaAuthor Commented:
Having done some research, I understand the problem a bit better now. The documentation of the Rich Text Box control that comes with VB6 does not list the /emfblip control word among the supported control words, but does list /wmetafile. I.e., this control can embed Windows Metafiles (.wmf), but not Enhanced Metafiles (.emf). I have observed that whenever an EMF picture is copied to the clipboard, the clipboard offers both EMF and WMF format, when asked for available formats. So when I try to copy an EMF and paste it to the Rich Text control, what the latter does is use the WMF offered by the clipboard, and not my original EMF. And, if I try to use the /emfblip control word directly and feed it to the Rich Text Control, it simply won't recognize this control word.
In my case, the WMF format will not do, I need some of the EMF features. So, the issue for me boils down to these questions:
1. how to create valid RTF code containing a given EMF picture, so that it can be pasted e.g. into Word (I didn't manage that so far, having no more information than what's in the RTF 1.5 specification)
2. to find a better Rich Text control which does support EMF embedding.
0
 
RMatzkaAuthor Commented:
To be more specific, what I need is the Metafile description which can be set with CreateEnhMetaFile and be retrieved with GetEnhMetaFileDescription. I need this information to be preserved throughout the process of copying the EMF from my app to the clipboard, the user pasting it into her Word textstream, later the user copying it back from the Word textstream to the Clipboard, and my app getting it from the Clipboard.
0
 
Richie_SimonettiIT OperationsCommented:
A better RTB control:
http://www.vbaccelerator.com/codelib/richedit/richedit.htm
see the features at bottom of that page.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now