Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleSimulate Alt-PrintScrn to save a form's image into a bitmap file
KeywordsAlt-Prnt, print screen, clipboard, screen capture, form image
CategoriesTips and Tricks
 
Use the keybd_event API function to simulate Alt-PrintScreen to copy the form's image to the clipboard. Use the Clipboard object's GetData method to get the picture and use SavePicture to save the picture into a bitmap file.
 
Private Sub Command1_Click()
#Const WINDOWS_VERSION = "Windows2000"

Dim alt_key As Long

    ' Capture an image of the form in the clipboard.
    ' Press Alt.
    alt_key = MapVirtualKey(VK_MENU, 0)
    keybd_event VK_MENU, alt_key, 0, 0
    DoEvents

    ' Press Print Scrn.
    #If WINDOWS_VERSION = "Windows2000" Then
        keybd_event VK_SNAPSHOT, 0, 0, 0
    #Else
        keybd_event VK_SNAPSHOT, 1, 0, 0
    #End If
    DoEvents

    ' Release Alt.
    keybd_event VK_MENU, alt_key, KEYEVENTF_KEYUP, 0
    DoEvents

    ' Paste the image into the bitmap file.
    SavePicture Clipboard.GetData(vbCFBitmap), Text1.Text
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated