On this page you will find some MapBasic code samples, both the program source and the compiled application. Everything on this page is offered "as is" without warranty of any kind, either expressed or implied, including limitation warranties of merchantability, fitness for a particular purpose, and noninfringement.
Unless otherwise stated MapBasic 9.0 has been used to compile the files - this means that the MBXs offered here will only run with MapInfo Professional 9.0 or higher. If you want to use the tools with another (an older) version of MapInfo Professional, you will have to compile the tool using the relevant version of the Mapbasic compiler.
The goal of this project is to provide some examples of how to use certain MapBasic functionality - not to offer full-blown applications. The applications below each focus on one 'trick'. You can study the source, modify it to suit your needs and implement it in your own apps.
The following code samples are available here:
C# Sample Code - convert a Date value to a Long Date string
Context Menu Sample Code - add a new menu item to a context menu
CreatePoint Sample Code - import a txt file and create points in one step
Custom Functions - create a custom function in MapBasic
Date Functions Sample Code - use Date functions in SQL Statements
DrawMode DM_CUSTOM_POLYGON Sample Code - a ToolButton to create custom polygons
EventHandler Sample Code - use the event handlers WinFocusChangedHandler and WinClosedHandler
Layout Sample Code - use the Layout statement in your MapBasic application
Modular Programming Sample Code - an example on how to set up your own project
MultiListBox Sample Code - use a MultiListBox control in your MapBasic application
SearchPoint Sample Code - use the SearchPoint() and SearchInfo() function in your MapBasic application
Thematic Mapping Sample Code - use MapBasic to create a ranged thematic map
|This application demonstrates how to use the event handlers WinFocusChangedHandler and WinClosedHandler.
The My Own Toolbutton Button on the EventHandler Toolbar will be enabled or disabled, depending on whether a Map Window has the focus or not.
|Please see the file below for EventHandler.MB and EventHandler.MBX.|
In the application a custom toolbar button and a custom cursor is used. This button and cursor are stored in the file Bird.dll (included in the zip file).
The file Bird.dll has been created with Pelles C. In this document you will find a step by step description on how to do this: from creating a new DLL from scratch, store bitmaps in it and call it from your MapBasic application.
The WinFocusChangedHandler procdure is a reserved procedure, called automatically when the window focus changes.
The WinClosedHandler procedure is a reserved procedure, called automatically when a Map, Browse, Graph, Layout, Redistricting, or MapBasic window is closed.
More code samples will follow...;-)