Can anybody tell me what's wrong with my code here? I try to draw a rectangle on my desktop.
Public Class Win32
Public Declare Function GetDC Lib "user32" (ByVal hwnd As Integer) As Integer
Public Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Public Declare Function GetDesktopWindow Lib "user32" () As Integer
End Class
Sub Main()
Dim rWorkArea As Rectangle
Dim m_graph As Graphics
Dim hwnd As Integer
Dim m_lHwnd As Long
Dim m_lHdc As Integer
hwnd = Win32.GetDesktopWindow
m_lHdc = Win32.GetDC(hwnd)
rWorkArea = Screen.GetWorkingArea(Screen.PrimaryScreen.WorkingArea)
Dim hdc As IntPtr
hdc = IntPtr.op_Explicit(m_lHdc)
m_graph = Graphics.FromHdc(hdc)
Dim redPen As New Pen(Color.Red, 4)
' Draw rectangle with GDI+.
m_graph.DrawRectangle(redPen, rWorkArea)
'm_graph.ReleaseHdc(hdc)
Win32.ReleaseDC(hwnd, m_lHdc)
end sub