Using the Magnifying Glass (Visual Basic)

1. Start Visual Basic and create a new VB6 application.

2. Add the LEAD Main ActiveX Control to your project, then add the control to your main form. Size and position the control as you want it to appear at run time.

3. Add two command buttons to your main form:

Name

Caption

Button1

Start MagGlass

Button 2

Stop MagGlass

4.. Declare the following global variables:

Dim nRet As Integer

Dim bMagGlass As Boolean

5. Add the following initialization code to the main form's Load procedure (Form_Load).

Private Sub Form_Load()
    ' Initialize some variables
   bMagGlass = False
   LEAD1.AutoPan = False


    'Set defaults for displaying the image.
    'These are all persistent properties that can be set in the properties box.
    LEAD1.Appearance = APPEARANCE_FLAT
    LEAD1.BorderStyle = 1
    LEAD1.BackColor = RGB(255, 255, 125)
    LEAD1.PaintDither = PAINTDITHER_DIFFUSION
    LEAD1.PaintPalette = PAINTPALETTE_AUTO
    LEAD1.AutoRepaint = True
    LEAD1.AutoSize = False
    LEAD1.AutoSetRects = True
    LEAD1.PaintSizeMode = PAINTSIZEMODE_FIT
    
   'Load an image

    LEAD1.Load "c:\test.bmp", 0, 1, 1
End Sub

6.   Add the following code to the Form_Unload procedure:

Private Sub Form_Unload(Cancel As Integer)
    If bMagGlass Then
        LEAD1.StopMagGlass 
    End If 
End Sub

7. Add this code to Button1_Click:

Private Sub Command1_Click()
Dim hRGN As Long
Dim xCenter As Single
Dim yCenter As Single

LEAD1.RgnFrameType = RGNFRAME_NONE
hRGN = LEAD1.GetRgnHandle
xCenter = LEAD1.RgnLeft + LEAD1.RgnWidth / 2
yCenter = LEAD1.RgnTop + LEAD1.RgnHeight / 2
LEAD1.SetRgnHandle hRGN, xCenter - LEAD1.BitmapWidth / 2, yCenter - LEAD1.BitmapHeight / 2, L_RGN_SET
LEAD1.DeleteRgnHandle (hRGN)

' Start the Magnifying Glass
nRet = LEAD1.StartMagGlass(150, 100, 200, vbBlack, LEAD1.BackColor, False, 1, True, CROSSHAIR_FINE, True, True)
bMagGlass = True
End Sub

8. Add this code to Button2_Click:

Private Sub Command2_Click()

'Stop the MagGlass

   If LEAD1.Bitmap <> 0 Then

      nRet = LEAD1.StopMagGlass

      If nRet = 0 Then

         bMagGlass = False

      End If

   End If
End Sub