?
Solved

Convert Enhanced Metafile into RTF

Posted on 2003-03-01
8
Medium Priority
?
1,395 Views
Last Modified: 2007-12-19
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
Comment
Question by:RMatzka
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8048983
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
 

Author Comment

by:RMatzka
ID: 8049161
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
 

Expert Comment

by:SpideyMod
ID: 8053945
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
Technology Partners: 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!

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8072575
Well, could you send me an emf file to test with or where i could find one?
0
 

Author Comment

by:RMatzka
ID: 8073184
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
 

Author Comment

by:RMatzka
ID: 8073268
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
 

Author Comment

by:RMatzka
ID: 8073309
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
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 1500 total points
ID: 8073385
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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month13 days, 11 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question