VIsualPenguin
Nov 13th, 2001, 07:46 AM
if I use the keyb_event to send a printscreen command, I just get a picture from the application. nothing else. how can I copy the screen completely.
VIP
Hack
Nov 13th, 2001, 07:59 AM
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, _
ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const VK_SNAPSHOT = &H2C
'Author: Dalin Nie (Edited by Matthew Gates)
'Origin: http://www.vbcode.com
'Purpose: This function capture the screen or the active window of your computer. Programmatically and save it to a .bmp file.
'VB version: VB 6,VB 5,VB 4/32
'Save Screen As Bitmap
Private Function SaveScreen(ByVal theFile As String) As Boolean
On Error Resume Next
'To get the Entire Screen
Call keybd_event(vbKeySnapshot, 1, 0, 0)
'To get the Active Window
'Call keybd_event(vbKeySnapshot, 0, 0, 0)
SavePicture Clipboard.GetData(vbCFBitmap), theFile
SaveScreen = True
Exit Function
End Function
' Prntform sample from BlackBeltVB.com
' http://blackbeltvb.com
'
' Written by Matt Hart
' Copyright 1999 by Matt Hart
'
' This software is FREEWARE. You may use it as you see fit for
' your own projects but you may not re-sell the original or the
' source code. Do not copy this sample to a collection, such as
' a CD-ROM archive. You may link directly to the original sample
' using "http://blackbeltvb.com/prntform.htm"
'
' No warranty express or implied, is given as to the use of this
' program. Use at your own risk.
'
' This sample utilizes a better method than "PrintForm" to print the contents of
' a Form. PrintForm sometimes excludes grid and other controls. This method simulates
' pressing the PrintScrn key, which copies the image of either the form or screen to
' the clipboard. Note that I call the .Clear method of the Clipboard first - that's because
' it might already have text or something on it.
'
' When printing, note that I scale the picture's height to proportionally fit the
' printer's resolution. The procedure would need to be adjusted if the Height of the
' Form/Screen was greater than Printer.ScaleHeight, or if the Height was greater than
' the Width and the Width was greater than Printer.ScaleWidth.
'
' Updated with VK_MENU keypresses - note that NT needs these.
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const VK_MENU As Byte = &H12
Private Const VK_SNAPSHOT As Byte = &H2C
Private Const KEYEVENTF_KEYUP = &H2
Dim lHeight As Long
Clipboard.Clear
Call keybd_event(VK_SNAPSHOT, 1, 0, 0)
DoEvents
Call keybd_event(VK_SNAPSHOT, 1, KEYEVENTF_KEYUP, 0)
Printer.Print
lHeight = (Printer.ScaleWidth / Screen.Width) * Screen.Height
Printer.PaintPicture Clipboard.GetData, 0, 0, Printer.ScaleWidth, lHeight
Printer.EndDocTake your pick!