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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        577 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        334 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        553 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        551 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X