I am simply trying to draw a rectangle on the screen, that has some transparency.
I can get this working in VB.NET with the following code
Code: Select all
Public Class Class1
Private Declare Function GetDC Lib "user32.dll" (ByVal hwnd As IntPtr) As IntPtr
Private Declare Function ReleaseDC Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal hdc As IntPtr) As IntPtr
Public Sub ShowBoundary(ByVal X1 As Integer, ByVal Y1 As Integer, ByVal X2 As Integer, ByVal Y2 As Integer)
Dim hdc As IntPtr = GetDC(IntPtr.Zero)
Try
Using g As Graphics = Graphics.FromHdc(hdc)
Using brder As New Pen(Color.Blue)
' Paint boundaries rectangle
Using myBrush As New System.Drawing.SolidBrush(Color.FromArgb(128, System.Drawing.Color.White))
g.FillRectangle(myBrush, New Rectangle(X1, Y1, X2 - X1, Y2 - Y1))
End Using
Using myBrush As New System.Drawing.SolidBrush(Color.FromArgb(128, System.Drawing.Color.Black))
g.FillRectangle(myBrush, New Rectangle(X1 + 1, Y1 + 1, (X2 - X1) - 2, (Y2 - Y1) - 2))
End Using
End Using
End Using
Finally
ReleaseDC(IntPtr.Zero, hdc)
End Try
End Sub
Code: Select all
SRT>DrawRectangle
//DrawRectangle Usage:
//GoSub>DrawRectangle,WindowHandle,PenSize,PenColor,SolidColor,ULXLocation,ULYLocation,LRXLocation,LRYLocation
LibFunc>user32,GetDC,HDC,%DrawRectangle_var_1%
LibFunc>gdi32,CreatePen,Penres,0,%DrawRectangle_var_2%,%DrawRectangle_var_3%
LibFunc>gdi32,SelectObject,SOPres,hdc,Penres
LibFunc>gdi32,CreateSolidBrush,SBres,%DrawRectangle_var_4%
LibFunc>gdi32,SelectObject,SOres,hdc,sbres
LibFunc>gdi32,Rectangle,recres,hdc,%DrawRectangle_var_5%,%DrawRectangle_var_6%,%DrawRectangle_var_7%,%DrawRectangle_var_8%
LibFunc>gdi32,DeleteObject,DOres,Penres
LibFunc>gdi32,DeleteObject,DOres,sbres
LibFunc>user32,ReleaseDC,RDCres,HDC_1,HDC
END>DrawRectangle
Code: Select all
RGB>255,255,255,colWhite
RGB>128,128,128,colGrey
RGB>0,0,0,colBlack
RGB>255,0,0,colRed
Let>OPAQUE=2
Let>TRANSPARENT=1
Let>HS_BDIAGONAL=3
Let>HS_CROSS=4
Let>HS_DIAGCROSS=5
Let>HS_FDIAGONAL=2
Let>HS_HORIZONTAL=0
Let>HS_VERTICAL=1
GoSub>DrawRectangle,0,1,%colWhite%,%colBlack%,10,10,100,100
SRT>DrawRectangle
LibFunc>user32,GetDC,HDC,%DrawRectangle_var_1%
Libfunc>gdi32,SetBkMode,sbmres,hdc,%TRANSPARENT%
LibFunc>gdi32,CreatePen,Penres,0,%DrawRectangle_var_2%,%DrawRectangle_var_3%
LibFunc>gdi32,SelectObject,SOPres,hdc,Penres
LibFunc>gdi32,CreateHatchBrush,SBres,%HS_DIAGCROSS%,%DrawRectangle_var_4%
LibFunc>gdi32,SelectObject,SOres,hdc,sbres
LibFunc>gdi32,Rectangle,recres,hdc,%DrawRectangle_var_5%,%DrawRectangle_var_6%,%DrawRectangle_var_7%,%DrawRectangle_var_8%
LibFunc>gdi32,DeleteObject,DOres,Penres
LibFunc>gdi32,DeleteObject,DOres,sbres
LibFunc>user32,ReleaseDC,RDCres,HDC_1,HDC
END>DrawRectangle
If anyone could point me in the right direction, or code examples of how I might get this implemented, I would be very grateful.
On a sidenote, say I draw a rectangle, what is the best way for me to "erase" the rectangle once I no longer want it present on the screen?
Using this appears to work, but wonder if anyone has a better / alternate option just clear the area the rectangle was drawn on.
Code: Select all
LibFunc>user32,InvalidateRect,invres,0,0,0