public void Stop() { if (htmlViewHandle != IntPtr.Zero) { WebBrowserAPI.SendMessage(htmlViewHandle, WebBrowserAPI.DTM_STOP, 0, 0); } }
public void SetScrolPosition(int value) { WebBrowserAPI.SCROLLINFO lpScrollInfo = new WebBrowserAPI.SCROLLINFO(); lpScrollInfo.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(lpScrollInfo); lpScrollInfo.fMask = WebBrowserAPI.SIF_POS; lpScrollInfo.nPos = value; WebBrowserAPI.SetScrollInfo(htmlViewHandle, WebBrowserAPI.SB_VERT, ref lpScrollInfo, true); Rectangle update = new Rectangle(); WebBrowserAPI.GetClientRect(htmlViewHandle, ref update); WebBrowserAPI.ScrollWindowEx(htmlViewHandle, 0, -(value), 0, 0, IntPtr.Zero, update, WebBrowserAPI.SW_ERASE | WebBrowserAPI.SW_INVALIDATE); }
protected override void OnParentChanged(EventArgs e) { base.OnParentChanged(e); var style = (int)(WebBrowserAPI.WS_VISIBLE | WebBrowserAPI.WS_TABSTOP | WebBrowserAPI.WS_CHILD | WebBrowserAPI.HS_NOSELECTION); htmlViewHandle = WebBrowserAPI.CreateWindowEx(0, "DISPLAYCLASS", null, style, 0, 0, Width, Height, Handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); //WmApi.SendMessage(htmlViewHandle, WmApi.DTM_ENABLECONTEXTMENU, 0, 1); hwnd = Handle; newWndProc = new WndProcDelegate(NewWndProc); oldWndProc = WebBrowserAPI.GetWindowLong(hwnd, WebBrowserAPI.GWL_WNDPROC); int success = WebBrowserAPI.SetWindowLong(hwnd, WebBrowserAPI.GWL_WNDPROC, newWndProc); }
private IntPtr NewWndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) { switch (msg) { case WebBrowserAPI.WM_NOTIFY: WebBrowserAPI.NmHdr n = WebBrowserAPI.NmHdr.GetStruct(lParam); switch (n.code) { case WebBrowserAPI.NM_INLINE_IMAGE: OnInlineObject(WebBrowserAPI.NM_INLINE_IMAGE, WebBrowserAPI.HtmlViewMessage.GetStruct(lParam)); break; case WebBrowserAPI.NM_BEFORENAVIGATE: OnBeforeNavigate(WebBrowserAPI.HtmlViewMessage.GetStruct(lParam)); break; case WebBrowserAPI.NM_NAVIGATECOMPLETE: OnNavigateComplete(WebBrowserAPI.HtmlViewMessage.GetStruct(lParam)); break; case WebBrowserAPI.NM_DOCUMENTCOMPLETE: OnDocumentComplete(WebBrowserAPI.HtmlViewMessage.GetStruct(lParam)); break; //case WebBrowserAPI.NM_CONTEXTMENU: // WebBrowserAPI.HtmlContextMessage hcm = WebBrowserAPI.HtmlContextMessage.GetStruct(lParam); // string lnk = hcm.linkHREF; // string tit = hcm.linkName; // System.Drawing.Point pt = hcm.pt; // OnContextMenu(hcm); // break; case WebBrowserAPI.NM_HOTSPOT: if (OnHotSpotClicked(WebBrowserAPI.HtmlViewMessage.GetStruct(lParam))) { // return not zero value to not let pass message to the parent control return(new IntPtr(1)); } break; } break; } return(WebBrowserAPI.CallWindowProc(oldWndProc, hWnd, msg, wParam, lParam)); }
public void Navigate(string url) { Stop(); if (url == null || url.Trim().Length == 0) { return; } //if (!String.IsNullOrEmpty(SpecialUrlParams)) //{ // if (url.IndexOf('?') > 0) // url += "&" + SpecialUrlParams; // else // url += "?" + SpecialUrlParams; //} _url = new Uri(url); WebBrowserAPI.SendMessage(htmlViewHandle, WebBrowserAPI.DTM_NAVIGATE, WebBrowserAPI.NAVIGATEFLAG_NOCACHE, url); }
protected override void OnHandleDestroyed(EventArgs e) { Stop(); base.OnHandleDestroyed(e); if (oldWndProc != IntPtr.Zero && hwnd != IntPtr.Zero) { WebBrowserAPI.SetWindowLong(hwnd, WebBrowserAPI.GWL_WNDPROC, oldWndProc); } Marshal.Release(htmlViewHandle); if (htmlViewHandle != IntPtr.Zero) { if (WebBrowserAPI.DestroyWindow(htmlViewHandle)) { htmlViewHandle = IntPtr.Zero; GC.Collect(); } } }
public WebBrowserEx() { InitializeComponent(); WebBrowserAPI.InitializeHtmlView(); }
public void SetScrollAnchor(string anchor) { WebBrowserAPI.SendMessage(htmlViewHandle, WebBrowserAPI.DTM_ANCHORW, 0, anchor); }
public void SetScrollEnd() { WebBrowserAPI.SendMessage(htmlViewHandle, WebBrowserAPI.WM_VSCROLL, WebBrowserAPI.SB_BOTTOM, 0); }
private void OnNavigateComplete(WebBrowserAPI.HtmlViewMessage message) { //string url = UnicodeToUtf8(message.target); //if (url.Substring(0, 5) == "http:") //{ // Stop(); // Navigate(_url.ToString()); // return; //} if (NavigateComplete != null) { NavigateComplete(message); } }
private void OnInlineObject(int notifyCode, WebBrowserAPI.HtmlViewMessage htmlViewMessage) { if (ShowWaitCursorWhileLoading) Cursor.Current = Cursors.WaitCursor; }
/// <summary> /// /// </summary> /// <param name="msg"></param> /// <returns>true if message was processed</returns> private bool OnHotSpotClicked(WebBrowserAPI.HtmlViewMessage msg) { Stop(); if (msg.target == null) return true; try { string escapedUrl = Uri.EscapeUriString(PrepareUrl(UnicodeToUtf8(msg.target))); string target = null; int idig = escapedUrl.IndexOf('#'); if (idig > -1) { target = escapedUrl.Substring(idig, escapedUrl.Length - idig); escapedUrl = escapedUrl.Substring(0, idig); } Uri uri = null; try { uri = new Uri(escapedUrl); } catch (UriFormatException) { } if (uri == null || String.IsNullOrEmpty(uri.Host)) { try { uri = new Uri(_url, escapedUrl); } catch (UriFormatException) { } } string postdata = null; if (msg.data != null && msg.data.Length > 0) postdata = UnicodeToUtf8(msg.data); WebBrowserNavigatingExEventArgs e = new WebBrowserNavigatingExEventArgs(uri, target, postdata); if (Navigating != null) { Navigating(this, e); if (!e.Cancel) return false; } } catch (UriFormatException) { return true; } catch (Exception) { return true; } return true; }
private void OnDocumentComplete(WebBrowserAPI.HtmlViewMessage message) { Debug.WriteLine("WebBrowser.OnDocumentComplete"); if (ShowWaitCursorWhileLoading) Cursor.Current = Cursors.Default; if (DocumentComplete != null) { DocumentComplete(message); //Из за увеличения размеров при VGA в браузере вручную ставим в 0 //if(ListViewSettings.Current.ScreenDPI >= 192) // ZoomLevel = 0; } }
//private void OnContextMenu(WebBrowserAPI.HtmlContextMessage message) //{ // string lnk = message.linkHREF; // string tit = message.linkName; //} private void OnBeforeNavigate(WebBrowserAPI.HtmlViewMessage message) { if (ShowWaitCursorWhileLoading) Cursor.Current = Cursors.WaitCursor; if (BeforeNavigate != null) { BeforeNavigate(message); } }
private void ViewWebBrowserDocumentComplete(WebBrowserAPI.HtmlViewMessage message) { ActivateMenuButtons(); ViewData["DocumentCompleteUrl"] = message.Url; OnViewStateChanged("DocumentCompleted"); }