using System; using System.Collections.Generic; using System.Text; using System.Security.Permissions; using System.Windows.Forms; using System.Drawing; using System.Runtime.InteropServices; using System.Threading; using System.Text.RegularExpressions; using US.Browser.IE.BLL; using System.Reflection; namespace US.Browser.IE { /// /// 功能接口区域 /// [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] [System.Runtime.InteropServices.ComVisibleAttribute(true)] public class RespondWeb { public BrowserDAO _UBF; public WebBrowser UB; /// /// 无参数构造 /// public RespondWeb() { } /// /// 页面初始化 /// /// public RespondWeb(WebBrowser WB, BrowserDAO uba) { this.UB = WB; _UBF = uba; } /// /// 构造函数 此类设置为窗口功能区域 /// public RespondWeb(BrowserDAO _USY, FVCBrower _UTV) { _UBF = _USY; try { _USY._UWB.ObjectForScripting = this; } catch (Exception e) { } } #region 操作收藏夹 /// /// 打开添加收藏控件窗体 /// /// public void OpenAddFVC(int ITF) { WebBrowser BL = this._UBF._UBL[ITF]; this._UBF._UFV.OpenAddFVC(BL); } /// /// 打开收藏列表 /// public void OpenFV(int ITF) { this._UBF._UFV.OpenFV(this._UBF._UBL[ITF]); } #endregion #region 页面操作 /// /// 新建窗口 /// /// /// public bool AddABrowser(string UURL, string UN, bool UTF) { WebBrowser _WB = this._UBF.AddBrowser(UURL, UN); if (this._UBF._UBL.Count > 1) { SetWindow(); } return true; } /// /// 获取指定的路径 /// public string GetLJ() { return Application.StartupPath + "\\html"; } /// /// 跳转谷歌 /// /// /// public string WysGoogle(string _thisURL) { string g = "http://g.helloit.info/"; if (Regex.Match(_thisURL.ToLower(), "google").Success) { return g; } return _thisURL; } //声明委托 public delegate void AsyncEventHandler(string UURL, string UN); /// /// 载入网址 /// /// /// public void LoadUrl(string UURL, string UN) { AsyncEventHandler asy = new AsyncEventHandler(ZR); IAsyncResult ia = asy.BeginInvoke(UURL, UN, null, null); } /// /// 异步获取 /// public void ZR(string UURL, string UN) { int i = 0; bool _UTF = USIE.MyPing(UURL, out i); this._UBF._UF.Invoke(new Action(delegate(string a) { this._UBF.ModifyOneBrowser(UN, WysGoogle(UURL == "" ? "http://seo.1473.cn/Client/taobao.html" : UURL)); }), ""); } /// /// 获取更新 /// public string GetGX() { return USClientCommunicate.GetPage("http://seo.1473.cn/Client/ver.txt"); } /// /// 获取当前浏览器版本号 /// /// public string IsGX() { return StaticClass.ver; } /// /// 上一页 /// /// public void Previous(string UN) { this._UBF.FindBrowser(UN).GoBack(); } /// /// 上一页 /// /// public void Next(string UN) { this._UBF.FindBrowser(UN).GoForward(); } /// /// 刷新 /// /// public void Refresh(string UN) { WebBrowser _UWB = this._UBF.FindBrowser(UN); BLL.WindowHWND.freem(); _UWB.Url = new Uri(_UWB.Url.ToString()); // _UWB.Refresh(); } /// /// 加载主页 /// /// public void LoadHome(string UN) { this.LoadUrl(System.IO.Path.GetFullPath("html/blank.html"), UN); } /// /// 生成页面的信息 /// /// /// public string SV(string UN) { return this._UBF.BrowserToJson(this._UBF.FindBrowser(UN), false); } #endregion #region 页面功能区域 /// /// 设置 /// public void Setup() { this._UBF.RS.SetProxy(); } /// /// 清除IE的缓存 /// public void clean() { USIE.CMD("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255"); } /// /// 停止加载 /// /// public void Stop(string UN) { this._UBF.FindBrowser(UN).Stop(); } /// /// 关闭一个浏览器 /// /// /// public bool CloseOneBrowser(string UN) { this._UBF.CloseOneBrowser(UN); return true; } /// /// 关闭窗体 /// public void CloseForm() { this._UBF._UF.Hide(); BLL.WindowHWND.freem(); } /// /// 新建窗体 /// /// public void NewForm(string UURL) { StaticClass.getInstance(); } /// /// 设置可见,将选中的browser可见,其余隐藏 /// /// public bool SetVisible(string UN) { int i; WebBrowser _UWB = _UBF.FindBrowser(UN); List _UBL = this._UBF._UBL; for (i = 0; i < _UBL.Count; i++) { _UWB = _UBL[i]; if (_UBL[i].Name == UN) { _UWB.Visible = true; if (_UWB.Document != null) { _UWB.Document.Window.Focus(); } } else { _UBL[i].Visible = false; } } BLL.WindowHWND.freem(); return true; } /// /// 显示的窗体聚焦 /// public void fouscwindow() { int i; List _UBL = this._UBF._UBL; for (i = 0; i < _UBL.Count; i++) { if (_UBL[i].Visible == true && _UBL[i].Document != null) { _UBL[i].Document.Window.Focus(); } } } /// /// 打开查看1473内容 /// public void OpenLook(object[] UDE, WebBrowser _UWB) { try { WebBrowser _UBE = _UWB != null ? _UWB : GetWebBrowser("http://www.1473.cn"); VisibleBrowser(_UBE); if (_UBE.Document == null) { DocCompleted _UTE = new DocCompleted(); _UTE.UDE = UDE; _UBE.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(_UTE._UBE_DocumentCompleted); } else { _UBE.Document.InvokeScript("YDHJH", UDE); } } catch (Exception e) { } } /// /// 加载完毕 /// public class DocCompleted { public object[] UDE; /// /// 加载完毕 /// /// /// public void _UBE_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { WebBrowser _UBW = (WebBrowser)sender; if (_UBW.ReadyState == WebBrowserReadyState.Complete && e.Url == _UBW.Url) { _UBW.DocumentCompleted -= new WebBrowserDocumentCompletedEventHandler(_UBE_DocumentCompleted); _UBW.Document.InvokeScript("YDHJH", UDE); UDE = null; } } } /// /// 获取指定域名下的webbrower /// /// public WebBrowser GetWebBrowser(string URL) { WebBrowser _UWB = this._UBF.FindWebUrl(URL); string _UN = Guid.NewGuid().ToString(); if (_UWB == null) { this._UBF._UWB.Document.InvokeScript("_addTag", new object[] { URL, _UN }); _UWB = this._UBF.FindBrowser("a" + _UN); } return _UWB; } /// /// 设置webrower可见 /// /// public void VisibleBrowser(WebBrowser UW) { bool _UTF; int i; List _UBL = this._UBF._UBL; Form _UFE = this._UBF._UF; for (i = 0; i < _UBL.Count; i++) { _UTF = UW == _UBL[i]; _UBL[i].Visible = _UTF; if (_UTF && _UBL[i].Document != null) { _UBL[i].Document.Window.Focus(); } } this._UBF._UF.Show(); if (this._UBF._UF.WindowState == FormWindowState.Minimized) { this._UBF._UF.WindowState = FormWindowState.Normal; } this._UBF._UF.BringToFront(); } /// /// 闪烁消息查看 /// public void ftpshow(string json) { ftp ff = new ftp(json, UB, this); } /// /// 取消闪烁消息 /// public void QXftpshow() { StaticClass._twstop(); StaticClass._USE.USIcon.MouseClick -= StaticClass._ume; } /// /// 消息查看 /// /// public void news(string json) { StaticClass._UNE.TFP(json, this.UB, this); } /// /// 取消消息查看 /// public void removenew() { StaticClass._UNE.remove(); } #endregion #region 设置页面大小变化 /// /// 设置窗体可见 /// public void SetWindow() { Form _UFE = this._UBF._UF; _UFE.Show(); if (_UFE.WindowState == FormWindowState.Minimized || _UFE.Visible == false) { _UFE.WindowState = FormWindowState.Normal; _UFE.Location = new Point((Screen.PrimaryScreen.WorkingArea.Width - _UFE.Width) / 2, (Screen.PrimaryScreen.WorkingArea.Height - _UFE.Height) / 2); } } /// /// 只显示网页部分 /// public void BigScreen() { this._UBF.TYUWBF11((WebBrowser)_UBF._UWB); } /// /// 设置全屏和缩小 /// public bool FormMaximized() { Form _UF = this._UBF._UF; if (_UF.WindowState == FormWindowState.Maximized)//全屏缩小 { _UF.WindowState = FormWindowState.Normal; BLL.WindowHWND.freem(); return false; } else//全屏 { _UF.MaximumSize = Screen.PrimaryScreen.WorkingArea.Size; _UF.WindowState = FormWindowState.Maximized; return true; } } /// /// 最小化 /// public void FormMinimized() { StaticClass._USE.Visible = true; this._UBF._UF.WindowState = FormWindowState.Minimized; } /// /// 窗体变大 /// public void Larger() { Rectangle _UDX = _UBF._UF.DesktopBounds, _USZ = System.Windows.Forms.Screen.GetWorkingArea(new Point(0, 0)); if (_USZ.Width == _UDX.Width && _USZ.Height == _USZ.Height) { _UBF._UF.Location = new Point(100, 100); _UBF._UF.Size = new Size(1064, 600); } else { _UBF._UF.DesktopBounds = _USZ; } } /// /// 最大化和原大小 /// public void DFullS() { bool FSTF = FormMaximized();//设置到制定大小 DXBH(FSTF);//大小变化 } /// /// 设置大小变化 /// /// public void DXBH(bool tf) { Point? _UPt, _TPt; Size? _UPs, _TPs; int[] i = new int[] { tf ? 0 : 2, tf ? 0 : 4 }; _TPt = new Point(i[0], i[0]); _UPt = new Point(i[0], _UBF._UWB.Height + i[0]);//webbrower位置 _TPs = new Size(_UBF._UF.Width - i[1], _UBF._UWB.Height); _UPs = new Size(_UBF._UF.Width - i[1], _UBF._UF.Height - _UBF._UWB.Height - i[1]);//头和内容webbrower大小 BSSZ(_UPt, _TPt, _UPs, _TPs);//设置大小 } /// /// 窗口里大小和位置定位 /// /// /// public void BSSZ(Point? UTY, Point? TTY, Size? UTS, Size? TTS) { CWB(UTY, UTS); TopWBF11(TTY, TTS); } /// /// 里面的webbrower修改大小 /// /// /// public void CWB(Point? TY, Size? _UBP) { int i; List _UL = this._UBF._UBL; WebBrowser _UWB; for (i = 0; i < _UL.Count; i++) { _UWB = _UL[i]; FVCBrower.ChangeBrower(_UWB, TY, _UBP, true); } } /// /// 头部F11设置 /// /// /// private void TopWBF11(Point? _TopBL, Size? _ts) { FVCBrower.ChangeBrower((WebBrowser)_UBF._UWB, _TopBL, _ts, false); } /// /// 全屏后鼠标移动效果 /// /// public void WYDC(bool TF) { WebBrowser _TopWB = _UBF._UWB; if (_TopWB.Location.Y == -35) if (TF) _TopWB.BringToFront(); else _TopWB.SendToBack(); } #endregion #region 窗口拖动 //窗体拖动 [DllImport("user32.dll")] public static extern bool ReleaseCapture();//API函数 public const int WM_SYSCOMMAND = 0x0112;//该变量表示将向Windows发送消息的类型 public const int SC_MOVE = 0xF010;//该变量表示发送消息的附加消息 public const int HTCAPTION = 0x0002; [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] static extern IntPtr PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); [DllImport("user32.dll", SetLastError = true)] static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd); [DllImport("user32.dll", CharSet = CharSet.Auto)] static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount); /// /// 拖动 /// public void _Main_Drag() { ReleaseCapture();//该函数从当前线程中释放鼠标捕获事件,并恢复鼠标输入处理 IntPtr _e = SendMessage(_UBF._UF.Handle, WM_SYSCOMMAND, (IntPtr)(SC_MOVE + HTCAPTION), IntPtr.Zero); } /// /// 窗体拖动后使用 /// /// /// public void WBSJ(int x, int y) { IntPtr handle = _UBF._UWB.Handle; StringBuilder className = new StringBuilder(100); while (className.ToString() != "Internet Explorer_Server") { handle = GetWindow(handle, 5); GetClassName(handle, className, className.Capacity); } const uint upCode = 0x202; PostMessage(handle, upCode, IntPtr.Zero, (IntPtr)((y << 16) | x)); } #endregion #region 没用的函数 //public string AddFV(string FVC, string FVH, string CID, string UID) //{ // string a = US.Browser.IE.BLL.USClientCommunicate.PostPage("http://collect.1473.cn:1334", "POST", "mode=", "UseBE_AddFV", "{ UID:'" + UID + "',CateID:'" + CID + "',href:'" + FVH + "',herfc:'" + FVC + "'}"); // return a; //} /// /// 一直全屏z /// //public void YZQP(Point? WZ) //{ // Form _UF = _UBF._UF; List _WL = _UBF._UBL; WebBrowser _TWB; int i; // _UF.WindowState = FormWindowState.Maximized; // if (WZ != null) // { // for (i = 0; i < _WL.Count; i++) // { // if ((_TWB = _WL[i]).Visible == false) continue; // FVCBrower.ChangeBrower(_TWB, WZ, new Size(_TWB.Width, _UBF._UF.Height - 4), true); // } // } //} // /// e ///// 响应web对form的请求 ///// //[PermissionSet(SecurityAction.Demand, Name = "FullTrust")] //[System.Runtime.InteropServices.ComVisibleAttribute(true)] //private BrowserDAO _browserDao; //private FVCBrower _fvcBrower; //bool fullScreen = false; //设置窗体一开始的状态 ///// ///// 构造函数 ///// ///// 请求的WebBrowser ///// 窗体 //public RespondWeb(BrowserDAO broDao, FVCBrower FB) //{ // this._browserDao = broDao; // this._fvcBrower = FB; // try // { // this._browserDao._webBrowser.ObjectForScripting = this; // } // catch (Exception e) // { // MessageBox.Show(e.ToString(), "错误"); // } //} ////打开添加收藏控件窗体 //public void OpenAddFVC(int i) //{ // WebBrowser BL = (WebBrowser)_browserDao.BrowserList[i]; // _fvcBrower.OpenAddFVC(BL); //} ////打开收藏列表 //public void OpenFV() //{ // _fvcBrower.OpenFV(); //} ///*被动对主窗体的动作*/ ////新建窗体 //public void AddABrowser(string url, string name) //{ // _browserDao.AddBrowser(url, name); // //if (WaitWebPageLoad((WebBrowser)_browserDao.BrowserList[_browserDao.BrowserList.Count - 1])) // //string name = ((WebBrowser)_browserDao.BrowserList[_browserDao.BrowserList.Count - 1]).Name; // //return _browserDao.BrowserToJson(name); //} ////载入网址 //public void LoadUrl(string url, string name) //{ // _browserDao.ModifyOneBrowser(name, url); //} ////上一页 //public void Previous(string name) //{ // _browserDao.FindBrowser(name).GoBack(); //} ////下一页 //public void Next(string name) //{ // _browserDao.FindBrowser(name).GoForward(); //} ////刷新 //public void Refresh(string name) //{ // _browserDao.FindBrowser(name).Refresh(); //} ////加载主页 //public void LoadHome(string name) //{ // this.LoadUrl(System.IO.Path.GetFullPath("html/blank.html"), name); //} ////设置 //public void Setup() //{ // //StaticClass.LoadUrl = System.IO.Path.GetFullPath("html/setting.html"); // StaticClass.urlType = "setting"; // this.NewForm(System.IO.Path.GetFullPath("html/setting.html")); //} ////停止加载 //public void Stop(string name) //{ // _browserDao.FindBrowser(name).Stop(); //} ////关闭一个浏览器控件 //public bool CloseOneBrowser(string name) //{ // _browserDao.CloseOneBrowser(name); // return true; //} ////最大化 //public void FormMaximized() //{ // if (this._browserDao.form.WindowState == FormWindowState.Normal) // { // this._browserDao.form.WindowState = FormWindowState.Maximized; // } // else if (this._browserDao.form.WindowState == FormWindowState.Maximized) // { // this._browserDao.form.WindowState = FormWindowState.Normal; // } //} ////最小化 //public void FormMinimized() //{ // this._browserDao.form.WindowState = FormWindowState.Minimized; //} ////关闭窗体 //public void CloseForm() //{ // //this._browserDao.form.Close(); // this._browserDao.form.Hide(); //} ////新建窗体 //public void NewForm(string url) //{ // StaticClass.LoadUrl = url; // StaticClass.getInstance(); //} ///// ///// 设置可见,将选中的browser可见,其余隐藏 ///// ///// //public bool SetVisible(String name) //{ // WebBrowser WB = new WebBrowser(); // try // { // foreach (WebBrowser wb in _browserDao.BrowserList) // { // wb.Visible = false; // if (wb.Name == name) // { // wb.Visible = true; // WB = wb; // continue; // } // } // } // catch { Thread.Sleep(150); WB.Document.Focus(); } // return true; //} //public static void SetTimeout(double interval, Action action) //{ // System.Timers.Timer timer = new System.Timers.Timer(interval); // timer.Elapsed += delegate(object sender, System.Timers.ElapsedEventArgs e) // { // timer.Enabled = false; // action(); // }; // timer.Enabled = true; //} ///// ///// 右键菜单 ///// ////public void ContextMenuStrip(string name) ////{ //// this._browserDao._broStrip.Show(1); //// this._browserDao._broStrip._respndStrip._borwserName = name; ////} ///// ///// 隐藏右键菜单 ///// ////public void HiddenContextMenuStrip() ////{ //// this._browserDao._broStrip.Hidden(); ////} ////窗体变大 //public void Larger() //{ // fullScreen = !fullScreen; // if (fullScreen) // { // this._browserDao.form.DesktopBounds = System.Windows.Forms.Screen.GetWorkingArea(new Point(0, 0));//获取或设置window桌面上的的大小和位置 // } // else // { // this._browserDao.form.Location = new Point(100, 100);//设置窗体变小之后位置 // this._browserDao.form.Size = new Size(1064, 600);//设置窗体变小之后大小 // } //} //public void FullScreen() //{ // if (this._browserDao.form.WindowState == FormWindowState.Normal) // { // this._browserDao.form.FormBorderStyle = FormBorderStyle.None; // this._browserDao.form.WindowState = FormWindowState.Maximized; // } // else if (this._browserDao.form.WindowState == FormWindowState.Maximized) // { // if (this._browserDao.form.FormBorderStyle == FormBorderStyle.Sizable) // { // this._browserDao.form.FormBorderStyle = FormBorderStyle.None; // this._browserDao.form.WindowState = FormWindowState.Normal; // this._browserDao.form.WindowState = FormWindowState.Maximized; // } // else // { // this._browserDao.form.FormBorderStyle = FormBorderStyle.Sizable; // this._browserDao.form.WindowState = FormWindowState.Normal; // } // } //}//全屏 //public void BigScreen() //{ // int i; // WebBrowser temp = new WebBrowser(); // Button _Quit = new Button(); // temp = (WebBrowser)US.Browser.IE.USMain.formList[0].Controls.Find("USBrowserNav", true)[0];//获取窗体上的控件 // temp.MinimumSize = new Size(1064, 0); // temp.Size = new Size(1064, 0); // for (i = 0; i < _browserDao.BrowserList.Count; i++) // { // WebBrowser a = new WebBrowser(); // a = (WebBrowser)_browserDao.BrowserList[i]; // a.Location = new Point(0, 0); // a.Size = new Size(1064, a.Size.Height + 65); // } // FullScreen(); // //_Quit.Location = new Point(0, 0); // //_Quit.Visible = true; //}//只显示网页的部分,上面的WebBrowser不要了 ////窗体拖动 //[DllImport("user32.dll")] //public static extern bool ReleaseCapture();//API函数 //[DllImport("user32.dll")] //public static extern bool SendMessage(IntPtr hwdn, int wMsg, int mParam, int lParam);//接受发送来的消息 并处理 //public const int WM_SYSCOMMAND = 0x0112;//该变量表示将向Windows发送消息的类型 //public const int SC_MOVE = 0xF010;//该变量表示发送消息的附加消息 //public const int HTCAPTION = 0x0002; //public void _Main_Drag() //{ // ReleaseCapture();//该函数从当前线程中释放鼠标捕获事件,并恢复鼠标输入处理 // SendMessage(this._browserDao.form.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); //} #endregion } }