Re: GDI/Screen capture

From: Steve Bugden (SteveBugden_at_discussions.microsoft.com)
Date: 10/07/04


Date: Thu, 7 Oct 2004 02:47:02 -0700

Hello Justin,

Thank you for the response.

Is there a better way to do this now? I'm using Visual Studio 2002.

Regards,

Steve.

"Justin Rogers" wrote:

> Whidbey introduces a CopyFromScreen method on the Graphics class. This will
> be used to promote bits on the Desktop DC into a managed environment. There
> were also GDI wrappers that had been written, but they are apparently marked
> internal in the latest releases and only available to the Windows Forms guys.
>
>
> --
> Justin Rogers
> DigiTec Web Consultants, LLC.
> Blog: http://weblogs.asp.net/justin_rogers
>
> "Steve Bugden" <SteveBugden@discussions.microsoft.com> wrote in message
> news:1754B3FC-C030-48A8-AD1B-42418E081C6A@microsoft.com...
> > Hi All
> >
> > Sometime ago I found some code which captures the screen using GDI (attached).
> >
> > I am wondering if it is posssible to achieve this directly from .Net without
> > the API calls. If this isn't possible is there a better way to do it.
> >
> > What sort of deployment issues will I have with the code attached below.
> > Will I need to deploy the gdi32.dll with my application for example?
> >
> > Regards,
> >
> > Steve.
> >
> > Public Class clsScreenCapture
> >
> > Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal
> > lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As
> > String, ByVal lpInitData As String) As Integer
> > Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As
> > Integer) As Integer
> > Private Declare Function CreateCompatibleBitmap Lib "GDI32" (ByVal hDC As
> > Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer
> > Private Declare Function GetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps"
> > (ByVal hdc As Integer, ByVal nIndex As Integer) As Integer
> > Private Declare Function SelectObject Lib "GDI32" (ByVal hDC As Integer,
> > ByVal hObject As Integer) As Integer
> > Private Declare Function BitBlt Lib "GDI32" (ByVal srchDC As Integer, ByVal
> > srcX As Integer, ByVal srcY As Integer, ByVal srcW As Integer, ByVal srcH As
> > Integer, ByVal desthDC As Integer, ByVal destX As Integer, ByVal destY As
> > Integer, ByVal op As Integer) As Integer
> > Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As Integer) As
> > Integer
> > Private Declare Function DeleteObject Lib "GDI32" (ByVal hObj As Integer)
> > As Integer
> > Const SRCCOPY As Integer = &HCC0020
> >
> > Public Function CaptureScreen() As Bitmap
> >
> > Dim hSDC, hMDC As Integer
> > Dim hBMP, hBMPOld As Integer
> > Dim r As Integer
> > Dim oBackground As Bitmap
> >
> > hSDC = CreateDC("DISPLAY", "", "", "")
> > hMDC = CreateCompatibleDC(hSDC)
> >
> > Dim fw, fh As Integer
> >
> > fw = Screen.PrimaryScreen.Bounds.Width 'GetDeviceCaps(hSDC, 0)
> > fh = Screen.PrimaryScreen.Bounds.Height 'GetDeviceCaps(hSDC, 10)
> > hBMP = CreateCompatibleBitmap(hSDC, fw, fh)
> >
> > hBMPOld = SelectObject(hMDC, hBMP)
> > r = BitBlt(hMDC, 0, 0, fw, fh, hSDC, 0, 0, 13369376)
> > hBMP = SelectObject(hMDC, hBMPOld)
> >
> > r = DeleteDC(hSDC)
> > r = DeleteDC(hMDC)
> >
> > Return Image.FromHbitmap(New IntPtr(hBMP))
> > DeleteObject(hBMP)
> >
> > End Function
> >
> > End Class
>
>
>



Relevant Pages

  • Re: GDI/Screen capture
    ... Justin Rogers ... "Steve Bugden" wrote in message ... >> The standard GDI is the only way to go for now. ... >>>>> lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Validation On An InputBox
    ... advice. ... >Hi Steve ... >The InputBoxfunction returns a string value, ... >> I assume I have to first declare s as something at the ...
    (microsoft.public.access.formscoding)
  • Re: Sorting a value based upon the values that appear in row A
    ... Dim rng As Range, sStr As String, i As Long ... "Steve" wrote in message ... >>Dim rng as Range, sStr as String, i as Long ...
    (microsoft.public.excel.programming)
  • Re: Base36
    ... that you've made is a string being attached. ... > "Justin Rogers" wrote in message ... >>> characters that may be confused for other characters when read by a> human. ... >>>> conversion is each direction is based on the tokens and powers arrays. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How do they make a laminated top?
    ... Steve Holst is laminating for tops and backs ... Have you ever played one of Steve's nylon string guitars? ... double-top/Nomex technique) his own 000 flat-top steel string. ... I think Steve is best known in the archtop world, ...
    (rec.music.makers.guitar.acoustic)