[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

clipboard

Posted on 2011-09-18
4
Medium Priority
?
569 Views
Last Modified: 2013-11-28
I'm using the followin code to load a bitmap to a picture control and then trying to copy the image to the clipboard:

 Private Declare Function OpenClipboard Lib "USER32" (ByVal hWnd As Long) As Long
Private Declare Function CloseClipboard Lib "USER32" () As Long
Private Declare Function SetClipboardData Lib "USER32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
Private Declare Function EmptyClipboard Lib "USER32" () As Long
Private Const CF_BITMAP = 2


Public Function SavePicBit(str21 As String, pPic As Object, boundFrame As BoundObjectFrame, frm As Form, estNo As Long, PicRef As Long)
.....
    pPic.Visible = True
pPic.SetFocus
pPic.Picture = str21
 OpenClipboard 0
 EmptyClipboard
 SetClipboardData pPic.Image & vbNullChar, CF_BITMAP

.....
I'm able to see the correct image appear on the control pPic, but the SetClipboardData is not saving the image to the clipboard.
Any sugestions on what is missing??

0
Comment
Question by:johnf9838
[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
  • 2
  • 2
4 Comments
 
LVL 13

Expert Comment

by:khairil
ID: 36556941
Hi,

Just call this code:

Clipboard.SetData pPic.Image 

Open in new window


It works fine.
0
 

Author Comment

by:johnf9838
ID: 36556960
I must be missing something. I had tried this code previously, but the message coming up is "argument not optional"
What do I need to declare to make this work? Also does it still need the OpenClipboard and EmptyClipboard??? This is in an Access 2003 module using VBA , not VB
0
 
LVL 13

Accepted Solution

by:
khairil earned 1500 total points
ID: 36557191
Sorry pal, missing that one.

SetClipboardData pPic.Image & vbNullChar, CF_BITMAP

is not the way to call the API. The first parameter is wFormat, which is CF_BITMAP. The second parameter are memory allocation of the handler.

Here is my code, fix it to your need. I am using other API called to load image to handler. I off to bed now, it really late for me now:

Const LR_LOADFROMFILE = &H10
Const IMAGE_BITMAP = 0
Const IMAGE_ICON = 1
Const IMAGE_CURSOR = 2
Const IMAGE_ENHMETAFILE = 3
Const CF_BITMAP = 2

Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal dwImageType As Long, ByVal dwDesiredWidth As Long, ByVal dwDesiredHeight As Long, ByVal dwFlags As Long) As Long
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function EmptyClipboard Lib "user32" () As Long
Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
Private Declare Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Long) As Long

Private Sub CopyImage()
Dim hDC As Long, hBitmap As Long

    'Load the bitmap into the memory
    hBitmap = LoadImage(0, "C:\Users\khairil\Desktop\graphic.bmp", IMAGE_BITMAP, 320, 200, LR_LOADFROMFILE)

    If hBitmap = 0 Then
        MsgBox "There was an error while loading the bitmap"
        Exit Sub
    End If

    'open the clipboard
    OpenClipboard 0

    'Clear the clipboard
    EmptyClipboard

    'Put our bitmap onto the clipboard
    SetClipboardData CF_BITMAP, hBitmap

    'Check if there's a bitmap on the clipboard
    If IsClipboardFormatAvailable(CF_BITMAP) = 0 Then
        MsgBox "There was an error while pasting the bitmap to the clipboard!"
    End If

    'Close the clipboard
    CloseClipboard

    'YOU CAN TRY AND PASTE INTO MSPAINT OR WORD
End Sub


Private Sub CommandButton1_Click()
    CopyImage
End Sub

Open in new window

0
 

Author Closing Comment

by:johnf9838
ID: 36557269
worked like a charm
Thanks
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

649 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