Implements
MapInfo.MiPro.Samples.IM.ICallbackNotify
' Strings displayed in a combobox, to let the user choose a map tool
Private _mapToolPan As String = "Pan"
' Id of the map window being reparented
Public _mapWindowId As String = ""
' HWND of the window being reparented
Private _hWnd As System.IntPtr
' Mapping of map tool names to tool command ids
Private _toolIdMap As Dictionary(Of String, Integer)
'ID of the custom OLE menu item on the map window's context menu
Private Const _customItemId As UInteger = 10000
' Reference to the callbackobject
Private _callbackObject As MapInfo.MiPro.Samples.IM.MapInfoCallBack
' Store a reference to MapInfo Professional's COM interface
Public _mapInfoApp As MapInfoApplication
Private Sub InitializeComObject()
Dim cmd As String = String.Format("Set Application Window {0}", Me.Handle)
' Create the MapInfo Professional object
_mapInfoApp =
New MapInfoApplication()
' Set parent window for MapInfo Professional dialogs
_mapInfoApp.Do(cmd)
' Create the callback object
_callbackObject =
New MapInfo.MiPro.Samples.IM.MapInfoCallBack(Me)
' Register the callback object with MapInfo Professional
_mapInfoApp.RegisterCallback(_callbackObject)
End Sub
Private
Sub MapForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Create an instance of MapInfo Professional, silently/hidden
InitializeComObject()
' Add a custom item to the map window's context menu
AddMapperShortcutMenuitem()
Dim WorkSpace1 As String = "D:\MapData\MyWorkSpace.WOR"
Dim cmd1 As String
cmd1 =
String.Format("Set application window {0}", Me.Handle)
MapInfoApp.Do(cmd1)
cmd1 =
String.Format("Set Next Document Parent {0} Style 1", Me.MapPanel.Handle)
MapInfoApp.Do(cmd1)
MapInfoApp.Do(
"Run application " & Chr(34) & WorkSpace1 & Chr(34))
'D:\MB115_NEW\HillsMapData\HILLS_AVL.WOR
_mapWindowId = MapInfoApp.Eval(
"WindowID(0)")
' MapInfoApp.Do("Run application " & Chr(34) & "D:\KEITHSOURCE\SAM_Sample\keithtest.mbx" & Chr(34))
' Call WindowInfo with 12 (WIN_INFO_WND) to get the Windows HWND.
' If the user resizes the form, we need the HWND to update the map size.
Dim hWnd As Long = Long.Parse(_mapInfoApp.Eval("WindowInfo(FrontWindow(),12)"))
_hWnd =
New System.IntPtr(hWnd)
End Sub
Keithit would be easier to use a VB.net tool bar and call the mapinfo functions from theirthe way your trying to do this will will be very hard.
Actually the buttons on the right side are a vb.net ToolStrip and ToolStripButtons(i had to make screen captures and clean up color for the images you see on the buttons). I am making pretty good progress with the app. I have had to press on about the ruler. However, I saw where someone said to get the ruler to appear is to make it the child of a newly added in form. Actually that was not necessary, I actually did the following and when the user tabs from this app to another, the ruler window goes with it, where as before it was behaving like a totally separate app. The code is as follows.
Dim cmd1 As String = String.Format("Run Menu Command {0}", commandId)
_mapInfoApp.Do(cmd1)
Dim msg As String
msg =
"Set Window Ruler Parent " & Me.MapPanel.Handle.ToString
_mapInfoApp.Do(msg)
Dim hwnd As Integer
hwnd = MapInfoApp.Eval(
"windowinfo(1007,12)")
SetParent(hwnd,
It seems as though MapInfo does a pretty good job of hiding the actual mouse clicks in their map window. In MapBasic, if a person makes a custom tool using the DM_CUSTOM_POLYLINE the xy's and developing object can not be analyzed until the drawer has completed drawing the polyline. It seems the only way to terminate this style tool is to double click at the end of drawing unlike the standard polyline tool.
Include "icons.def"
Include "mapbasic.def"
Declare Sub Main
Declare Sub draw_via_button
Sub Main
Create ButtonPad "Custom" As
ToolButton
Icon MI_ICON_LINE
DrawMode DM_CUSTOM_POLYLINE
Cursor MI_CURSOR_CROSSHAIR
ModifierKeys On
Calling draw_via_button
HelpMsg "Draws a polyline on a Map window\nDraw Line"
Show
End Sub
Sub draw_via_button
Dim x1, y1,x2, y2 As Float
If WindowInfo(FrontWindow(),WIN_INFO_TYPE) <> WIN_MAPPER Then
Note "This tool may only be used on a Map window. Sorry!"
Exit Sub
End If
Dim Pobj1 as object
Pobj1=CommandInfo(CMD_INFO_CUSTOM_OBJ)
Dim Pobj2 as object
alter object Pobj1 info OBJ_INFO_PEN,MAKEPEN(2,255,3)
dim i as integer
for i =1 to objectinfo(Pobj1,obj_info_npnts)
print format$(objectnodeX(Pobj1,1,i),"00.000000")
print format$(objectnodeY(Pobj1,1,i),"00.000000")
insert into cosmetic1(obj) values (Createpoint(objectnodeX(Pobj1,1,i), objectnodeY(Pobj1,1,i)))
next
insert into cosmetic1(obj) values (Pobj1)
end sub
"Set Window Ruler Parent " & Me.Handle.ToString (Me.MapPanel.Handle.ToString is incorrect)
_mapInfoApp.Do(msg)
you need to control mapinfo from VB.net the problem with integrated mapping is that windows 7 is a multi thread operation system and mapinfo is an outdated 32 bit windows App they just don't play nice
I have been using two different windows 7 machines one 64 and one 32. Currently using the integrated mapping where I just use a map window from MI Pro. I can check to see if a particular layer is in the map, if not I see if it is on the hard drive, if not I create it. Either way the window ID for the map window is used several times without issue. As soon as I try to add the Layer to the Map window using (vb.net/mapbasic syntax Do and EVal of course) I get a COM/Hresult error complaining that it is the wrong Window ID. This darn window id is used repeatedly prior to trying to add the layer. I can even right click and add the newly created mappable table to the map window. But programmatically MI Pro complains about the darn window ID. I even tried using the Frontwindow() command to no avail. I even copied the syntax for the statement to the mapbasic window with the full blown mi pro open and it worked. Unbelievable. I have not given up yet. I will persist and the software will abide.
In MapInfo Pro. If there is only one map window open. I used the:
Add map auto layer "MyLayer"
Okay i got it to work by not subbing it out. most of this all happens in the MapForm Load event(but i like to sub what I can).
Public Sub AddMapLayer(ByVal MIobj1 As Object, ByVal TabLayer1 As String, ByVal MapWinID1 As Integer)
'I tried this
Dim cmd1 As String = "Add Map Auto Layer " + TabLayer1
and i tried this
cmd1 =
"Add Map Window " & MapWinID1.ToString & " Layer " + TabLayer1
MIobj1.do(cmd1)
End Sub
'This checks existence, opens if it does, creates it if it does not.
Call MakeCrumbTrail(MapInfoApp, WorPath1)
======This works in the form load event=====
_mapInfoApp.Do(
"Add Map Window " + _mapWindowId.ToString + " Layer crumbtrail")
and remmed out this
====this does not work in a call from the form load====
'Call AddMapLayer(MIObj1, CTTab1, mapwindid)
Public Function Create_Map_ScamCodes(ByVal tablename As String, ByVal filename As String) As IntegerDim MSG As String
tablename = tablename.Replace(" ", "_")MSG = "Create Table " & Chr(34) & tablename & Chr(34) & " (Long Float,Lat Float,ScrambleCode Integer,Carrier Char(40),DeviceName Char(100)) file " _
& Chr(34) & filename & Chr(34) & " TYPE NATIVE Charset " & Chr(34) & "WindowsLatin1" & Chr(34)
mapinfo.do(MSG)
MSG = "Create Map For " & tablename & " CoordSys Earth Projection 1, 0"
mapinfo.do(MSG)
MSG = "Map From " & tablename
mapinfo.do(MSG)
MSG = "Set Map Layer 1 Editable On"
mapinfo.do(MSG)
Return Val(mapinfo.eval("frontwindow()"))
End Function
Public Function Create_BCCH(ByVal row As Double, ByVal mapinfo_window_ID As Integer, ByVal tablename As String, ByVal pointcolor As Color, ByVal Code As Integer, ByVal count As Integer, ByVal other As Boolean) As DoubleDim msg As String
tablename = tablename.Replace(" ", "_")
msg = "Set Style Font Makefont(""Arial"", 1, 30, " & pointcolor.ToArgb & "," & Color.White.ToArgb() & ") "
mapinfo.do(msg)
msg = "Insert Into " & tablename & "(obj) Values ( CreateText ( " & mapinfo_window_ID & ", -0.1," & row & "," & Chr(34) & Chr(149) & Chr(34) & ",0,5,0))"
mapinfo.do(msg)
msg = "Set Style Font Makefont(""Arial"", 1, 12, " & Color.Black.ToArgb() & "," & Color.White.ToArgb() & ") "
mapinfo.do(msg)
msg = "Insert Into " & tablename & "(obj) Values ( CreateText ( " & mapinfo_window_ID & ", -0.1," & row & "," & Chr(34) & Code & " BCCH ( " & count & " ) " & Chr(34) & ",0,5,15))"
mapinfo.do(msg)
row = row - 0.1
Return row
End Function
the mapinfo object is defined on the main form. I have added a module with multiple subs. there is a timer with an ontimed event. During the ontimedevent I attempt to insert something into mapinfo table, however I do not believe the OnTimedEvent knows what the MapInfoApp object is. It is really not clear to me how one makes all public variables available for additional modules. I suppose I could take the contents of the module and put in the code for the form. That is a lot of code on one form. Any thoughts would be appreciated.
make 1 form that handle all of you mapinfo controls trying to pass the mapinfo object will not work
Okay that did the trick. All of the code is now with the form code. The mapinfo object is now well known through out.