Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to check if Addon window already opened?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to check if Addon window already opened?

    Hi,

    I need to restrict the opening of an addon window to just one instance.

    If the addon window is already opened and the user clicks the New > MyAddon menu item again to open another window... I don't want the 2nd window to open. Is there a way to do that?

    TIA

    #2
    Hello defa0009,

    Thank you for your post.

    You could loop through all active windows and detect if another window is open.

    Here is a forum post with example code:

    https://forum.ninjatrader.com/forum/...te#post1101524

    Comment


      #3
      Originally posted by NinjaTrader_Gaby View Post
      You could loop through all active windows and detect if another window is open.
      Perfect!!!

      Comment


        #4
        The other solution didn't really work for me but it helped me to figure out what I needed to do...

        In case anyone else is looking to limit the number of addon windows opened to one instance here is some skeleton code how to it...

        Code:
        namespace NinjaTrader.NinjaScript.AddOns {
        
            public class MyAddonWindow : NinjaTrader.NinjaScript.AddOnBase {
        
                private NTMenuItem newWindowMenuItem;
                
                private bool windowOpened = false;
        
                protected override void OnStateChange() {
        
                    // code goes here
                }
        
                protected override void OnWindowCreated(Window window) {
        
                    // code goes here
                }
        
                private void OnMenuItemClick(object sender, RoutedEventArgs e) {
        
                    if(windowOpened == false) {
                        
                        Globals.RandomDispatcher.InvokeAsync(new Action(() => new MasterWindow().Show()));
                        
                        windowOpened = true;
                    }
                }
        
                protected override void OnWindowDestroyed(Window window) {
        
                    if(newWindowMenuItem != null && window is ControlCenter) {
        
                        // code goes here
        ​
                    } else if(window is NTWindow) {
                        
                        NTWindow ntWin = window as NTWindow;
                        
                        if(ntWin != null && ntWin.Caption.Equals("MasterWindow"))
                            windowOpened = false;
                    }
                }
            }
        
            public class MasterWindow : NTWindow, IWorkspacePersistence {
        
                public MasterWindow() {
        
                    Caption = "MasterWindow";
                }
            }
        }
        ​

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        89 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        143 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        83 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        257 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        334 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X