Callback in vb.net

来源:互联网 发布:sass 淘宝镜像 编辑:程序博客网 时间:2024/06/09 21:34
Even though I'm not quite sure as to what the problem exactly is
with your callback function (was not included in your sample code),
here is the complete code for a very simple Visual Basic .NET app,
using two MI OLE callback functions (receiving status text and
custom tool input event notification):

Form1 contains the map window (PictureBox, "pbMap") and a text box
("tbStatus"), displaying the contents of the status line.

''''''''''''' Begin of VBN code '''''''''''''''''''''''''''''''''''

Public Class Form1

     ' The MapInfo OLE object:
     Private mi As Object

     ' The object implementing the COM/OLE2 automation server as
     ' the target of the callbacks originating from the MI OLE object:
     Private comServObj As New ComClass1

     ' A shared object reference to the status text control for
     ' later access within the status text callback function:
     Public Shared tbStatObj As Object

     Public Sub New()

         ' Initialize main form (built with VS Form Designer):
         InitializeComponent()

         ' Save persistent (shared) obj ref to status text control:
         tbStatObj = Me.tbStatus

         ' Create and configure the MI COM object, open a map etc.:
         mi = CType(CreateObject("MapInfo.Application"), MapInfo.DMapInfo)
         mi.do("Set Application Window " & CType(Me.pbMap.Handle, String))
         mi.do("Set Next Document Parent " & CType(Me.pbMap.Handle, String) _
               & " Style 1")
         mi.do("Open Table ""c:/maps/world.tab"" Interactive Map From World")
         mi.Do("Set Map Display Position")
         mi.Do("Create Buttonpad ""SelectGeneric"" As Toolbutton ID 785 " _
               & "DrawMode 34 Cursor 134 Calling OLE ""SelectGeneric""")
         mi.Do("Run Menu Command ID 785")
         mi.SetCallback(comServObj)

     End Sub

End Class


' Register this class as a COM/OLE2 class:
<ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)> _
Public Class ComClass1

     ' Unique IDs for this COM app interface:
     Public Const ClassId As String     =
"9CC9946D-C1E4-4f42-9E8C-C4693BD04577"
     Public Const InterfaceId As String =
"CC6697F7-968D-47dc-9B5B-84DEF8FD5D6B"
     Public Const EventsId As String    =
"2A765F7E-E628-4427-A730-A695543EDB79"

     Public Sub New()
         MyBase.New()
     End Sub

     ' Callback function receiving the contents of the MapInfo status line,
     ' when changed:
     Public Sub SetStatusText(ByVal strStatus As String)
         ' Show status line text in text box:
         CType(Form1.tbStatObj, Control).Text = strStatus
     End Sub

     ' Callback function for notification of user input events
     ' generated by the custom tool (ID 785, see above):
     Public Sub SelectGeneric(ByVal str As String)
         MessageBox.Show("A user input event occurred with the parameters:" _
                          & vbCrLf & str, "MI Custom Tool Callback")
     End Sub

End Class

''''''''''''' End of VBN code '''''''''''''''''''''''''''''''''''
 
原创粉丝点击