AW: Was das Programm macht ist einfach...
22.02.2010 15:53:03
Uwe
Hallo Pepi,
teste mal das.
Gefunden auf
http://www.xlam.ch/pos/code.htm#Screen%20Shot%20eines%20Benutzerformulares%20in%20die%20Zwischenablage%20erstellen
' **************************************************************
' Modul: UserForm1 Typ = Userform
Option Explicit
Private Sub CommandButton1_Click()
Me.Repaint
Call UserFormScreenShot
With ActiveSheet
.Paste .Range("D4")
End With
End Sub
' Modul: Modul1 Typ = Allgemeines Modul
Option Explicit
Type RECT_Type
left As Long
top As Long
right As Long
bottom As Long
End Type
Declare Function GetActiveWindow Lib "User32" () As Long
Declare Function GetDesktopWindow Lib "User32" () As Long
Declare Sub GetWindowRect Lib "User32" (ByVal Hwnd As Long, lpRect As RECT_Type)
Declare Function GetDC Lib "User32" (ByVal Hwnd As Long) As Long
Declare Function CreateCompatibleDC Lib "Gdi32" (ByVal hdc As Long) As Long
Declare Function CreateCompatibleBitmap Lib "Gdi32" (ByVal hdc As Long, ByVal nWidth As Long, _
ByVal nHeight As Long) As Long
Declare Function SelectObject Lib "Gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Declare Function BitBlt Lib "Gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, _
ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, _
ByVal XSrc As Long, ByVal YSrc As Long, ByVal dwRop As Long) As Long
Declare Function OpenClipboard Lib "User32" (ByVal Hwnd As Long) As Long
Declare Function EmptyClipboard Lib "User32" () As Long
Declare Function SetClipboardData Lib "User32" (ByVal wFormat As Long, ByVal hMem As Long) As _
Long
Declare Function CloseClipboard Lib "User32" () As Long
Declare Function ReleaseDC Lib "User32" (ByVal Hwnd As Long, ByVal hdc As Long) As Long
Declare Function DeleteDC Lib "Gdi32" (ByVal hdc As Long) As Long
Global Const SRCCOPY = &HCC0020
Global Const CF_BITMAP = 2
Public Sub UserFormScreenShot()
Dim FormHwnd As Long
Dim DeskHwnd As Long
Dim hdc As Long
Dim hdcMem As Long
Dim rect As RECT_Type
Dim junk As Long
Dim fwidth As Long
Dim fheight As Long
Dim hBitmap As Long
DeskHwnd = GetDesktopWindow()
FormHwnd = GetActiveWindow()
Call GetWindowRect(FormHwnd, rect)
fwidth = rect.right - rect.left
fheight = rect.bottom - rect.top
hdc = GetDC(DeskHwnd)
hdcMem = CreateCompatibleDC(hdc)
hBitmap = CreateCompatibleBitmap(hdc, fwidth, fheight)
If hBitmap 0 Then
junk = SelectObject(hdcMem, hBitmap)
junk = BitBlt(hdcMem, 0, 0, fwidth, fheight, hdc, rect.left, rect.top, SRCCOPY)
junk = OpenClipboard(DeskHwnd)
junk = EmptyClipboard()
junk = SetClipboardData(CF_BITMAP, hBitmap)
junk = CloseClipboard()
End If
junk = DeleteDC(hdcMem)
junk = ReleaseDC(DeskHwnd, hdc)
End Sub
Gruß Uwe