AW: Bitmap in UF
27.03.2023 19:33:40
volti
Hi,
ich habe noch ein bisschen was umgestellt. Schau mal, ob es jetzt besser läuft.
Code:
Private Declare PtrSafe Function OleCreatePictureIndirect Lib "oleaut32.dll" ( _
ByRef PicDesc As PIC_DESC, ByRef RefIID As GUID, _
ByVal fPictureOwnsHandle As LongPtr, ByRef IPic As IPictureDisp) As Long
Private Declare PtrSafe Function CopyImage Lib "user32" ( _
ByVal handle As LongPtr, ByVal un1 As Long, ByVal n1 As Long, _
ByVal n2 As Long, ByVal un2 As Long) As LongPtr
Private Declare PtrSafe Function IsClipboardFormatAvailable Lib "user32" ( _
ByVal wFormat As Long) As Long
Private Declare PtrSafe Function GetClipboardData Lib "user32" ( _
ByVal wFormat As Long) As LongPtr
Private Declare PtrSafe Function OpenClipboard Lib "user32" ( _
ByVal hWnd As LongPtr) As Long
Private Declare PtrSafe Function CloseClipboard Lib "user32" () As Long
Private Declare PtrSafe Function EmptyClipboard Lib "user32" () As Long
Private Declare PtrSafe Function CLSIDFromString Lib "ole32.dll" ( _
ByVal lpsz As Any, ByRef pCLSID As GUID) As Long
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Private Type PIC_DESC
lSize As Long
lType As Long
hPic As LongPtr
hPal As LongPtr
End Type
Private Const PICTYPE_BITMAP = 1
Private Const CF_BITMAP = 2
Private Const IMAGE_BITMAP = 0
Private Const LR_COPYRETURNORG = &H4
Private Const GUID_IPICTUREDISP As String = "{7BF80981-BF32-101A-8BBB-00AA00300CAB}"
Sub Paste_Picture_In_UF()
If Sheets("1Hz").Range("E1") = 1 Then
AppActivate UserForm1.Caption, True
Call Paste_Picture_In_UF_EX(3, "DA1:DE6")
Call Paste_Picture_In_UF_EX(4, "DG1:DK6")
ElseIf Sheets("1Hz").Range("E1") = 2 Then
AppActivate UserForm1.Caption, True
Call Paste_Picture_In_UF_EX(3, "DM1:DQ6")
Call Paste_Picture_In_UF_EX(4, "DS1:DW6")
End If
End Sub
Sub Paste_Picture_In_UF_EX(iUF As Integer, sBer As String)
' Fügt ein Bild aus der Zwischenablage in ein Userform-Control ein
Dim oPict As IPictureDisp
Dim tPicInfo As PIC_DESC, tID_IDispatch As GUID
OpenClipboard (0&)
EmptyClipboard
CloseClipboard
On Error Resume Next
Do
ThisWorkbook.Sheets("1Hz").Range(sBer).CopyPicture Appearance:=xlScreen, Format:=xlBitmap
If Err = 0 Then Exit Do
Err.Clear
Loop
If IsClipboardFormatAvailable(CF_BITMAP) <> 0 Then
If OpenClipboard(0&) <> 0 Then
Call CLSIDFromString(StrPtr(GUID_IPICTUREDISP), tID_IDispatch)
With tPicInfo
.lSize = LenB(tPicInfo)
.lType = PICTYPE_BITMAP
.hPic = CopyImage(GetClipboardData(CF_BITMAP), _
IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG)
End With
If tPicInfo.hPic <> 0 Then _
OleCreatePictureIndirect tPicInfo, tID_IDispatch, 0&, oPict
If Not oPict Is Nothing Then
Select Case iUF
Case 3: UserForm1.Image3.Picture = oPict
Case 4: UserForm1.Image4.Picture = oPict
End Select
Else
MsgBox "Das Bild kann nicht angezeigt werden!", vbCritical, "Bild einfügen"
End If
End If
CloseClipboard
End If
Application.CutCopyMode = False
End Sub
_________________________
viele Grüße aus Freigericht 😊
Karl-Heinz