Set Window map_win_id Front does not work

56 views
Skip to first unread message

Nicholas G Lawrence

unread,
Dec 9, 2024, 9:39:45 PM12/9/24
to mapi...@googlegroups.com

Hello all,

I am running MapInfo v2023 and MapBasic v2019

In my MapBasic code, I want to explicitly make the Map Window active. Essentially, I want to replicate the action of clicking on the title bar of the Map Window

I use the command Set Window map_win_id Front

But it does not work

I have confirmed that I do know the correct value for map_win_id. I have already gathered this value by grabbing the value of FrontWindow() during a mouse-click inside the mouse window event

I need this so that a button in the Ribbon activates. I have already enabled the button with SetRbnToolBtnCtrlEnabled but the button remains greyed out until I click on the title bar of the Map Window

 

 

Nick Lawrence
Senior Spatial Science Officer | Geospatial Technologies
Engineering & Technology | Transport and Main Roads

 

Floor 19 | 313 Adelaide Street | Brisbane City Qld 4000
GPO Box 1412 | Brisbane City Qld 4001
P: (07) 30667977
E: nicholas....@tmr.qld.gov.au
W:
www.tmr.qld.gov.au

 


WARNING: This email (including any attachments) may contain legally privileged, confidential or private information and may be protected by copyright. You may only use it if you are the person(s) it was intended to be sent to and if you use it in an authorised way. No one is allowed to use, review, alter, transmit, disclose, distribute, print or copy this email without appropriate authority.

If this email was not intended for you and was sent to you by mistake, please telephone or email me immediately, destroy any hard copies of this email and delete it and any copies of it from your computer system. Any right which the sender may have under copyright law, and any legal privilege and confidentiality attached to this email is not waived or destroyed by that mistake.

It is your responsibility to ensure that this email does not contain and is not affected by computer viruses, defects or interference by third parties or replication problems (including incompatibility with your computer system).

Opinions contained in this email do not necessarily reflect the opinions of the Department of Transport and Main Roads, or endorsed organisations utilising the same infrastructure.

Nicholas G Lawrence

unread,
Dec 9, 2024, 11:04:12 PM12/9/24
to mapi...@googlegroups.com

 

I think I have solved it

Though I do not like my solution.

My code is supposed to Enable a greyed-out button after the user clicks inside the Map Window, so they can proceed to the next step of the workflow.

The bad behaviour occurs when the Map Window is active, then I use my custom Tool button to click inside the map window. The next button along remains greyed out. But it "pops" into being Enabled if I click on the title bar of the Map Window. This is a non-intuitive extra step that I do not want to force upon the users. I use the command Set Window map_win_id Front to force the Map Window to be active, but this does not work.

Good behaviour occurs if (for some reason) any window that is not the Map Window is active (like the Explorer Window), then I use my custom Tool button to click inside the map window. The next button along is enabled as it should be.

I suspect that the command Set Window map_win_id Front only really works if a window other than the Map Window is active. I think that MapInfo makes the assessment that the Map Window is already the front window and chooses to not do anything.

My solution is to first force a different window (I chose the Message Window) to be active and then, on the next line, force the Map Window to be active.

Set Window WIN_MESSAGE Front
Set Window gMapWinID Front

This works. The next button along is enabled like it should be.

Essentially, I am faking clicking on the title bar of the Message Window and then clicking on the title bar of the Map Window, and this triggers the custom button in the RIbbon to refresh properly.

It works, but I don't like it, it feels like a hack

 

Cheers,

Nick

--
--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en

---
You received this message because you are subscribed to the Google Groups "MapInfo-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapinfo-l+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/mapinfo-l/SY6P282MB3816818C21E7D68E248B60D8D33D2%40SY6P282MB3816.AUSP282.PROD.OUTLOOK.COM.

Nicholas G Lawrence

unread,
Dec 10, 2024, 6:58:54 PM12/10/24
to mapi...@googlegroups.com

I am pasting here code that demonstrates the behaviour that I consider an issue

 

This mapbasic script creates a ribbon with two tool buttons, and one Exit button

The second tool button starts off disabled

Using the first tool button and clicking inside the map window is supposed to Enable the second tool button

But! The second tool button is only enabled if the user also clicks onto the title bar of the map window, thus “refreshing” the ribbon.

What I want is for the second tool button to be enabled without having to click onto the title bar of the map window.

 

Here is the code that I am pasting

 

 

' test code to demonstrate problem with map window losing focus

 

 

Include "MapBasic.def"                       '- standard MapBasic definitions

Include "Icons.def"                          '- standard MapBasic definitions

Include "Menu.def"                           '- standard MapBasic definitions

Include "Enums.def"

Include "IMapInfoPro.def"

 

 

 

 

 

Dim mapinfoApplication As This

Dim Ribbon As This

Dim RibbonTabColl As This

Dim RibbonTab As This

Dim ribbonGroupsColl As This

Dim ribbonGroup1 As This

Dim groupControlColl_1 As This

Dim ribbonGroup2 As This

Dim groupControlColl_2 As This

Dim button1a As This

Dim button1b As This

Dim button2a As This

 

 

 

Declare Sub Main

Declare Sub subClickMap1

Declare Sub subClickMap2

Declare Sub subExit

Declare Sub EndHandler

 

 

 

Sub Main

 

   Dim nCtrlIdx As Integer

   Dim sTabName, sTabCaption As String

   Dim sGroupName, sGroupCaption As String

   Dim sButtonName, sButtonCaption As String

   Dim sDropDButtonName, sDropDButtonCaption, sDropDButtonGroupName, sDropDButtonGroupCaption As String

 

   '--- Create the Tab "Example"

   Call RegisterUriParser(New_GenericUriParser(1),"pack",-1)

   mapinfoApplication = SystemInfo(SYS_INFO_IMAPINFOAPPLICATION)

   Ribbon = GetRibbon(mapinfoApplication)

   RibbonTabColl = GetTabsColl(Ribbon)

   RibbonTab = RbnTabCollAddStrStr(RibbonTabColl,"CLineTabID","Example")

   ribbonGroupsColl = GetRbnTabGrps(RibbonTab)

 

   '--- Create the Group "Test"

   ribbonGroup1 = RbnCtrlGrpCollAddStrStr(ribbonGroupsColl,"CLineGroup1ID","Test")

   Call SetRbnCtrlGrpIsLauncherVisible(ribbonGroup1,FALSE)

   groupControlColl_1 = GetRbnCtrlGrpCtrls(ribbonGroup1)

 

   '--- Create the button1a "Click in Map 1"

   button1a = MICtrlCollAddStrStrInt(groupControlColl_1,"CLineButton1dID","Click in Map 1",ControlType_ToolButton)

   Call SetRbnToolBtnCtrlIsLarge(button1a,TRUE)

   Call SetRbnToolBtnCtrlCallingHandler(button1a,"subClickMap1")

   Call SetRbnToolBtnCtrlLargeIcon(button1a,New_Uri("pack://application:,,,/MapInfo.StyleResources;component/Images/Mapping/redo_32x32.png",0))

   Call SetRbnToolBtnCtrlCursorId(button1a,MI_CURSOR_CROSSHAIR)

   Call SetRbnToolBtnCtrlDrawMode(button1a,DM_CUSTOM_POINT)

 

   '--- Create the button1b "Click in Map 2"

   button1b = MICtrlCollAddStrStrInt(groupControlColl_1,"CLineButton1eID","Click in Map 2",ControlType_ToolButton)

   Call SetRbnToolBtnCtrlIsLarge(button1b,TRUE)

   Call SetRbnToolBtnCtrlCallingHandler(button1b,"subClickMap2")

   Call SetRbnToolBtnCtrlLargeIcon(button1b,New_Uri("pack://application:,,,/MapInfo.StyleResources;component/Images/Mapping/redo_32x32.png",0))

   Call SetRbnToolBtnCtrlCursorId(button1b,MI_CURSOR_CROSSHAIR)

   Call SetRbnToolBtnCtrlDrawMode(button1b,DM_CUSTOM_POINT)

   Call SetRbnToolBtnCtrlEnabled(button1b,FALSE)

 

   '--- Create the Group2 "Admin"

   ribbonGroup2 = RbnCtrlGrpCollAddStrStr(ribbonGroupsColl,"CLineGroup2ID","Admin")

   Call SetRbnCtrlGrpIsLauncherVisible(ribbonGroup2,FALSE)

   groupControlColl_2 = GetRbnCtrlGrpCtrls(ribbonGroup2)

 

   '--- Create the button2a "Exit"

   button2a = MICtrlCollAddStrStrInt(groupControlColl_2,"CLineButton2aID","Exit",ControlType_Button)

   Call SetRbnBtnCtrlIsLarge(button2a,TRUE)

   Call SetRbnBtnCtrlCallingHandler(button2a,"subExit")

   Call SetRbnBtnCtrlLargeIcon(button2a,New_Uri("pack://application:,,,/MapInfo.StyleResources;component/Images/Application/exit_32x32.png",0))

 

 

 

 

End Sub

 

 

 

Sub subClickMap1

Print "subClickMap1"

 

Print "enable button 2"

   Call SetRbnToolBtnCtrlEnabled(button1b,TRUE)

 

 

End Sub

 

 

Sub subClickMap2

Print "subClickMap2"

 

 

End Sub

 

 

Sub subExit

Print "subExit"

 

End Program

 

End Sub

 

 

 

 

Sub EndHandler

Dim bRemoved As Logical

 

'remove buttons

'bRemoved = MICtrlCollRemove(groupControlColl_1,button1a)

'button1a = NULL_PTR

'bRemoved = MICtrlCollRemove(groupControlColl_1,button1b)

'button1b = NULL_PTR

bRemoved = MICtrlCollRemove(groupControlColl_2,button2a)

button2a = NULL_PTR

 

'remove groups

bRemoved = RbnCtrlGrpCollRemove(ribbonGroupsColl,ribbonGroup1)

ribbonGroup1 = NULL_PTR

bRemoved = RbnCtrlGrpCollRemove(ribbonGroupsColl,ribbonGroup2)

ribbonGroup2 = NULL_PTR

 

'remove tab

bRemoved = RbnTabCollRemove(RibbonTabColl,RibbonTab)

RibbonTab = NULL_PTR

 

End Sub

Reply all
Reply to author
Forward
0 new messages