How to Simulate Alt-PrintScrn to save a form’s image into a bitmap file
Posted on January 4, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | 'System & API - How to Simulate Alt-PrintScrn to save a form's image into a bitmap file Option Explicit 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 = &H12 Private Const VK_SNAPSHOT = &H2C Private Const KEYEVENTF_KEYUP = &H2 Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" _ (ByVal wCode As Long, ByVal wMapType As Long) As Long 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 Private Sub Form_Load() Dim app_path As String app_path = App.Path If Right$(app_path, 1) <> "\" Then app_path = app_path & "\" Text1.Text = app_path & "form_img.bmp" End Sub |