Close existing tab when new Tab is opened

Add-in Express™ Support Service
That's what is more important than anything else

Close existing tab when new Tab is opened
 
Todd Price




Posts: 3
Joined: 2013-06-14
I'm currently working on task of closing an existing tab whenever a new tab is opened. I'm relatively new to add-in express and was going through the padding section of article http://www.add-in-express.com/docs/internet-explorer-addon-development.php

The article mentions that OnTabCreated and OnTabActivated events are invoked when new tab is created. But I'm not able to find these events in the Properties event list.

When I tried registering OnTabCreated event I'm getting error -- does not contain a definition for 'OnTabCreated'. How can I access these events?
Posted 10 Jul, 2014 17:07:40 Top
Andrei Smolin


Add-in Express team


Posts: 14094
Joined: 2006-05-11
Hello Todd,

This is possible in an IE add-on project only. Such a project is based on an ADXIEModule.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 11 Jul, 2014 02:32:49 Top
Todd Price




Posts: 3
Joined: 2013-06-14
Thanks a lot Andrei. I was able to use the events after creating it as an IE add-on project.

However, I'm not able to close previous tabs when new tab is being created.

I'm having difficulty in how to identify the tabs. I used GetModuleIndex and ran a loop to identify the previous tabs. But for some reason the tab indexes keep on changing whenever a new tab is opened.

For example, when there's 2 tabs the index of tab1 is 0 and tab2 is 1. But when I open a 3rd tab, the index value of tab1 is 0, tab2 changes to 2 and tab3 is 1.

Could you help me with how to identify the tabs? And also I've not been able to close the tabs after using TabClose method from ADXIEModule. I'm enclosing the code for your reference.

 private void IEModule_OnTabActivated(object sender, EventArgs e)
        {
            int newTabIndex = this.GetModuleIndex();
            MessageBox.Show("Module index "+ this.GetModuleIndex().ToString());
            MessageBox.Show("Module count " + this.GetModuleCount().ToString());
            for(int i=0;i<this.GetModuleCount();i++)
            {
                if(i!=newTabIndex)
                {
                    AddinExpress.IE.ADXIEModule module = this.GetModuleByIndex(i);
                    MessageBox.Show(module.GetModuleIndex().ToString());
                    MessageBox.Show("Tabbed browsing "+i+" " +module.IsTabbedBrowsingEnabled().ToString());
                    MessageBox.Show("Quick Tabs "+i+" " +module.IsQuickTabsEnabled().ToString());
                    module.TabClose();
                }

            }

            //int checkThread = module.ThreadID;
            //MessageBox.Show(this.ParentHandle.ToString());
            //MessageBox.Show(module.GetTabIndex().ToString());


        }
Posted 14 Jul, 2014 16:35:57 Top
Andrei Smolin


Add-in Express team


Posts: 14094
Joined: 2006-05-11
Hello Todd,

Try this approach:

private const int WM_USER = 0x0400;
private const int WM_CLOSETAB = WM_USER + 100;

private void IEModule_OnTabActivated(object sender, EventArgs e) {
    this.SendMessageToAll(WM_CLOSETAB, this.ParentHandle, IntPtr.Zero);
}

private void IEModule_OnSendMessage(ADXIESendMessageEventArgs e) {
    if (e.Message == WM_CLOSETAB) {
        if (this.ParentHandle != e.WParam) {
            System.Diagnostics.Debug.WriteLine("!!! IEModule_OnSendMessage. calling TabClose()");
            this.TabClose();
        }
    }
} 


Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 15 Jul, 2014 05:20:57 Top