Zurück zur Homepage

Bildschirmkopie

Fenster- oder Bildschirmkopien in die Zwischenablage klappen nicht mit (igitt) SendKeys. Hier zwei Prozeduren, die das machen. NT muss auch hier etwas anders gehandhabt werden, als Win 9x.

Beispieldatei (copytoclip.zip 12 kB)

Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_MENU = &H12
Private Const VK_SNAPSHOT = &H2C

Private Declare Sub keybd_event Lib "user32" _
  (ByVal bVk As Byte, ByVal bScan As Byte, _
  ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Declare Function GetVersionEx Lib _
  "kernel32" Alias "GetVersionExA" _
  (lpVersionInformation As OSVERSIONINFO) As Long

 Private Type OSVERSIONINFO
  dwOSVersionInfoSize As Long
  dwMajorVersion As Long
  dwMinorVersion As Long
  dwBuildNumber As Long
  dwPlatformId As Long
  szCSDVersion As String * 128
End Type

'Bildschirmkopie, wenn mode=0. Fensterkopie, wenn mode=1
Public Sub CopyToClip(mode As Integer)
  Dim lngParam As Long
  If mode <> 0 Then
    keybd_event VK_MENU, 0, 0, 0
    keybd_event VK_SNAPSHOT, 0, 0, 0
    keybd_event VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0
    keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0
  Else
    If IsWindows9X() Then lngParam = 1
    keybd_event VK_SNAPSHOT, lngParam, 0, 0
    keybd_event VK_SNAPSHOT, lngParam, KEYEVENTF_KEYUP, 0
  End If
End Sub

Private Function IsWindows9X()
  Dim osinfo As OSVERSIONINFO
  With osinfo
    .dwOSVersionInfoSize = Len(osinfo)
    GetVersionEx osinfo
    If .dwPlatformId = 1 Then _
      IsWindows9X = True
    End With
End Function