
Originally Posted by
Jason
Hmm, did you use the exact code I used as a controlled test? (With a button on the form obviously.)
I sure did! Strange how it didn't work though.
EDIT - Got it working, probably because ScreenDC wasn't declared at the start.
[php]Imports System****ntime.InteropServices
Public Class Form1
#Region "DllImports"
<DllImport("Gdi32.dll")> _
Public Shared Function GetPixel(ByVal hdc As IntPtr, ByVal x As Integer, ByVal y As Integer) As Integer
End Function
<DllImport("Gdi32.dll")> _
Public Shared Function SetPixel(ByVal hdc As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal xColor As Integer) As Integer
End Function
<DllImport("Gdi32.dll")> _
Public Shared Function CreateDC(ByVal driverName As String, ByVal deviceName As String, ByVal output As String, ByVal lpInitData As IntPtr) As IntPtr
End Function
<DllImport("Gdi32.dll")> _
Public Shared Function DeleteDC(ByVal dc As IntPtr) As Boolean
End Function
#End Region
Private ScreenDC As IntPtr = CreateDC("Display", Nothing, Nothing, IntPtr.Zero)
Private midX As Integer = My.Computer.Screen.Bounds.Size.Width / 2
Private midY As Integer = My.Computer.Screen.Bounds.Size.Height / 2
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs)
DeleteDC(ScreenDC)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For i As Integer = midX - 10 To midX + 10
SetPixel(ScreenDC, i, midY, Color.Red.ToArgb)
Next
For x As Integer = midY - 10 To midY + 10
SetPixel(ScreenDC, midX, x, Color.Red.ToArgb)
Next
End Sub
End Class[/php]
The crosshair seems to be in Black and White though.