![getclipboarddata copyimage getclipboarddata copyimage](https://support.joinhandshake.com/hc/article_attachments/360072251594/copy_image_address.png)
hPal = IIf(lPicType = CF_BITMAP, hPal, 0) ' Handle to palette (if bitmap). Type = IIf(lPicType = CF_BITMAP, PICTYPE_BITMAP, PICTYPE_ENHMETAFILE) ' Type of Picture Size = Len(uPicInfo) ' Length of structure. ' Create the Interface GUID (for the IPicture interface) ' IPicture requires a reference to "OLE Automation"ĭim r As Long, uPicInfo As uPicDesc, IID_IDispatch As GUID, IPic As IPicture Private Function CreatePicture(ByVal hPic As Long, ByVal hPal As Long, ByVal lPicType) As IPicture ''' Requires a reference to the "OLE Automation" type library ''' Purpose: Converts a image (and palette) handle into a Picture object. If hPtr 0 Then Set PastePicture = CreatePicture(hCopy, 0, lPicType) 'If we got a handle to the image, convert it into a Picture object and return it HCopy = CopyEnhMetaFile(hPtr, vbNullString) HCopy = CopyImage(hPtr, IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG) 'Create our own copy of the image on the clipboard, in the appropriate format. HPicAvail = IsClipboardFormatAvailable(lPicType) 'Check if the clipboard contains the required format LPicType = IIf(lXlPicType = xlBitmap, CF_BITMAP, CF_ENHMETAFILE) 'Convert the type of picture requested from the xl constant to the API constant
![getclipboarddata copyimage getclipboarddata copyimage](https://i.stack.imgur.com/DW0pc.png)
''' 15 Nov 98 Stephen Bullen Updated to create our own copies of the clipboard imagesįunction PastePicture(Optional lXlPicType As Long = xlPicture) As IPictureĭim h As Long, hPicAvail As Long, hPtr As Long, hPal As Long, lPicType As Long, hCopy As Long ''' xlPicture to create a metafile (default) ''' Arguments: lXlPicType - The type of picture to create. ''' Purpose: Get a Picture object showing whatever's on the clipboard. 'The API format types we're interested in 'Create our own copy of the bitmap, so it doesn't get wiped out by subsequent clipboard updates.ĭeclare Function CopyImage Lib "user32" (ByVal handle As Long, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long 'Create our own copy of the metafile, so it doesn't get wiped out by subsequent clipboard updates.ĭeclare Function CopyEnhMetaFile Lib "gdi32" Alias "CopyEnhMetaFileA" (ByVal hemfSrc As Long, ByVal lpszFile As String) As Long Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As uPicDesc, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long 'Convert the handle into an OLE IPicture interface. Private Declare Function CloseClipboard Lib "user32" () As Long Private Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Integer) As Long Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Integer) As Long 'Does the clipboard contain a bitmap/metafile? 'Declare a UDT to store the bitmap information 'Declare a UDT to store a GUID for the IPicture OLE Interface
#GETCLIPBOARDDATA COPYIMAGE CODE#
'* fnOLEError Get the error text for an OLE error code '* CreatePicture Private function to convert a bitmap or metafile handle to an OLE reference '* PastePicture The entry point for the routine '* to paste a picture of whatever is on the clipboard into a standard image control. '* Set Image1.Picture = PastePicture(xlPicture) '* To use it, just copy this module into your project, then you can use: '* The code in this module has been derived from a number of sources '* The code requires a reference to the "OLE Automation" type library '* the picture type - xlBitmap or xlPicture. The PastePicture function takes an optional argument of '* This object can then be assigned to (for example) and Image control '* DESCRIPTION: Creates a standard Picture object from whatever is on the clipboard. '* AUTHOR & DATE: STEPHEN BULLEN, Office Automation Ltd