0

I'm trying to capture (printscreen) part of the active window. I'm using this simple and efficient code from Lutz Gentkow that works like a charm to capture the whole active window, but I need to capture a defined part of the window only, say a 300 px w x 150 px h.

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 KEYEVENTF_KEYUP = &H2
Private Const VK_SNAPSHOT = &H2C
Private Const VK_MENU = &H12

Sub AltPrintScreen()
     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 Sub

Also found this code from Zack Barresse that does what I want but for the Whole Screen, which make me believe it's possible but capturing from Whole Screen doesn't work for me as I use multiple screens.

Using windows API is out of my scope of knowledge so can anyone point me to the right direction on how to capture Part of the Active Window, eg defining StartLeft, StartTop, Width, Height ? by modifying one of this codes? Thanks

Diego
  • 105
  • 2
  • 4
  • 18
  • 1
    `by modifying one of this codes` - you can't. You can by throwing this code away and having a completely different code. If you're not happy with that, you can [pretend](https://stackoverflow.com/a/43904536/11683) it's just a part of the image. – GSerg Jul 17 '17 at 06:50
  • If you believe that abusing the clipboard for internal application use is ok, make sure to thoroughly test your uninstaller code. – IInspectable Jul 17 '17 at 14:38

0 Answers0