MapInfo Pro Developers User Group

Welcome to the MapInfo Pro Developers community!  We are a group dedicated to the discussion and understanding of MapBasic and .Net MapInfoPro AddIn development. Bring your questions and ideas here. This group includes several members of the Pro development team from around the world.

Please feel free to start a discussion in the discussion tab or join in a conversation.

Product Information  Ideas Portal  MapInfo Community Downloads

Discussions

Members

Resources

Events

 View Only
  • 1.  I am stuck creating a button in Ribbon

    Posted 10-26-2017 01:43

    Hello all,

    I am reading the documents "How to customize the mapinfo pro ribbon interface" and "Porting simple applications to the ribbon interface using mapbasic"

     

    My code (below) does not work. It creates a tab, a tab group and a button, but when I click on the button, nothing happens.

     

    'Ribbon

    Include "mapbasic.def"

    Include "IMapInfoPro.def"

    Include "Enums.def"

     

    Declare Sub Main

    Declare Sub Button1Sub

     

    Sub Main

    Dim mapinfoApplication As This

    Dim Ribbon As This

    Dim RibbonTabColl As This

    Dim RibbonTab As This

    Dim ribbonGroupsColl As This

    Dim ribbonGroup As This

    Dim groupControlColl As This

    Dim button1 As This

     

    mapinfoApplication = SystemInfo(SYS_INFO_IMAPINFOAPPLICATION)

    Ribbon = GetRibbon(mapinfoApplication)

    RibbonTabColl = GetTabsColl(Ribbon)

    RibbonTab = RbnTabCollAddStrStr(RibbonTabColl,"TabID","Tab Name")

    ribbonGroupsColl = GetRbnTabGrps(RibbonTab)

    ribbonGroup = RbnCtrlGrpCollAddStrStr(ribbonGroupsColl,"GroupID","Group Name")

    groupControlColl = GetRbnCtrlGrpCtrls(ribbonGroup)

    button1 = MICtrlCollAddStrStrInt(groupControlColl,"Button1ID","Button Name",ControlType_Button)

    Call SetRbnBtnCtrlIsLarge(button1,TRUE)

    Call SetRbnBtnCtrlCallingHandler(button1,"Button1Sub")

     

    End Sub

     

    Sub Button1Sub

    Note "Pressed button1"

    End Sub

     



  • 2.  RE: I am stuck creating a button in Ribbon

    Posted 10-26-2017 01:59

    After some more fiddling about, I got it to work with this code (below)

    Pressing the first button works

    Pressing the second button closes the app

     

    'Ribbon

    Include "mapbasic.def"

    Include "IMapInfoPro.def"

    Include "Enums.def"

     

    Dim mapinfoApplication As This

    Dim Ribbon As This

    Dim RibbonTabColl As This

    Dim RibbonTab As This

    Dim ribbonGroupsColl As This

    Dim ribbonGroup As This

    Dim groupControlColl As This

    Dim button1 As This

    Dim button2 As This

     

    Declare Sub Main

    Declare Sub Button1Sub

    Declare Sub EndHandler

    Declare Sub GoodBye

     

    Sub Main

     

    mapinfoApplication = SystemInfo(SYS_INFO_IMAPINFOAPPLICATION)

    Ribbon = GetRibbon(mapinfoApplication)

    RibbonTabColl = GetTabsColl(Ribbon)

    RibbonTab = RbnTabCollAddStrStr(RibbonTabColl,"TabID","Tab Name")

    ribbonGroupsColl = GetRbnTabGrps(RibbonTab)

    ribbonGroup = RbnCtrlGrpCollAddStrStr(ribbonGroupsColl,"GroupID","Group Name")

    groupControlColl = GetRbnCtrlGrpCtrls(ribbonGroup)

     

    button1 = MICtrlCollAddStrStrInt(groupControlColl,"Button1ID","Button Name",ControlType_Button)

    Call SetRbnBtnCtrlIsLarge(button1,TRUE)

    Call SetRbnBtnCtrlCallingHandler(button1,"Button1Sub")

     

    button2 = MICtrlCollAddStrStrInt(groupControlColl,"Button1ID","Good Bye",ControlType_Button)

    Call SetRbnBtnCtrlIsLarge(button2,TRUE)

    Call SetRbnBtnCtrlCallingHandler(button2,"GoodBye")

     

    End Sub

     

    Sub Button1Sub

     

    Note "Pressed button1"

     

    End Sub

     

    Sub GoodBye

     

    Print "GoodBye"

    End Program

     

    End Sub

     

    Sub EndHandler

     

    Dim bRemoved As Logical

     

    Print "EndHandler activated"

     

    bRemoved = MICtrlCollRemove(groupControlColl,button1)

    button1 = NULL_PTR

     

    bRemoved = MICtrlCollRemove(groupControlColl,button2)

    button2 = NULL_PTR

     

    bRemoved = RbnTabCollRemove(RibbonTabColl,RibbonTab)

    RibbonTab = NULL_PTR

     

    End Sub

     



  • 3.  RE: I am stuck creating a button in Ribbon

    Employee
    Posted 10-26-2017 02:24

    One of the typical pitfalls that I have fallen into a number of times, is not having the Endhandler that that clean up the controls added when the applications ends.

    This is required when you compile your source code when a MapBasic compiler for 64 bit.

    If it isn't there, the application loads, add the controls and end again without removing the controls. This leads you into all sorts of funny experiments until you realise that the tool isn't even running and that's the reason why nothing happen when you click on the controls.

    Could that have been the reason why your first example didn't work?



  • 4.  RE: I am stuck creating a button in Ribbon

    Posted 10-26-2017 02:27

    Yes, the main difference between my two drafts of code is that I added an EndHandler routine.



  • 5.  RE: I am stuck creating a button in Ribbon

    Posted 10-26-2017 02:27

    Thanks Peter!



  • 6.  RE: I am stuck creating a button in Ribbon

    Posted 10-29-2017 19:10

    Hi Nick, Peter,

    Thanks for this, while I have not contributed to this issue, I now have a much clearer idea of how to port my own map basic applications to the Ribbon Bar?.

    This is exactly the type of thing I needed, thank you very much to you both.

    cheers

    Peter



  • 7.  RE: I am stuck creating a button in Ribbon

    Posted 10-31-2017 22:08

    I found the only way to get the button to function properly was to call the sub a second time using;

    Alter Menu ID 4 Add

    "&Record Selector..." Calling recSelector

     

    The code below did not work on its own.

    call SetRbnBtnCtrlCallingHandler(recselBtn, "recSelector")

     

    No idea why this should be so.



  • 8.  RE: I am stuck creating a button in Ribbon

    Employee
    Posted 11-01-2017 04:23

    Toby, do you have an EndHandler in your application? If not, this might be the cause.



  • 9.  RE: I am stuck creating a button in Ribbon

    Posted 11-01-2017 17:54

    Yes, its working fine. I just thought it was odd, that without the End Handler or 'Alter Menu ID 4' code the button wouldn't function even though it has a calling handler.