cholden
asked on
Open Browser Window from Windows App
I have a little application that opens a browser window from a windows application built using VS2005.
Added references for Microsoft.mshtml and interop.shdocvw.
Then created a browser class:
public class StaticBrowser
{
public static IWebBrowser2 TheInstance = new InternetExplorerClass()
as IWebBrowser2;
}
Next used the following code in a menu click to open a browser window:
private void staticBrowserToolStripMenu Item_Click (object sender,
EventArgs e)
{
object missing = System.Reflection.Missing. Value;
StaticBrowser.TheInstance. Navigate(" http://www.ezywrap.com",
ref missing, ref missing, ref missing, ref missing);
StaticBrowser.TheInstance. Visible = true;
}
This is all fine and the browser window opens - if I click the menu item again the same browser window is used and you can see it re-display - the same window.
The problem is if the user closes the browser window that was open the following error happens when the user clicks the menu item again to open the browser window.
System.Runtime.InteropServ ices.COMEx ception (0x80010108): The object invoked has disconnected from its clients. (Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED))
Is there any way to bring up this window again - I know I can use a non static Browser but that results in a new window with every click which is something I was trying to avoid.
thanks
Added references for Microsoft.mshtml and interop.shdocvw.
Then created a browser class:
public class StaticBrowser
{
public static IWebBrowser2 TheInstance = new InternetExplorerClass()
as IWebBrowser2;
}
Next used the following code in a menu click to open a browser window:
private void staticBrowserToolStripMenu
EventArgs e)
{
object missing = System.Reflection.Missing.
StaticBrowser.TheInstance.
ref missing, ref missing, ref missing, ref missing);
StaticBrowser.TheInstance.
}
This is all fine and the browser window opens - if I click the menu item again the same browser window is used and you can see it re-display - the same window.
The problem is if the user closes the browser window that was open the following error happens when the user clicks the menu item again to open the browser window.
System.Runtime.InteropServ
Is there any way to bring up this window again - I know I can use a non static Browser but that results in a new window with every click which is something I was trying to avoid.
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
What I finally ended up doing was catching the exception and re-initializing the instance - was trying to avoid doing it this way, but it works:
object missing = System.Reflection.Missing. Value;
try
{
StaticBrowser.TheInstance. Navigate(" http://www.ezywrap.com", ref missing, ref missing, ref missing, ref missing);
}
catch
{
StaticBrowser.TheInstance = new InternetExplorerClass() as IWebBrowser2;
StaticBrowser.TheInstance. Navigate(" http://www.ezywrap.com", ref missing, ref missing, ref missing, ref missing);
}
StaticBrowser.TheInstance. Visible = true;
}
thanks
object missing = System.Reflection.Missing.
try
{
StaticBrowser.TheInstance.
}
catch
{
StaticBrowser.TheInstance = new InternetExplorerClass() as IWebBrowser2;
StaticBrowser.TheInstance.
}
StaticBrowser.TheInstance.
}
thanks
ASKER
thanks