Go Premium for a chance to win a PS4. Enter to Win

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

WMF picture from clipboard in Access 97?

Hi, all.  I need to retrieve a picture from the clipboard using Access 97.  The application that puts it there actually puts it in three formats at the same time: BMP, windows metafile format, and its native format.  I want to copy the metafile version and place it in an image or frame for later use.  I'd rather not disturb the user with a dialog box every time this happens (basically every record).

I've seen the article "How to Retrieve Information from the Clipboard" -- it shows how to get text from the clipboard but I don't know how to a) go about getting a metafile format picture instead, and b) what to do with it when I've got it in order to place it in, say, an image control.

Does someone have a handy-dandy function for doing this?

Thanks in advance,
Ed


0
EdStout
Asked:
EdStout
  • 2
  • 2
1 Solution
 
ozphilCommented:
VBA does not have a Clipboard object, but VB does.
Why VB has it and VBA doesnt is beyond me.

I had a look at the C  API code to handle clipboard operations on WMF formats, and the code is as ugly as it gets. Refer to Charles Petzold 'Programming Windows'.

My workaround is to create and exe or activeX exe in VB which uses the Clipboard object to read the clipboard WMF format into a picture box, clear the clipboard and then write the picturebox back into the clipboard.

The exe form is made invisible so the user doesnt see whats happening behind the scenes.

I have coded the exe and it works fine, although i havent tried it for a multiformat clipboard image, but it should work.

I have not done an activeX exe version. With an activeX exe you could activatate the program as an object rather than shelling out to an exe.

If youre interested in this approach i could provide the VB code for you to test. There is very little code involved.


0
 
EdStoutAuthor Commented:
Thanks.  I agree about the VBA omission.  And yes, if you wouldn't mind sending the code (to EdStout@Heuristech.com), it'd save some time.  And perhaps the Access code to call it, just to make sure?

Thanks again.
0
 
ozphilCommented:
Thanks EdStout.

I thought id place the code here so that those paying to see the answer will actually see it. Ive hard wired the windows system and temporary directories. You can make it more generic if you wish.

1. In Access, insert the following code:

Private Sub Command2_Click()
    ' This reads the wmf image component in clipboard and replaces
    ' clipboard multiple format image with wmf format only. It also write wmf
    ' image to a temporary file c:\temp\wmfimage.wmf
    Shell ("c:\windows\readclipboardwmf.exe")
   
    ' read the temporary image file
    Image1.Picture = "c:\temp\wmfimage.wmf"
End Sub


2. In VB ( i used VB5), insert the following code:
Make a readclipboardwmf.exe from this code. Make the form visible property false.

Private Sub Form_Load()
    If Clipboard.GetFormat(vbCFMetafile) Then
        Me.Picture1 = Clipboard.GetData()
        Clipboard.Clear
        Clipboard.SetData Me.Picture1, vbCFMetafile
        ' Save image to file so that it can be read by
        ' MS Access image control
        SavePicture Picture1, "c:\temp\wmfimage.wmf"
    Else
        MsgBox "No metafile clipboard format found"
    End If

    End
 
End Sub

0
 
EdStoutAuthor Commented:
Works like a champ!  I can use the returned clipboard data just fine.  Thanks again.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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