Using the Magnifying Glass (Visual Basic)
Take the following steps to enable the generation of the MagGlassExt event and update the zoomed image using the LEADTOOLS Internet toolkit.
1. |
Start Visual Basic. Select Standard EXE and click Open. |
2. |
Add the LEAD RasterView Control (14.5) to your project. |
|
On the Project pull-down menu, use the Components option, and select the LEAD RasterView Control (14.5). |
3. |
Add the LEAD Raster Internet Object Library (14.5) to your project. |
|
On the Project pull-down menu, use the References option, and select the LEAD Raster Internet Object Library (14.5). |
4. |
Add the LEAD Raster Object Library and LEAD Raster Variant Object Library to your project |
|
On the Project pull-down menu, use the References option, and select the LEAD Raster Object Library (14.5). |
|
On the Project pull-down menu, use the References option, and select the LEAD Raster Variant Object Library (14.5). |
5. |
Add the LEAD RasterIO Object Library to your project.. |
|
On the Project pull-down menu, use the References option, and select the LEAD RasterIO Object Library (14.5). |
6. |
Select the LEAD RasterView control; then add the control to your main form. Size and position the control as you want it to appear at run time. |
7. |
Add seven command buttons to your main form and name them as follows: |
|
Name |
Caption |
|
StartUpServer |
Start Up Server |
|
ShutDownServer |
Shut Server Down |
|
ConnectToRemoteServer |
Connect To Remote Server |
|
DisconnectFromRemoteServer |
Disconnect From Remote Server |
|
LoadRemoteImage |
Load Remote Image |
|
StartMagnifyingGlass |
Start Magnifying Glass |
|
StopMagnifyingGlass |
Stop Magnifying Glass |
8. |
Add a Text box to your main form and name it as follows: |
|
|
Name |
|
|
RemoteComputer. |
|
9. |
Set the Text property to the name of the computer you will use as a server, or set it to 10.0.32.241. |
|
10. |
Define the following global variables: |
Dim hServer As Integer ' handle to server
Dim gnCommandID As Long
Dim bMagGlass As Boolean
Public WithEvents RasterIO As LEADRasterIO
Public WithEvents LEADNet1 As LEADRasterInet
11. |
Add the following initialization code to the main form's Load procedure. In online help, you can use the Edit pull-down menu to copy the block of code. |
Private Sub Form_Load()
Dim Factory As New LEADRasterFactory
Dim LEADRaster As LEADRaster
Dim szLic As String
' Initialize some variables
hServer = 0
gnCommandID = 0
bMagGlass = False
' Set defaults for displaying the image.
' These are all persistent properties that can be set in the properties box.
LEADRasterView1.Appearance = APPEARANCE_FLAT
LEADRasterView1.BorderStyle = 1
LEADRasterView1.BackColor = RGB(255, 255, 125)
LEADRasterView1.PaintDither = PAINTDITHER_DIFFUSION
LEADRasterView1.PaintPalette = PAINTPALETTE_AUTO
LEADRasterView1.AutoRepaint = True
LEADRasterView1.AutoSize = False
LEADRasterView1.AutoSetRects = True
LEADRasterView1.PaintSizeMode = PAINTSIZEMODE_FIT
' Create the Raster IO and Raster Inet objects
Set RasterIO = CreateObject("LEADRasterIO.LEADRasterIO")
Set LEADNet1 = CreateObject("LEADRasterInet.LEADRasterInet")
' Create a temp LEADRaster object and use it
' to unlock support for the Inet object
szLic = "LEADTOOLS OCX Copyright (c) 1991-2005 LEAD Technologies, Inc."
Set LEADRaster = Factory.CreateObject("LEADRaster.LEADRaster", szLic)
LEADRaster.UnlockSupport L_SUPPORT_INTERNET, "TestKey"
' Stop generation of runtime exceptions for LEAD RasterView Control, LEAD
' RasterIO Object Library and LEAD Raster Internet Object Library.
LEADRasterView1.EnableMethodErrors = False
RasterIO.EnableMethodErrors = False
LEADNet1.EnableMethodErrors = False
End Sub
12. |
Code the main form's Form_Unload procedure as follows: |
Private Sub Form_Unload(Cancel As Integer)
Dim i As Integer
Dim num As Integer
' Disconnect all connections
num = LEADNet1.ConnectListNum
For i = 0 To LEADNet1.ConnectListNum - 1
LEADNet1.InetDisconnect LEADNet1.ConnectList(i)
Next i
If bMagGlass Then
LEADRasterView1.StopMagGlass
End If
End Sub
13. |
Code the StartUpServer button's click procedure as follows: |
Private Sub StartUpServer_Click()
Dim nRet As Integer
' Initialize server on port 1000
nRet = LEADNet1.InetServerInit( 1000)
HServer = LEADNet1.InetServerHandle
If nRet <> 0 Then
MsgBox "Error Initializing server: " + CStr(nRet)
End If
End Sub
14. |
Code the ShutDownServer button's click procedure as follows: |
Private Sub ShutDownServer_Click()
Dim nRet As Integer
If hServer <> 0 Then
nRet = LEADNet1.InetServerClose(hServer)
If nRet <> 0 Then
MsgBox "Error Shutting Down server: " + CStr(nRet)
Else
hServer = 0
End If
End If
End Sub
15. |
Code the LEADNet1_InetAccept event as follows: |
Private Sub LEADNet1_InetAccept(ByVal iServer As Integer)
Dim hComputer As Integer
Dim hName As String
nRet = LEADNet1.InetAcceptConnect(hServer)
hComputer = LEADNet1.InetConnectedComputer
If nRet <> 0 Then
MsgBox "Error accepting connection: " + CStr(nRet)
Exit Sub
End If
LEADNet1.InetGetHostName hComputer, HOST_NAME_DESCRP
hName = LEADNet1.InetHostName
' Add to our list
LEADNet1.SendList(LEADNet1.SendListNum) = hComputer
MsgBox "Connection accepted from: " + hName
End Sub
16. |
Code the ConnectToRemoteServer button's click procedure as follows: |
Private Sub ConnectToRemoteServer_Click()
Dim nRet As Integer
' Connect to remote computer on port 1000
nRet = LEADNet1.InetConnect(RemoteComputer.Text, 1000)
If nRet <> 0 Then
MsgBox "Error connecting to " + RemoteComputer.Text + ": " + CStr(nRet)
End If
End Sub
17. |
Code the DisconnectFromRemoteServer button's click procedure as follows: |
Private Sub DisconnectFromRemoteServer_Click()
Dim nRet As Integer
' We are assuming only one connection in this example.
' Therefore, the handle to the remote computer will be
' in the first position in the SendList
nRet = LEADNet1.InetDisconnect(LEADNet1.SendList(0))
If nRet <> 0 Then
MsgBox "Error disconnecting from remote: " + CStr(nRet)
End If
End Sub
18. |
Code the LEADNet1_InetConnected event as follows: |
Private Sub LEADNet1_InetConnected(ByVal iComputer As Integer)
Dim sRemote As String
' Get remote host name
LEADNet1.InetGetHostName iComputer, HOST_NAME_DESCRP
SRemote = LEADNet1.InetHostName
' Add this connection to our SendList
LEADNet1.SendList(LEADNet1.SendListNum) = iComputer
MsgBox "Successfully connected to remote computer: " + sRemote
End Sub
19. |
Code the LEADNet1_InetDisconnected event as follows: |
Private Sub LEADNet1_InetDisconnected(ByVal iComputer As Integer)
If hServer = 0 Then
MsgBox "Disconnect from remote server"
Else
MsgBox "Connection to remote computer closed"
End If
End Sub
20. |
Code the LoadRemoteImage button's click procedure as follows: |
Private Sub LoadRemoteImage_Click()
Dim nRet As Integer
nRet = LEADNet1.InetSendLoadCmd(999, "v:\images\eagle.cmp", 0, 1)
If ((nRet <> 0) And (nRet <> ERROR_DATA_QUEUED)) Then
MsgBox "ERROR " & CStr(nRet) & " calling InetSendLoadCmd."
End If
End Sub
21. |
Code the StartMagnifyingGlass button's click procedure as follows: |
Private Sub StartMagnifyingGlass_Click()
Dim nRet As Integer
If LEADRasterView1.Raster.Bitmap <> 0 And hServer = 0 Then
' Enable MagGlassExt event.
If LEADRasterView1.EnableMagGlassEvent = False Then
LEADRasterView1.EnableMagGlassEvent = True
End If
LEADRasterView1.RgnFrameType = 0
' Start the Magnifying Glass
nRet = LEADRasterView1.StartMagGlass(100, 100, 400, RGB(255, 0, 0), RGB(128, 128, 128), True, 1, False, CROSSHAIR_FINE, True, True)
If nRet = 0 Then
bMagGlass = True
End If
End If
End Sub
22. |
Code the StopMagnifyingGlass button's click procedure as follows: |
Private Sub StopMagnifyingGlass_Click()
Dim nRet As Integer
If LEADRasterView1.Raster.Bitmap <> 0 And hServer = 0 Then
nRet = LEADRasterView1.StopMagGlass
If nRet = 0 Then
bMagGlass = False
End If
End If
End Sub
23. |
Code the LEADRasterView1_MagGlassExt event as follows: |
Private Sub LEADRasterView1_MagGlassExt(ByVal nMaskPlaneStart As Long, ByVal nMaskPlaneEnd As Long, ByVal vMaskPlane As LEADRasterVariant)
Dim nRet As Integer
gnCommandID = gnCommandID + 1
nRet = LEADNet1.InetSendGetMagGlassDataCmd(gnCommandID, 0, (vMaskPlane), nMaskPlaneStart, nMaskPlaneEnd)
If ((nRet <> 0) And (nRet <> ERROR_DATA_QUEUED)) Then
MsgBox "ERROR " & CStr(nRet) & " calling InetSendGetMagGlassDataCmd."
End If
End Sub
24. |
Code the LEADNet1_InetReceiveCmd event as follows: |
Private Sub LEADNet1_InetReceiveCmd(ByVal iComputer As Integer, ByVal InetCommand As Integer, ByVal nCommandID As Long, ByVal nError As Integer, ByVal Params As LEADRasterInetLib.ILEADRasterInetPacket, ByVal nExtraDataSize As Long, ByVal ExtraData As LEADRasterVariant)
Dim nStatus As Integer
Dim vColorBuffer As LEADRasterVariant
nStatus = ERROR_FEATURE_NOT_SUPPORTED
If (nError <> 0) Then
nStatus = ERROR_TRANSFER_ABORTED
Else
Select Case InetCommand
Case INETCMD_LOAD
' check the validity of the parameters
If ((Params.ParamCount = 4) And (Params.ParamType(0) = PARAM_TYPE_STRING) And (Params.ParamType(1) = PARAM_TYPE_INT32) And (Params.ParamType(2) = PARAM_TYPE_INT32) And (Params.ParamType(3) = PARAM_TYPE_UINT32)) Then
nStatus = RasterIO.Load(LEADRasterView1.Raster, Params.ParamValue(0).StringValue, Params.ParamValue(1).LongValue, 1, 1)
If nStatus <> 0 Then
MsgBox "Load Bitmap failed with error code: " & CStr(nRet)
Else
nStatus = LEADNet1.InetSendBitmap(LEADRasterView1.Raster, FILE_CMP, 0, QFACTOR_PQ2)
If nStatus <> 0 Then
MsgBox "SendBitmap failed with error code: " & CStr(nRet)
End If
End If
Else
nStatus = ERROR_INV_PARAMETER ' Invalid parameters
End If
LEADNet1.InetSendLoadRsp nCommandID, 0, 0, Null, nStatus
Exit Sub
Case INETCMD_GET_MAGGLASS_DATA
' check the validity of the parameters
If ((Params.ParamCount = 5) And (Params.ParamType(0) = PARAM_TYPE_UINT32) _
And (Params.ParamType(1) = PARAM_TYPE_UINT32) And (Params.ParamType(2) = PARAM_TYPE_USTRING) _
And (Params.ParamType(3) = PARAM_TYPE_INT32) And (Params.ParamType(4) = PARAM_TYPE_INT32)) Then
If LEADRasterView1.Raster.Bitmap <> 0 Then
nStatus = LEADNet1.InetGetMagGlassData(LEADRasterView1.Raster, vColorBuffer, Params.ParamValue(2).StringValue, Params.ParamValue(3).LongValue, Params.ParamValue(4).LongValue)
If nStatus <> 0 Then
MsgBox "InetGetMagGlassData failed with error code: " & CStr(nStatus)
End If
Else
nStatus = ERROR_INV_PARAMETER ' Invalid parameter
End If
Else
nStatus = ERROR_INV_PARAMETER ' Invalid parameters
End If
LEADNet1.InetSendGetMagGlassDataRsp nCommandID, vColorBuffer.StringValue, Params.ParamValue(2).StringValue, Params.ParamValue(3).LongValue, Params.ParamValue(4).LongValue, 0, Null, nStatus
Exit Sub
End Select
End If
LEADNet1.InetSendRsp InetCommand, nCommandID, Nothing, 0, Null, nStatus
End Sub
25. |
Code the LEADNet1_InetReceiveRsp event as follows: |
Private Sub LEADNet1_InetReceiveRsp(ByVal iComputer As Integer, ByVal InetCommand As Integer, ByVal nCommandID As Long, ByVal nError As Integer, ByVal nStatus As Integer, ByVal Params As LEADRasterInetLib.ILEADRasterInetPacket, ByVal nExtraDataSize As Long, ByVal ExtraData As Variant)
Dim nRet As Integer
If (nError <> 0) Then Exit Sub
Select Case InetCommand
Case INETCMD_LOAD:
If nStatus <> 0 Then
MsgBox "Load failed with error code: " + CStr(nStatus)
End If
Case INETCMD_GET_MAGGLASS_DATA
If (nStatus = 0) Then
If ((Params.ParamCount = 6) And (Params.ParamType(0) = PARAM_TYPE_UINT32) _
And (Params.ParamType(1) = PARAM_TYPE_USTRING) And (Params.ParamType(2) = PARAM_TYPE_UINT32) _
And (Params.ParamType(3) = PARAM_TYPE_USTRING) And (Params.ParamType(4) = PARAM_TYPE_INT32)) _
And (Params.ParamType(5) = PARAM_TYPE_INT32) Then
nRet = LEADRasterView1.UpdateMagGlass(CVar(Params.ParamValue(1)), CVar(Params.ParamValue(3)), Params.ParamValue(4), Params.ParamValue(5), True)
If (nRet <> 0) Then
MsgBox "UpdateMagGlass failed with error code: " & CStr(nRet)
End If
Else
MsgBox "Invalid parameter passed to INETCMD_GET_MAGGLASS_DATA response"
End If
Else
MsgBox "Get MagGlass Data from server with error code " & CStr(nStatus)
End If
End Select
End Sub
26. |
Code the LEADNet1_InetReceiveBitmap event as follows: |
Private Sub LEADNet1_InetReceiveBitmap(ByVal iComputer As Integer, ByVal hBitmap As Long)
LEADRasterView1.Raster.Bitmap = hBitmap
End Sub
27. |
On the main menu, select File > Make .exe, specify a path for the exe file then press OK. |
28. |
Run the exe file two times to execute two applications. |
29. |
In the first application press Start Up Server button. |
30. |
In the second application fill the edit box with the IP address of the remote computer on which you started the first application as a server. Then, press the Connect To Remote Server button to connect to the specified address. |
31. |
Next, press the Load Remote Image button of application number two to load an image on the server. Then press the Start Magnifying Glass button to start the Magnifying Glass with Internet support. Press the left mouse button and move over the image to see the zoomed area using the Magnifying Glass with Internet support. |