using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Reflection; namespace US.Browser.IE { [ComVisible(true)] public partial class News : Form { WebBrowser _UWB; RespondWeb _UPW; bool _UTF = true; #region /// /// 设置聚焦 /// /// protected override void WndProc(ref Message m) { if (m.Msg == BLL.WindowHWND.WM_MOUSEACTIVATE)//鼠标事件 { m.Result = new IntPtr(BLL.WindowHWND.MA_NOACTIVATE); _UTF = false; return; } else if (m.Msg == BLL.WindowHWND.WM_NCACTIVATE) //聚焦 { if (((int)m.WParam & 0xFFFF) != BLL.WindowHWND.WA_INACTIVE) { if (_UTF) { BLL.WindowHWND.SetActiveWindow(m.LParam); } _UTF = true; } } base.WndProc(ref m); } #endregion /// /// 初始化窗体 /// public News(BrowserDAO UBE) { _UPW = new RespondWeb(null, UBE); InitializeComponent(); InitBrower(); } /// /// 初始化窗体 /// void InitBrower() { this.Ne.Url = new System.Uri(Application.StartupPath + "\\html\\News.htm"); this.Ne.IsWebBrowserContextMenuEnabled = false; this.Ne.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(Ne_DocumentCompleted); this.Ne.ObjectForScripting = this; Ne.ScriptErrorsSuppressed = true; } /// /// 初始化成功 /// /// /// void Ne_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { if (this.Ne.ReadyState == WebBrowserReadyState.Complete && e.Url == this.Ne.Url) { string _id = GetId(); USMain.id = (_id == "" || _id == null) ? "11111111-1111-1111-1111-111111111111" : _id; } } /// /// 这里是传参交互 /// /// public void TFP(string Json, WebBrowser UWB, RespondWeb UPW) { if ((bool)this.Ne.Document.InvokeScript("Init", new object[] { Json })) { if (StaticClass.UCON != "Teacher") { init(false); } _UWB = UWB; _UPW = UPW; } } /// /// 消息消失 /// public void remove() { animate(true, 0, this); } /// /// 显示窗体出现 /// /// public void init(bool UTF) { if (this.Visible == false) { Point _UPE = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width - 20, Screen.PrimaryScreen.WorkingArea.Height - this.Height - 1); this.PointToScreen(_UPE); this.Location = _UPE; this.Opacity = 0; this.Visible = true; if (!UTF) { this.SendToBack(); } else { this.BringToFront(); } animate(false, 1, this); } else if (UTF) { this.BringToFront(); } } /// /// 动画函数 /// /// /// /// public static void animate(bool tf, int c, Form uf) { int i = 0; System.Windows.Forms.Timer _tt = new System.Windows.Forms.Timer(); double k = c == 0 ? -0.2 : 0.2; _tt.Tick += new EventHandler(delegate(object sender, EventArgs g) { uf.Opacity += k; if (i++ == 10) { _tt.Stop(); _tt.Dispose(); _tt = null; if (tf) { uf.Hide(); } }; }); _tt.Interval = 100; _tt.Start(); } /// /// 查看html内容 /// /// /// public void Look(string tf, string ue) { _UPW.OpenLook(new object[] { tf, ue }, null); } /// /// 获取ID /// /// public string GetId() { return (string)this.Ne.Document.InvokeScript("GetID"); } /// /// 设置最新Id /// public void SetId(string id) { USMain.id = id; } /// /// 拖动函数 /// public void Drag() { BLL.WindowHWND._Main_Drag(this); } } }