DirectX .Net?

  • Thread starter Thread starter gregory_may
  • Start date Start date
G

gregory_may

Does anyone know if anything is in the works to make DirectX work better
with .Net?

Thanks!
 
I have been working on a screen capture routine. This is close (Its what I
am using for now), one big problem with this .... Direct X overlays &
Applications don't get captured. I wish there is a nice way to grab the
Screen, Menu Pop-up's, Cursors, & DirectX Overlays all in one shot (Oh, and
it needs to be fast).

If you have any suggestions they are much appreciated!

Thanks!



Public oBackground As System.Drawing.Bitmap

Public Sub CaptureScreen()

Dim hSDC, hMDC, hMDC2 As Integer

Dim hBMP, hBMPOld As Integer

Dim CurInf As CursorInfo

Dim CurPos As PointAPI

Dim FW As Integer 'Width

Dim FH As Integer 'Height

Try

'Source DC

hSDC = CreateDC("DISPLAY", "", "", "")

'Destination DC with transpairent windows

hMDC = CreateCompatibleDC(hSDC)

'Screen Width

FW = GetDeviceCaps(hSDC, HORIZRES)

'Screen height

FH = GetDeviceCaps(hSDC, VERTRES)

hBMP = CreateCompatibleBitmap(hSDC, FW, FH)

hBMPOld = SelectObject(hMDC, hBMP)

Call BitBlt(hMDC, 0, 0, FW, FH, hSDC, 0, 0, RasterOperations.SRCCOPY +
RasterOperations.CAPTUREBLT)

Call DeleteDC(hSDC)

'get cursor information

CurInf.cbSize = Len(CurInf)

Call GetCursorInfo(CurInf)

If (CurInf.flags And CURSOR_SHOWING) Then

'Call GetCursorPos(CurPos)

Call DrawIconEx(hMDC, CurInf.ptScreenPos.X, CurInf.ptScreenPos.Y, _

CurInf.hCursor, 0, 0, 0, False, DI_NORMAL)

End If

Call SelectObject(hMDC, hBMPOld)

Call DeleteDC(hMDC)

oBackground = System.Drawing.Image.FromHbitmap(New IntPtr(hBMP))

DeleteObject(hBMP)

DeleteObject(hBMPOld)

'Seems to be a memory hole in fromHbitmap ....

'Code gets SLOW when not GC.Collect ing ... wierd.

'GC.Collect() &&&

Catch ex As Exception

Debug.WriteLine("General GDI ERROR: " & ex.Message.ToString)

End Try

End Sub

' Constants - BitBlt.dwRop

Public Enum RasterOperations

SRCCOPY = &HCC0020 ' Copies the source rectangle directly to the destination
rectangle.

SRCPAINT = &HEE0086 ' Combines the colors of the source and destination
rectangles by using the Boolean OR operator.

SRCAND = &H8800C6 ' Combines the colors of the source and destination
rectangles by using the Boolean AND operator.

SRCINVERT = &H660046 ' Combines the colors of the source and destination
rectangles by using the Boolean XOR operator.

SRCERASE = &H440328 ' Combines the inverted colors of the destination
rectangle with the colors of the source rectangle by using the Boolean AND
operator.

NOTSRCCOPY = &H330008 ' Copies the inverted source rectangle to the
destination.

NOTSRCERASE = &H1100A6 ' Combines the colors of the source and destination
rectangles by using the Boolean OR operator and then inverts the resultant
color.

MERGECOPY = &HC000CA ' Merges the colors of the source rectangle with the
brush currently selected in hdcDest, by using the Boolean AND operator.

MERGEPAINT = &HBB0226 ' Merges the colors of the inverted source rectangle
with the colors of the destination rectangle by using the Boolean OR
operator.

PATCOPY = &HF00021 ' Copies the brush currently selected in hdcDest, into
the destination bitmap.

PATPAINT = &HFB0A09 ' Combines the colors of the brush currently selected in
hdcDest, with the colors of the inverted source rectangle by using the
Boolean OR operator. The result of this operation is combined with the
colors of the destination rectangle by using the Boolean OR operator.

PATINVERT = &H5A0049 ' Combines the colors of the brush currently selected
in hdcDest, with the colors of the destination rectangle by using the
Boolean XOR operator.

DSTINVERT = &H550009 ' Inverts the destination rectangle.

BLACKNESS = &H42 ' Fills the destination rectangle using the color
associated with index 0 in the physical palette. (This color is black for
the default physical palette.)

WHITENESS = &HFF0062 ' Fills the destination rectangle using the color
associated with index 1 in the physical palette. (This color is white for
the default physical palette.)

NOMIRRORBITMAP = &H80000000 ' Windows 98, Windows 2000: Prevents the bitmap
from being mirrored.

CAPTUREBLT = &H40000000 ' Windows 98, Windows 2000: Includes any windows
that are layered on top of your window in the resulting image. By default,
the image only contains your window.

End Enum
 
Back
Top