Bill Thoen wrote:
Using MapBasic, does anyone know if it is possible to create a custom
"mapper shortcut" menu for one map window and a different one for another
map window in the same session?
Well, well... Once again, this list comes up with the answer! Thanks to
Jacques Paris and Steve Nabors for the hints. The trick is to use the
WinFocusChangedHandler() function and rewrite the MapperShortcut menu
(ID 17) depending on whether the focus is in the special window you want
or not. Steve also mentioned that if you push this technique too far
it's not all that stable. But the following scrapplication shows that it
works, and for two windows it looks stable enough (I couldn't break it.)
This creates a simple table and opens two windows. The one with the
yellow rectangle is the special one. Right-click in this one and all you
get is is the Exit option on the flying menu. But right-click on the
green one and you get the normal MapperShortcut menu. Sorry for the lack
of comments, but this is just a study for the real thing later. However,
it works and cleans up after itself.
' SwitchMenu.mb
' Demo showing how to switch mapper shortcut menus on
' the fly for special mappers
Include "MapBasic.def"
Declare Sub Main
Declare Sub MnuExit
Declare Sub WinFocusChangedHandler
Declare Sub OpenMappers
Dim m_nWin As Integer
Sub Main
Create Menu "SwitchMenu" As
"Exit" Calling MnuExit
Alter Menu Bar Add "SwitchMenu"
Set Handler WinFocusChangedHandler Off
Call OpenMappers
Set Handler WinFocusChangedHandler On
End Sub
Sub MnuExit
Drop Table Special
End Program
End Sub
Sub WinFocusChangedHandler
If CommandInfo (CMD_INFO_WIN) = m_nWin Then
Create Menu "MapperShortcut" As
"Exit" Calling MnuExit
Else
Create Menu "MapperShortcut" As Default
End If
End Sub
Sub OpenMappers
Dim objRect As Object
Close All Interactive
Create Table Special (
id Integer
)
File ApplicationDirectory$()+"Special.TAB"
Create Map For Special CoordSys NonEarth Units "in" Bounds (0,0) (10,10)
Set CoordSys Table Special
Create Rect Into Variable objRect
(1,1) (4,4)
Pen (1,2,0)
Brush (2,YELLOW,WHITE)
Insert Into Special (obj, id) Values (objRect, 1)
Create Rect Into Variable objRect
(6,3) (9,6)
Pen (1,2,0)
Brush (2,GREEN,WHITE)
Insert Into Special (obj, id) Values (objRect, 2)
Map From Special
Set Window FrontWindow() Position (0,0) Width 3 Height 3
Set Map Center (2.5,2.5) Zoom 4 Units "in"
m_nWin = FrontWindow() ' Make this the special mapper
Map From Special
Set Window FrontWindow() Position (4.2,1) Width 3 Height 3
Set Map Center (7.5,4.5) Zoom 4 Units "in"
End Sub
_______________________________________________
MapInfo-L mailing list
MapInfo-L@lists.directionsmag.com
http://www.directionsmag.com/mailman/listinfo/mapinfo-l