Capture the Flag
Coded by Xander Obrzut
Capture the Flag Project Download
VB.NET 2005 Project File
This download link is for the executable and Visual Studio 2005 source code.
It basically reproduces the Ability Tools Screen Magnifier.
Features include;
Capturing the Desktop into a Bitmap
Changing the resolution of the Bitmap
Importing Win32 DLL functions
Utilises gui32.dll
BitBlt : RevokeDC : GetDC
Overrides the form's Paint() and OnPaintBackground() routines.
Source Code
Public Class Form1
' Import the gDI BitBlt function that enables the background of
' the window to be captured
Dim bm As Bitmap = New Bitmap(SystemInformation.VirtualScreen.Width, _
SystemInformation.VirtualScreen.Height)
Private Sub test()
Dim desktopDC As IntPtr = Win32Helper.GetDC(System.IntPtr.Zero)
Dim g As Graphics = Graphics.FromImage(bm)
Dim bmDC As IntPtr = g.GetHdc()
Win32Helper.BitBlt(bmDC, 0, 0, bm.Width, bm.Height, desktopDC, Me.Location.X - 100, Me.Location.Y - 100, 13369376)
Win32Helper.ReleaseDC(System.IntPtr.Zero, desktopDC)
g.ReleaseHdc(bmDC)
g.Dispose()
End Sub
Protected Overrides Sub OnPaintBackground(ByVal e As System.Windows.Forms.PaintEventArgs)
'MyBase.OnPaintBackground(e)
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
'MyBase.OnPaint(e)
test()
bm.SetResolution(50, 50)
e.Graphics.DrawImage(bm, 0, 0)
e.Dispose()
'RaiseEvent Paint(Me, e)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Start()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Invalidate()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.Invalidate()
End Sub
End Class
Public NotInheritable Class Win32Helper
EntryPoint:="BitBlt", _
CallingConvention:=Runtime.InteropServices.CallingConvention.StdCall, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Public Shared Function _
BitBlt(ByVal hdcDest As IntPtr, _
ByVal nXDest As Integer, _
ByVal nYDest As Integer, _
ByVal nWidth As Integer, _
ByVal nHeight As Integer, _
ByVal hdcSrc As IntPtr, _
ByVal nXSrc As Integer, _
ByVal nYSrc As Integer, _
ByVal dwRop As Int32) As Boolean
' Leave function empty
End Function
EntryPoint:="GetDC", _
CallingConvention:=Runtime.InteropServices.CallingConvention.StdCall, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Public Shared Function GetDC(ByVal hWnd As IntPtr) As IntPtr
' Leave function empty
End Function
EntryPoint:="ReleaseDC", _
CallingConvention:=Runtime.InteropServices.CallingConvention.StdCall, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Public Shared Function ReleaseDC(ByVal hWnd As IntPtr, _
ByVal hDC As IntPtr) As Boolean
' Leave function empty
End Function
End Class ' End Win32Helper