Results 1 to 3 of 3

Thread: [RESOLVED] My screen capture app doesn't copy Visual Basic's dropdown menus.

Threaded View

  1. #3

    Thread Starter
    Fanatic Member Peter Porter's Avatar
    Join Date
    Jul 2013
    Location
    Germany
    Posts
    581

    Smile 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
    Last edited by Peter Porter; Mar 22nd, 2015 at 07:10 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width