Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PrintScreen

Status
Not open for further replies.

tbuch

Programmer
Oct 17, 2000
80
0
0
US
Does anyone know a way to do a PrintScreen without the user pressing the PrintScreen key?

tbuch
 
If it's a vb form that you want to printscreen then you can do a Form1.PrintForm
 
You can simulate PrintScreen and Alt + PrintScreen with these API functions:
Code:
Public Declare Sub keybd_event Lib "user32" (Byval bVk As Integer, Byval _
bScan As Integer, Byval dwFlags As Long, Byval dwExtraInfo As Long)

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

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

Public Const VER_PLATFORM_WIN32_NT = 2
Public Const VER_PLATFORM_WIN32_WINDOWS = 1
Public Const VER_PLATFORM_WIN32s = 0

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

Public Function fGetWinMajorVer() As Integer

 '--- Returns the major version of Windows as an integer
 '--- or zero if an error occurs.
 '--- returns 4 or greater for W2000 or later

 Dim pudtOSI As OSVERSIONINFO
 Dim plngRtn As Long

 pudtOSI.szCSDVersion = Space$(128)
 pudtOSI.dwOSVersionInfoSize = Len(pudtOSI)
 plngRtn = GetVersionEx(pudtOSI)

 If Not plngRtn = 0 Then
  fGetWinMajorVer = Cint(pudtOSI.dwMajorVersion)
 End If

End Function

Public Sub sCopyScreenToClip

 '--- simulates PrintScreen

 If fGetWinMajorVer > 4 Then
  'Windows 2000
  keybd_event VK_SNAPSHOT, 0, 0, 0
 Else
  'All other versions of Windows
  keybd_event VK_SNAPSHOT, 1, 0, 0
 End If

End Sub

Public Sub sCopyActiveWindowToClip

 '--- simulates Alt + PrintScreen

 If fGetWinMajorVer > 4 Then
  'Windows 2000
  keybd_event VK_SNAPSHOT, 1, 0, 0
 Else
  'All other versions of Windows
  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
 End If

End Sub

Paul Bent
Northwind IT Systems
 
Not sure if it apply, but you can look here:

thread222-520827 the background behind a form) thread
 
I re-thought my situation, and decided to leave itr to the user to press the PrintScreen key. No sense doing EVERYTHING for the user!

But thanks for the tips. I may use them in another project.

tbuch
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top