Advertisement
Java_Volume1 Windows API Call/ Explanation #98519

Screen Capture Class Module

This module will allow you to easily save screen captures. You can specify wether you want to capture the entire screen or just the active window. I've included a copy of the class module for download (since PSC doesn't do that good of a job at formating the code). Any comments or suggestions are welcome.

AI

Ringkasan AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Kode Sumber
original-source
<p>Option Explicit<br>
<br>
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As
Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)<br>
Private Declare Function MapVirtualKey Lib "user32" Alias
"MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long<br>
Private Declare Function GetVersionEx& Lib "kernel32" Alias
"GetVersionExA" (lpVersionInformation As OSVERSIONINFO)<br>
<br>
Private Const VK_MENU = &H12<br>
Private Const VK_SNAPSHOT = &H2C<br>
Private Const KEYEVENTF_KEYUP = &H2<br>
<br>
' used for dwPlatformId<br>
Private Const VER_PLATFORM_WIN32s = 0<br>
Private Const VER_PLATFORM_WIN32_WINDOWS = 1<br>
Private Const VER_PLATFORM_WIN32_NT = 2<br>
<br>
Private Type OSVERSIONINFO ' 148 Bytes<br>
dwOSVersionInfoSize As Long<br>
dwMajorVersion As Long<br>
dwMinorVersion As Long<br>
dwBuildNumber As Long<br>
dwPlatformId As Long<br>
szCSDVersion As String * 128<br>
End Type<br>
<br>
<br>
Public Function SaveScreenToFile(ByVal strFile As String, Optional EntireScreen As Boolean
= True) As Boolean</p>
<p><br>
Dim altscan%<br>
Dim snapparam%<br>
Dim ret&, IsWin95 As Boolean<br>
Dim verInfo As OSVERSIONINFO</p>
<blockquote>
 <p><br>
 On Error GoTo errHand<br>
 <br>
 'Check if the File Exist<br>
 If Dir(strFile) <> "" Then<br>
 Kill strFile<br>
 'Exit Function<br>
 End If<br>
 <br>
 altscan% = MapVirtualKey(VK_MENU, 0)<br>
 If EntireScreen = False Then<br>
 keybd_event VK_MENU, altscan, 0, 0<br>
 ' It seems necessary to let this key get processed before<br>
 ' taking the snapshot.<br>
 End If<br>
 <br>
 verInfo.dwOSVersionInfoSize = 148<br>
 ret = GetVersionEx(verInfo)<br>
 If verInfo.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then<br>
 IsWin95 = True<br>
 Else<br>
 IsWin95 = False<br>
 End If<br>
 <br>
 If EntireScreen = True And IsWin95 Then snapparam = 1<br>
 <br>
 DoEvents ' These seem necessary to make it reliable<br>
 <br>
 ' Take the snapshot<br>
 keybd_event VK_SNAPSHOT, snapparam, 0, 0<br>
 <br>
 DoEvents<br>
 <br>
 If EntireScreen = False Then keybd_event VK_MENU, altscan, KEYEVENTF_KEYUP, 0<br>
 <br>
 SavePicture Clipboard.GetData(vbCFBitmap), strFile<br>
 <br>
 SaveScreenToFile = True<br>
 <br>
 Exit Function<br>
 <br>
 errHand:<br>
 <br>
 'Error handling<br>
 SaveScreenToFile = False</p>
</blockquote>
<p><br>
End Function<br>
<br>
Komentar Asli (3)
Dipulihkan dari Wayback Machine