MapInfo Pro Developers User Group

Embedding a window in a MapBasic dialog

  • 1.  Embedding a window in a MapBasic dialog

    Posted 11 days ago
      |   view attached
    With the release of the 64-bit versions of MapInfo Pro and so the introduction of the new ribbon and tabbed interface, we also had to say farewell to the former way of dealing with windows. This is especially visible when you want to embed one window in another window or inside a MapBasic dialog.

    You need to do this in a different way now.

    To make it easier for myself and for the other MapBasic users amongst us, I added some new functions to the MapBasic Common Library, more precisely to the WINDOWLib module, which makes it easier to embed a window in a MapBasic dialog.

    Here's a basic example of how to do this. The tool below takes the front window and clones it into a DocumetWindow control in a dialog. The result looks like this:


    1. Download the latest version of the MapBasic Common Library from Github. You can either download it using a zip-file or clone the repository using, for example, the GitHub Desktop tool.

    2. Make sure to include at least the WINDOWLib.def file in your module.
    In my example that has been attached, you'll notice I include a number of other modules:
    Include "Library\DEBUGLib.def"
    Include "Library\ERRORLib.def"
    Include "Library\ProgramInfo.def"
    Include "Library\RIBBONLib.def"
    Include "Library\TABLELib.def"
    Include "Library\WINDOWLib.def"


    I use these for a number of different reasons that might not apply to your use.

    3. In your MapBasic project file, you will also need to include at least the compiled MapBasic object file: WINDOWLib.mbo.

    4. When creating your dialog, you need to include at least one DocumentWindow control and the handler of your dialog needs to call a procedure that will add a window to that control at load time. My example uses the current front window, so I also check that there is a window.

    mnWID = FrontWindow()
    If mnWID = 0 Then
       Note "No window open!"
       Exit Sub
    End If

    Dialog
       Title "Embed Front Window"
       Calling MENUEmbedFrontWindow_OnLoad


       Control DocumentWindow    ID CTRL_DOC_WINDOW
          Position 5,5 Width 300 Height 300

       Control OKButton
       Control CancelButton   


    When the dialog is closed by the user, I check if the window that was embedded has been closed. If that's not the case, I close it myself.

    If WINExists(mnWIDEmbedded) Then
       Close Window mnWIDEmbedded
       mnWIDEmbedded = 0
    End If


    Here is the source code for the dialog handler/procedure that will create and embed a copy of the front window into my dialog:
    mnWIDEmbedded = WINCreateForDocumentControl(CTRL_DOC_WINDOW, WindowInfo(mnWID, WIN_INFO_CLONEWINDOW)) 

    CTRL_DOC_WINDOW is the Control ID of the DocumentWindow control and mnIDEmbedded is a modular variable that holds the Window ID of the embedded window.

    The functions WINCreateForDocumentControl can be found in the WINDOWLib module and is used for creating a new window and embedding it in a DocumentWindow control. It takes two parameters: 1, the ID of the DocumentWindow controls and 2, the MapBasic statement used to create the new window. This statement can be the clone functions of any existing window, a Map Fron statement, a Browse From statement or any other MapBasic statement that will create a new document window.

    You can find the example code attached to this post and you can also find it on GitHub: mbEmbedMapInDialog.

    I hope you found this article useful. If you have any clarifying questions, feel free to post them as comments.

    ------------------------------
    Peter Horsbøll Møller
    Pitney Bowes
    ------------------------------

    Attachment(s)

    zip
    mbEmbedMapInDialog.zip   1.05MB 1 version