MapInfo Pro

 View Only

MapBasic Monday: Introduction to the Tools window

  • 1.  MapBasic Monday: Introduction to the Tools window

    Employee
    Posted 03-06-2023 05:56

    Happy #mapinfomonday 

    Today, we continue our #MapBasicMonday journey of creating a MapBasic application from scratch. In this article, I will show you how to integrate your application nicely into the Tools Window.

    The Tools Window

    You open the Tools Window via the Tool Extensions control on the Home tab. You can also choose to keep it open or autohide depending on how much you use it.

    The Tools Window gives you access to all the currently running tools, all the registered tools, and all the most recently used tools, too. You can access each from the three tabs in the Tools Window.

    We will today focus on the Running tab showing the currently loaded and running tools.

    If you move the mouse over a running tool or click on a running tool, additional controls and text appear. We want our tool to support some of these controls as well.

    There are controls for help, for an about box, and to exit the tool. And there are also texts for the tool name, a descriptive text, and a version as well.

    The controls and text are published from the .NET implementation of the MapBasic application that has been added when we switched to 64-bit, but you can set these values through MapBasic without worrying about the .NET implementation. We will leave that for another day.

    Integrating the tool

    To integrate the tool, we need to add a number of procedures and functions to our tool. MapInfo Pro will pick up these when you load the tool and then show the controls and texts in the Tools window too.

    At the top of my source code, I add the declarations for the procedures and functions that we need.

    Declare Sub Main
    
    '**Procedures and functions for the Tools window
    Declare Sub AddIn_About
    Declare Function AddIn_Name() As String
    Declare Function AddIn_Description() As String
    Declare Function AddIn_Version() As String
    Declare Function AddIn_ImageUri() As String	
    
    '**Custom procedures for opening tables	
    Declare Sub OpenTableCustomers
    Declare Sub OpenTableCatchmentAreas

    As you can see I have added one procedure and four functions. They all start with "AddIn_". There are a few more you can add if you want: A procedure to be called for the Default Command of the application and the text for the Default Command, and a procedure to be called for help.

    The Default Command of an application will get executed when you double-click on a running tool in the Tools Window.

    Let's add the actual implementation of these, too.

    For the About, I'll create a simple dialog that just shows some descriptive text about the tool.

    '******************************************************************
    'Sub AddIn_About: Dialog showing information about the tool
    '******************************************************************
    Sub AddIn_About
    	
    	Note AddIn_Name() & " " & AddIn_Version()
    		& Chr$(10)
    		& Chr$(10) & AddIn_Description()
    	
    End Sub

    Instead of writing the text directly in the procedure here, I will call the functions that also are used in the Tools Window. In this way, the text will be the same in those two places and I also need to keep it updated in one place.

    The function Chr$(10) returns a new line string resulting in the text being split across three lines.

    And now for the three functions returning some specific text about the application.

    '******************************************************************
    'Function AddIn_Name(): Returning the name of the application
    '******************************************************************
    Function AddIn_Name() As String
    
    	AddIn_Name = "EasyOpenTables"
    
    End Function
    	
    '******************************************************************
    'Function AddIn_Description(): 
    '******************************************************************
    Function AddIn_Description() As String
    	
    	AddIn_Description = "This application opens a few tables into the active map with predefined layer and label settings."
    
    End Function
    
    '******************************************************************
    'Function AddIn_Version(): Returning the version of the application
    '******************************************************************
    Function AddIn_Version() As String
    
    	AddIn_Version = "0.4"
    
    End Function

    And now I will implement the final function that will return the icon used next to the tool in the Tools Window.

    '******************************************************************
    'Function AddIn_ImageUri(): Returning the icon for the add-in in the Tools window
    '******************************************************************
    Function AddIn_ImageUri() As String
    
    	AddIn_ImageUri = MI_IMG_APP_OPENWORKSPACE_16  'Consider using _32 for high resolution screens
    
    End Function

    The function returns the 16 by 16 pixel icon also used on the Open Workspace control. MI_IMG_APP_OPENWORKSPACE_32 is a constant defined in the file RibbonControls.def which I included in my source code in an earlier session.

    And that's it.

    When you now compile and load the tool, it looks like this in the Tools Window.

    The dialog shown on the left is shown when you click on the about control on the right side of the application in the Tools Window.

    Stay tuned for more over the coming weeks!



    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------