PDA

View Full Version : I want to draw a overlay circle not in solid



Unregistered
March 3, 2004, 17:35:32
How to draw a circle in overlay without solid ??

Stefan Geissler
March 4, 2004, 07:49:59
First of all, some GDI functions have to be declared:


Private Declare Function CreatePen Lib "gdi32.dll" _
(ByVal penstyle As Integer, _
ByVal Width As Integer, _
ByVal Color As Long) As Long

Private Declare Function Ellipse Lib "gdi32.dll" ( _
ByVal hDC As Long, _
ByVal nLeftRect As Long, _
ByVal nTopRect As Long, _
ByVal nRightRect As Long, _
ByVal nBottomRect As Long _
) As Boolean


Private Declare Function DeleteObject Lib "gdi32.dll" _
(ByVal handle As Long) As Boolean


Now, we can use these function to draw an ellipse. (For circles and arcs
refer to the MSD library.

Private Sub DrawCircle()
Dim hDC As Long
Dim hPen As Long

With ICImagingControl1.OverlayBitmap
' Get the device context of the overlay bitmap object.
hDC = .GetDC
hPen = CreatePen(1, 1, RGB(255, 100, 100))
SelectObject hDC, hPen
' Draw a filled ellipse (circle) with the current selected pen.
Ellipse hDC, 30, 30, 100, 100

DeleteObject hPen
End With
End Sub

For drawing a non filled circle, use the following code:
//Draw an arc
MoveToEx(hDC,200,100,NULL);
AngleArc( hDC, 200,100,50,0,360);

These functios must be delcared from the GDI32.DLL

For using GDI functions, you need to query the device context (HDC) of the bitmap overlay object.
You can find resources on graphics programming with GDI on http://www.codeguru.com.

Amtec
April 6, 2004, 18:22:47
I have to been trying to draw an 'empty' circle using the suggested...

MoveToEx(hDC,200,100,NULL);
AngleArc( hDC, 200,100,50,0,360);

Unfortunatly I have been unable to get VB to accept these functions, even if I remove the () and ; as the NULL seems to be unacceptable.

Could you advise me as to what I am doing wrong or if there is an alternative method for drawing circles etc

Many thanks

Steve Hobson

Johannes Vogel
April 7, 2004, 16:45:07
Hello,

One additional GDI function has to be delcared in the following way:

Private Declare Function GetStockObject Lib "gdi32.dll" (ByVal obj As Long) As Long


The drawing code should look like this

With ob
' Get the device context of the overlay bitmap object.
hDC = .GetDC

' Solid, light red pen, width 1
hPen = CreatePen(0, 1, RGB(255, 100, 100))
SelectObject hDC, hPen
' 5 is NULL_BRUSH, that is empty
hBrush = GetStockObject(5)
SelectObject hDC, hBrush
' Draw empty ellipse
Ellipse hDC, 30, 30, 100, 100
DeleteObject hPen
End With

Stefan Geissler
April 13, 2004, 07:42:11
Hello,

The functions MoveToEx() and AngleArc() must be declared in the same way as the functions CreatePen() etc.


Private Declare Function MoveToEx Lib "gdi32.dll" ( _
ByVal hDC As Long, _
ByVal X As Long, _
ByVal Y As Long, _
ByVal lpPoint As Long, _
) As Boolean

Private Declare Function AngleArc Lib "gdi32.dll" ( _
ByVal hDC As Long, _
ByVal X As Long, _
ByVal Y As Long, _
ByVal Radius As Long, _
ByVal StartAngle As Single, _
ByVal SweepAngle As Single, _
) As Boolean


I did not test, whether the type "Single" is ok for the C type "float". If you get errors, try "Double" instead of "Single".