1 Attachment(s)
[RESOLVED] My screen capture app doesn't copy Visual Basic's dropdown menus.
Lets say someone wants to capture a video tutorial coding within visual basic. Using my app, it will capture the screen to a video, but it wont capture Visual Basic's dropdown menus, like what you see if you click Debug. I would really appreciate it if someone could tweak my code below to capture VB's dropdowns.
My application is at the following link:
http://www.vbforums.com/showthread.p...eb-2015-update
Attachment 124963
Code:
Dim BMP As New System.Drawing.Bitmap(MW, MH2, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
Dim Cap As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(BMP)
Cap.CopyFromScreen(New Point(0, bdr), New Point(0, 0), ScreenSize, System.Drawing.CopyPixelOperation.SourceCopy)
BMP.Save(writer.BaseStream, System.Drawing.Imaging.ImageFormat.Bmp)
BMP.Dispose()
Cap.Dispose()
GC.Collect()
.
Re: My screen capture app doesn't copy Visual Basic's dropdown menus. Need help!
It also doesn't copy some tool tips, or other popup menus in Visual Studio.
I believe it is probably because in Visual Studio they are using layered windows to get the drop shadow around the menus, and copyFromScreen won't copy the layered windows.
There is apparently suppose to be an option that can be turned on in one of the overloads of CopyFromScreen that will copy the layered windows, but also apparently is flawed so doesn't work.
I don't know, haven't tried anything, but it appears there may be an "older" P/Invoke method to do the screen capture that will copy the layered windows. See this link to investigate if you haven't already.
Re: [RESOLVED] My screen capture app doesn't copy Visual Basic's dropdown menus.
Thanks Passel!
Hans Passant's code using P/Invoke to capture the screen works like a Charm! My app can now capture Visual Studio's layered dropdown menus.
I'll update my application at the above link soon.
Code:
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Namespace WindowsFormsApplication1
Public Partial Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Sub button1_Click(sender As Object, e As EventArgs)
Dim sz As Size = Screen.PrimaryScreen.Bounds.Size
Dim hDesk As IntPtr = GetDesktopWindow()
Dim hSrce As IntPtr = GetWindowDC(hDesk)
Dim hDest As IntPtr = CreateCompatibleDC(hSrce)
Dim hBmp As IntPtr = CreateCompatibleBitmap(hSrce, sz.Width, sz.Height)
Dim hOldBmp As IntPtr = SelectObject(hDest, hBmp)
Dim b As Boolean = BitBlt(hDest, 0, 0, sz.Width, sz.Height, hSrce, _
0, 0, CopyPixelOperation.SourceCopy Or CopyPixelOperation.CaptureBlt)
Dim bmp As Bitmap = Bitmap.FromHbitmap(hBmp)
SelectObject(hDest, hOldBmp)
DeleteObject(hBmp)
DeleteDC(hDest)
ReleaseDC(hDesk, hSrce)
bmp.Save("c:\temp\test.png")
bmp.Dispose()
End Sub
' P/Invoke declarations
<DllImport("gdi32.dll")> _
Private Shared Function BitBlt(hdcDest As IntPtr, xDest As Integer, yDest As Integer, wDest As Integer, hDest As Integer, hdcSource As IntPtr, _
xSrc As Integer, ySrc As Integer, rop As CopyPixelOperation) As Boolean
End Function
<DllImport("user32.dll")> _
Private Shared Function ReleaseDC(hWnd As IntPtr, hDc As IntPtr) As Boolean
End Function
<DllImport("gdi32.dll")> _
Private Shared Function DeleteDC(hDc As IntPtr) As IntPtr
End Function
<DllImport("gdi32.dll")> _
Private Shared Function DeleteObject(hDc As IntPtr) As IntPtr
End Function
<DllImport("gdi32.dll")> _
Private Shared Function CreateCompatibleBitmap(hdc As IntPtr, nWidth As Integer, nHeight As Integer) As IntPtr
End Function
<DllImport("gdi32.dll")> _
Private Shared Function CreateCompatibleDC(hdc As IntPtr) As IntPtr
End Function
<DllImport("gdi32.dll")> _
Private Shared Function SelectObject(hdc As IntPtr, bmp As IntPtr) As IntPtr
End Function
<DllImport("user32.dll")> _
Public Shared Function GetDesktopWindow() As IntPtr
End Function
<DllImport("user32.dll")> _
Public Shared Function GetWindowDC(ptr As IntPtr) As IntPtr
End Function
End Class
End Namespace