|
-
Mar 20th, 2025, 03:47 PM
#18
Member
Re: VB6 - Capture any Window, even in background, with WinRT / Windows.Graphics.Captu
Certainly For the implementation of vb6 it is really a marvel. 
I remember starting this thread: https://www.vbforums.com/showthread....nd-PrintWindow
But I ended up using PrintWindow. Now I'd like to use Windows.Graphics.Capture, which is great for reducing CPU load.
Do you think you could help me organize a .dll file to properly encapsulate this application? In fact, I created one with PrintWindow that creates a hidden picturebox at runtime. When I call a function, I capture the window image using Hwnd at that instant and can easily export it to another picturebox for easy scaling and cropping if needed.
Although in this case, I'd like to implement continuous capture, As you have done in your project. Doing this repeatedly with standard timers causes the yellow frame to flicker, which is a bit annoying on Windows 10.
Code:
Public CVHwnd As Long
Public CVCapture As PictureBox
Private CVForm As Form
'---------------------------------------------------------------
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function PrintWindow Lib "User32.dll" (ByVal hwnd As Long, ByVal hdcBlt As Long, ByVal nFlags As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
'----------------------------------------------------------------
Public Function SetupCapture(GHwnd As Long, ByRef GForm As Object)
On Error GoTo QH
CVHwnd = GHwnd
Set CVForm = GForm
Set CVCapture = CVForm.Controls.Add("VB.PictureBox", "MainCaptureCV")
QH:
End Function
Public Function GetCapture(SMode As Long, Optional SWidth As Long, Optional SHeight As Long)
Dim Calc_hWnd As Long
Dim Calc_Rect As RECT
CVForm.ScaleMode = vbPixels
CVCapture.ScaleMode = vbPixels
CVCapture.AutoRedraw = True
' Get Handle to windows calculator
Calc_hWnd = CVHwnd
' get size of windows calculator
If Calc_hWnd Then
GetWindowRect Calc_hWnd, Calc_Rect
' size temp destination to calc
If SWidth = 0 Then
CVCapture.Width = (Calc_Rect.Right - Calc_Rect.Left)
Else
CVCapture.Width = SWidth
End If
If SHeight = 0 Then
CVCapture.Height = (Calc_Rect.Bottom - Calc_Rect.Top)
Else
CVCapture.Height = SHeight
End If
' capture it
PrintWindow Calc_hWnd, CVCapture.hdc, SMode 'PW_CLIENTONLY Or PW_RENDERFULLCONTENT
CVCapture.Refresh
BitBlt CVCapture.hdc, 0, 0, _
CVCapture.ScaleWidth, _
CVCapture.ScaleHeight, _
CVCapture.hdc, 0, 0, vbSrcCopy
CVCapture.Picture = CVCapture.Image
Else
'Msgbox "Err Cap"
End If
End Function
Last edited by Maatooh; Mar 20th, 2025 at 04:47 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|