Creating a Windows Metafile (WMF) then placing on clipboard

Creating a Windows Metafile (WMF) then placing on clipboard

Post by TPG NEW » Fri, 14 Apr 2000 04:00:00



My VB5 application allows the user to create a graphic image on the screen.
I want the application to be able to copy the graphic image and drop it into
a ms word document.

I tried just putting a bitmap of the graphic image onto the clipboard.
However the graphics contains a lot of lines and rectangles, so when it's
droped into ms word the user can't stretch the image.

The following code creates a metafile and then attempts a loadpicture.

However I get an error "Invalid picture format" . Loadpicture loads other
metafiles (not created by vb api calls) Ok.

Any idea whats wrong with the code here.

--------------------------------------------------------------
    Dim MfH As Long

    ' Create metafile using windows api
    MfH = CreateMetaFile("c:\WTEMP.WMF")
    Rectangle MfH, 100, 100, 150, 150
    CloseEnhMetaFile MfH

    ' Load the metafile
    Picture = LoadPicture("c:\WTEMP.WMF")     '  Gives error message
'invalid picture format'

    ' Place on clipboard
    Clipboard.Clear
    Clipboard.SetData Picture, vbCFMetafile
----------------------------------------------------------------

Any help would be greatly appreciated.

 
 
 

Creating a Windows Metafile (WMF) then placing on clipboard

Post by alpi » Fri, 14 Apr 2000 04:00:00


Quote:>My VB5 application allows the user to create a graphic image on the screen.
>I want the application to be able to copy the graphic image and drop it into
>a ms word document.

>I tried just putting a bitmap of the graphic image onto the clipboard.
>However the graphics contains a lot of lines and rectangles, so when it's
>droped into ms word the user can't stretch the image.

>The following code creates a metafile and then attempts a loadpicture.

>However I get an error "Invalid picture format" . Loadpicture loads other
>metafiles (not created by vb api calls) Ok.

>Any idea whats wrong with the code here.

>--------------------------------------------------------------
>    Dim MfH As Long

>    ' Create metafile using windows api
>    MfH = CreateMetaFile("c:\WTEMP.WMF")
>    Rectangle MfH, 100, 100, 150, 150
>    CloseEnhMetaFile MfH

>    ' Load the metafile
>    Picture = LoadPicture("c:\WTEMP.WMF")     '  Gives error message
>'invalid picture format'

>    ' Place on clipboard
>    Clipboard.Clear
>    Clipboard.SetData Picture, vbCFMetafile
>----------------------------------------------------------------

>Any help would be greatly appreciated.

If I'm not mistaken, I think you should be using the Crea*hMetaFile API
function instead of the CreateMetaFile API function.

HTH,
Bryan

_________________________________________________________
New Vision Software             "When the going gets weird,"
Bryan Stafford                            "the weird turn pro."

MS MVP Visual Basic                   Fear and Loathing in LasVegas

 
 
 

Creating a Windows Metafile (WMF) then placing on clipboard

Post by Klas Nygre » Thu, 04 May 2000 04:00:00


Hi,

There are two different Windows metafile formats. Search for 'metafile' in
the MS Knowleadgebase for more info....

Klas


Quote:

> My VB5 application allows the user to create a graphic image on the
screen.
> I want the application to be able to copy the graphic image and drop it
into
> a ms word document.

> I tried just putting a bitmap of the graphic image onto the clipboard.
> However the graphics contains a lot of lines and rectangles, so when it's
> droped into ms word the user can't stretch the image.

> The following code creates a metafile and then attempts a loadpicture.

> However I get an error "Invalid picture format" . Loadpicture loads other
> metafiles (not created by vb api calls) Ok.

> Any idea whats wrong with the code here.

> --------------------------------------------------------------
>     Dim MfH As Long

>     ' Create metafile using windows api
>     MfH = CreateMetaFile("c:\WTEMP.WMF")
>     Rectangle MfH, 100, 100, 150, 150
>     CloseEnhMetaFile MfH

>     ' Load the metafile
>     Picture = LoadPicture("c:\WTEMP.WMF")     '  Gives error message
> 'invalid picture format'

>     ' Place on clipboard
>     Clipboard.Clear
>     Clipboard.SetData Picture, vbCFMetafile
> ----------------------------------------------------------------

> Any help would be greatly appreciated.

 
 
 

1. creating an enhanced metafile and copying to the clipboard

I am using NT 4.0 with Visual C++.  I am trying to copy an OpenGL image into
the clipboard through the use of an enhanced metafile.  I can create a DC
for the enhanced metafile, set the pixel format for it, and create rendering
context from this, but the clipboard image always comes up blank.  I've
provided a snippet of my code below which has gone through numerous
permutations.  According to the MS documentation, NT 4.0 is supposed to
support this type of drawing without going into the DIB file type.  What am
I doing wrong?

 ---- start of code ----

 int nPixelFormat;     // Pixel format index

 static PIXELFORMATDESCRIPTOR pfd = {
  sizeof(PIXELFORMATDESCRIPTOR), // Size of this structure
  1,        // Version of this structure
  PFD_DRAW_TO_WINDOW |   // Draw to Window (not to bitmap)
  PFD_SUPPORT_OPENGL |   // Support OpenGL calls in window
  PFD_TYPE_RGBA,     // RGBA Color mode
  24,        // Want 24bit color
  0,0,0,0,0,0,     // Not used to select mode
  0,0,       // Not used to select mode
  0,0,0,0,0,      // Not used to select mode
  32,        // Size of depth buffer
  0,        // Not used to select mode
  0,        // Not used to select mode
  PFD_MAIN_PLANE,     // Draw in main plane
  0,        // Not used to select mode
  0,0,0 };      // Not used to select mode

  HDC hdc_emf;    // device context for enhanced metafile
  HENHMETAFILE h_emf;    // handle to enhanced metafile
  HGLRC h_rc;    // rendering context

// m_hDC is the DC for the main viewing window
  hdc_emf = CreateEnhMetaFile(m_hDC, NULL, &wrect, NULL);    // create the
enhanced metafile in memory
  assert(hdc_emf != NULL);

  // Choose a pixel format that best matches that described in pfd
  nPixelFormat = ChoosePixelFormat(hdc_emf, &pfd);

  // Set the pixel format for the device context
  VERIFY(SetPixelFormat(hdc_emf, nPixelFormat, &pfd));

  // Create the rendering context
  h_rc = wglCreateContext(hdc_emf);

  // Make the rendering context current
  VERIFY(wglMakeCurrent(hdc_emf, h_rc));

  RenderOpenGLScene();

  h_emf = CloseEnhMetaFile(hdc_emf);
  assert(h_emf != NULL);

  if(::SetClipboardData(CF_ENHMETAFILE, h_emf) == NULL)
  {
   AfxMessageBox("Unable to set Clipboard data");
  }

  wglDeleteContext(h_rc);

  CloseClipboard();
  DeleteEnhMetaFile(h_emf);
  wglMakeCurrent(m_hDC, NULL);

2. Detecting almost duplicate images

3. Windows Metafile & Clipboard

4. dont make any deals with Yrartsch he is LAER

5. How to create metafiles (wmf, emf) ?

6. req: character studio 1.15 or 2....

7. Help on creating Metafiles/WMF ?

8. Windows Metafile Format (wmf) Graphics

9. Windows Metafiles (WMF) to EPS?

10. Windows Metafiles (.WMF)

11. Windows Metafile (.wmf) to PICT format?

12. Windows Metafile Format (wmf) Graphics