Link to home
Start Free TrialLog in
Avatar of thedude112286
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.IDocHostUIHandler
      {
#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(slide.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.DocumentComplete += new AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(OnDocumentComplete);
                  
                  this.Controls.Add(browserControl);
                  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.SystemColors.ActiveCaption;
                  //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_DocumentCompleteEvent e)
            {
                  MessageBox.Show("document complete");
                  
                  ((WebBrowser.IHTMLDocument2)browserControl.Document).SetDesignMode("On");
                  
                  WebBrowser.ICustomDoc customDoc = (WebBrowser.ICustomDoc)
                                                                        browserControl.Document;
                  customDoc.SetUIHandler((WebBrowser.IDocHostUIHandler)this);
            }
#endregion events
            
            
#region DocHostUI            
            public uint ShowContextMenu(uint dwID, ref /*tagPOINT*/UtilityLibrary.Win32.POINT pPoint,
                                    [MarshalAs(UnmanagedType.IUnknown)] object pcmdtReserved,
                                    [MarshalAs(UnmanagedType.IDispatch)] 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(this, 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.MessageBox.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.DOCHOSTUIFLAG.DOCHOSTUIFLAG_SCROLL_NO |
                WebBrowser.DOCHOSTUIFLAG.DOCHOSTUIFLAG_NO3DBORDER |
              WebBrowser.DOCHOSTUIFLAG.DOCHOSTUIFLAG_DISABLE_SCRIPT_INACTIVE |*/
              WebBrowser.DOCHOSTUIFLAG.DOCHOSTUIFLAG_DIV_BLOCKDEFAULT);
          }
   
          public void ShowUI(uint dwID,
                        [MarshalAs(UnmanagedType.Interface)] IntPtr pActiveObject,
                        [MarshalAs(UnmanagedType.Interface)] IntPtr pCommandTarget,
                        [MarshalAs(UnmanagedType.Interface)] IntPtr pFrame,
                        [MarshalAs(UnmanagedType.Interface)] 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.Interface)] 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_CONTROL) >= 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(UnmanagedType.Interface)] IntPtr pDropTarget,
                                    [MarshalAs(UnmanagedType.Interface)] ref IntPtr ppDropTarget)
          {
          }

          public void GetExternal([Out, MarshalAs(UnmanagedType.IDispatch)] 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(IDataObject pDO, ref IDataObject ppDORet)
          {
                  //      return doIn;
          }
#endregion DocHostUI
      }
Avatar of ACGT
ACGT

Hello,

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
Avatar of thedude112286

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
Avatar of ACGT
ACGT

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you very much.  This worked perfectly.