thedude112286
asked on
AxWebBrowser problem
I have a form that uses an AxWebBrowser control. However, it will not navigate to any site or local file. What is the problem and how can I fix it? I have tried everything. Please help. By the way, IDocHostUIHandler and ICustomDoc are impliemented corectly in another file in the namespace WebBrowser and Slide is a class with members and properties fileName and title.
public class SlideView : System.Windows.Forms.Form,
WebBrowser.IDocHostUIHandl er
{
#region members
private AxSHDocVw.AxWebBrowser browserControl;
private Slide slide;
#endregion members
#region constructors
// should I Delete this constructor?
public SlideView()
{
InitializeComponent();
InitBrowser();
}
public SlideView(Slide slide)
{
if (slide.FileName == String.Empty)
{
slide.FileName = GLOBALS._Document.MainPath + @"\Slides\" + slide.Title + ".htm";
System.IO.File.Create(slid e.FileName );
}
this.slide = slide;
this.Text = slide.Title;
InitializeComponent();
InitBrowser();
}
#endregion constructors
#region properties
public Slide Slide {
get {
return slide;
}
}
#endregion properties
#region methods
private void InitBrowser()
{
browserControl = new AxSHDocVw.AxWebBrowser();
browserControl.BeginInit() ;
browserControl.Location = new Point(0,0);
browserControl.Size = this.ClientSize;
browserControl.DocumentCom plete += new AxSHDocVw.DWebBrowserEvent s2_Documen tCompleteE ventHandle r(OnDocume ntComplete );
this.Controls.Add(browserC ontrol);
browserControl.EndInit();
// this does not work for any site!!!!!! Please help.
object o = null;
browserControl.Navigate("www.yahoo.com" , ref o, ref o, ref o, ref o);
}
#endregion methods
#region autogen
void InitializeComponent() {
this.SuspendLayout();
//
// CreatedForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.SystemColor s.ActiveCa ption;
//this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "SlideView";
this.ResumeLayout(false);
}
#endregion autogen
#region events
protected override void OnSizeChanged(EventArgs e)
{
browserControl.Size = this.ClientSize;
}
public void OnDocumentComplete(object sender, DWebBrowserEvents2_Documen tCompleteE vent e)
{
MessageBox.Show("document complete");
((WebBrowser.IHTMLDocument 2)browserC ontrol.Doc ument).Set DesignMode ("On");
WebBrowser.ICustomDoc customDoc = (WebBrowser.ICustomDoc)
browserControl.Document;
customDoc.SetUIHandler((We bBrowser.I DocHostUIH andler)thi s);
}
#endregion events
#region DocHostUI
public uint ShowContextMenu(uint dwID, ref /*tagPOINT*/UtilityLibrary .Win32.POI NT pPoint,
[MarshalAs(UnmanagedType.I Unknown)] object pcmdtReserved,
[MarshalAs(UnmanagedType.I Dispatch)] object pdispReserved)
{
// use this code to show a custom menu
/*const int Ok = 0;
Point p = new Point(pPoint.x, pPoint.y);
p = PointToClient(p);
myCustomContextMenu.Show(t his, p);
throw new COMException("", Ok); */// HRESULT = S_OK: MSHTML won't show its menu
// use this code to let MsHtml shows its menu
System.Windows.Forms.Messa geBox.Show ("HI from cm");
const int Error = 1;
throw new COMException("", Error); // HRESULT = S_FALSE: MSHTML will show its menu
}
public void GetHostInfo(ref WebBrowser.DOCHOSTUIINFO theHostUIInfo)
{
// turn three flags on
theHostUIInfo.dwFlags |= (uint) (/*WebBrowser.DOCHOSTUIFLA G.DOCHOSTU IFLAG_SCRO LL_NO |
WebBrowser.DOCHOSTUIFLAG.D OCHOSTUIFL AG_NO3DBOR DER |
WebBrowser.DOCHOSTUIFLAG.D OCHOSTUIFL AG_DISABLE _SCRIPT_IN ACTIVE |*/
WebBrowser.DOCHOSTUIFLAG.D OCHOSTUIFL AG_DIV_BLO CKDEFAULT) ;
}
public void ShowUI(uint dwID,
[MarshalAs(UnmanagedType.I nterface)] IntPtr pActiveObject,
[MarshalAs(UnmanagedType.I nterface)] IntPtr pCommandTarget,
[MarshalAs(UnmanagedType.I nterface)] IntPtr pFrame,
[MarshalAs(UnmanagedType.I nterface)] IntPtr pDo) {}
public void HideUI() {}
public void UpdateUI() {}
public void EnableModeless(int fEnable) {}
public void OnDocWindowActivate(int fActivate) {}
public void OnFrameWindowActivate(int fActivate) {}
///<see DocHostUIHandler.cs></see>
public void ResizeBorder(ref /*tagRECT*/object prcBorder,
[MarshalAs(UnmanagedType.I nterface)] IntPtr pUIWindow,
int fRameWindow) {}
public void TranslateAccelerator(ref tagMSG lpMsg, ref Guid pguidCmdGroup, uint nCmdID)
{
//const int Ok = 0;
const int Error = 1;
/*const int WM_KEYDOWN = 0x0100;
const int VK_CONTROL = 0x11;
if (lpMsg.message != WM_KEYDOWN)
// allow message
throw new COMException("", Error); // returns HRESULT = S_FALSE
if (GetAsyncKeyState(VK_CONTR OL) >= 0)
// Ctrl key not pressed: allow message
throw new COMException("", Error); // returns HRESULT = S_FALSE
// disable the Ctrl-N and Ctrl-P accelerators
lpMsg.wParam &= 0xFF; // get the virtual keycode
if ( (lpMsg.wParam == 'N') || ((lpMsg.wParam == 'P')) )
throw new COMException("", Ok); // returns HRESULT = S_OK
*/// allow everything else
throw new COMException("", Error); // returns HRESULT = S_FALSE
}
public void GetOptionKeyPath(ref string pchKey, uint dw) {}
public void GetDropTarget([MarshalAs(U nmanagedTy pe.Interfa ce)] IntPtr pDropTarget,
[MarshalAs(UnmanagedType.I nterface)] ref IntPtr ppDropTarget)
{
}
public void GetExternal([Out, MarshalAs(UnmanagedType.ID ispatch)] out object ppDispatch)
{
ppDispatch = null;
}
public void TranslateUrl(uint dwTranslate, string URLIn, ref string URLOut)
{
URLOut = URLIn; // add code here to modify the Url the user is trying to
// navigate to. Ex:
// // prevent users from leaving your web site
// if (URLIn.IndexOf("mywebsite. com") < 0)
// URLOut = "http://www.mywebsite.com";
// else
// URLOut = URLIn;
}
public void FilterDataObject(IDataObje ct pDO, ref IDataObject ppDORet)
{
// return doIn;
}
#endregion DocHostUI
}
public class SlideView : System.Windows.Forms.Form,
WebBrowser.IDocHostUIHandl
{
#region members
private AxSHDocVw.AxWebBrowser browserControl;
private Slide slide;
#endregion members
#region constructors
// should I Delete this constructor?
public SlideView()
{
InitializeComponent();
InitBrowser();
}
public SlideView(Slide slide)
{
if (slide.FileName == String.Empty)
{
slide.FileName = GLOBALS._Document.MainPath
System.IO.File.Create(slid
}
this.slide = slide;
this.Text = slide.Title;
InitializeComponent();
InitBrowser();
}
#endregion constructors
#region properties
public Slide Slide {
get {
return slide;
}
}
#endregion properties
#region methods
private void InitBrowser()
{
browserControl = new AxSHDocVw.AxWebBrowser();
browserControl.BeginInit()
browserControl.Location = new Point(0,0);
browserControl.Size = this.ClientSize;
browserControl.DocumentCom
this.Controls.Add(browserC
browserControl.EndInit();
// this does not work for any site!!!!!! Please help.
object o = null;
browserControl.Navigate("www.yahoo.com"
}
#endregion methods
#region autogen
void InitializeComponent() {
this.SuspendLayout();
//
// CreatedForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.SystemColor
//this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "SlideView";
this.ResumeLayout(false);
}
#endregion autogen
#region events
protected override void OnSizeChanged(EventArgs e)
{
browserControl.Size = this.ClientSize;
}
public void OnDocumentComplete(object sender, DWebBrowserEvents2_Documen
{
MessageBox.Show("document complete");
((WebBrowser.IHTMLDocument
WebBrowser.ICustomDoc customDoc = (WebBrowser.ICustomDoc)
browserControl.Document;
customDoc.SetUIHandler((We
}
#endregion events
#region DocHostUI
public uint ShowContextMenu(uint dwID, ref /*tagPOINT*/UtilityLibrary
[MarshalAs(UnmanagedType.I
[MarshalAs(UnmanagedType.I
{
// use this code to show a custom menu
/*const int Ok = 0;
Point p = new Point(pPoint.x, pPoint.y);
p = PointToClient(p);
myCustomContextMenu.Show(t
throw new COMException("", Ok); */// HRESULT = S_OK: MSHTML won't show its menu
// use this code to let MsHtml shows its menu
System.Windows.Forms.Messa
const int Error = 1;
throw new COMException("", Error); // HRESULT = S_FALSE: MSHTML will show its menu
}
public void GetHostInfo(ref WebBrowser.DOCHOSTUIINFO theHostUIInfo)
{
// turn three flags on
theHostUIInfo.dwFlags |= (uint) (/*WebBrowser.DOCHOSTUIFLA
WebBrowser.DOCHOSTUIFLAG.D
WebBrowser.DOCHOSTUIFLAG.D
WebBrowser.DOCHOSTUIFLAG.D
}
public void ShowUI(uint dwID,
[MarshalAs(UnmanagedType.I
[MarshalAs(UnmanagedType.I
[MarshalAs(UnmanagedType.I
[MarshalAs(UnmanagedType.I
public void HideUI() {}
public void UpdateUI() {}
public void EnableModeless(int fEnable) {}
public void OnDocWindowActivate(int fActivate) {}
public void OnFrameWindowActivate(int fActivate) {}
///<see DocHostUIHandler.cs></see>
public void ResizeBorder(ref /*tagRECT*/object prcBorder,
[MarshalAs(UnmanagedType.I
int fRameWindow) {}
public void TranslateAccelerator(ref tagMSG lpMsg, ref Guid pguidCmdGroup, uint nCmdID)
{
//const int Ok = 0;
const int Error = 1;
/*const int WM_KEYDOWN = 0x0100;
const int VK_CONTROL = 0x11;
if (lpMsg.message != WM_KEYDOWN)
// allow message
throw new COMException("", Error); // returns HRESULT = S_FALSE
if (GetAsyncKeyState(VK_CONTR
// Ctrl key not pressed: allow message
throw new COMException("", Error); // returns HRESULT = S_FALSE
// disable the Ctrl-N and Ctrl-P accelerators
lpMsg.wParam &= 0xFF; // get the virtual keycode
if ( (lpMsg.wParam == 'N') || ((lpMsg.wParam == 'P')) )
throw new COMException("", Ok); // returns HRESULT = S_OK
*/// allow everything else
throw new COMException("", Error); // returns HRESULT = S_FALSE
}
public void GetOptionKeyPath(ref string pchKey, uint dw) {}
public void GetDropTarget([MarshalAs(U
[MarshalAs(UnmanagedType.I
{
}
public void GetExternal([Out, MarshalAs(UnmanagedType.ID
{
ppDispatch = null;
}
public void TranslateUrl(uint dwTranslate, string URLIn, ref string URLOut)
{
URLOut = URLIn; // add code here to modify the Url the user is trying to
// navigate to. Ex:
// // prevent users from leaving your web site
// if (URLIn.IndexOf("mywebsite.
// URLOut = "http://www.mywebsite.com";
// else
// URLOut = URLIn;
}
public void FilterDataObject(IDataObje
{
// return doIn;
}
#endregion DocHostUI
}
ASKER
I haven't yet resolved the problem and if you wouldn't mind, I think it would be a big help if you could post the webbrowser class. Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much. This worked perfectly.
did you solve the problem until now?
I use a webbrowser class with axshdocvw that gives me the possibility to add a webbrowser control to my windows application. It works fine, if you still need, I could copy it here?
Sabine