Draw Rectangle on top of screen/Desktop

cheng_sh

Freshman
Joined
Feb 18, 2003
Messages
25
Location
KL
Hello everybody,
Is it possible to use VB.NET to draw a Rectangle on top of the screen/desktop? Can somebody teach me how to do that?

Thank you very much.
 
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
Code:
 
No error but just can't see the rectangle that's suppose to be on top of the desktop.

Thank you for your reply.
 
Back
Top