123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- 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
- /// <summary>
- /// 设置聚焦
- /// </summary>
- /// <param name="m"></param>
- 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
- /// <summary>
- /// 初始化窗体
- /// </summary>
- public News(BrowserDAO UBE)
- {
- _UPW = new RespondWeb(null, UBE); InitializeComponent(); InitBrower();
- }
- /// <summary>
- /// 初始化窗体
- /// </summary>
- 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;
- }
- /// <summary>
- /// 初始化成功
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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; }
- }
- /// <summary>
- /// 这里是传参交互
- /// </summary>
- /// <param name="Json"></param>
- 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;
- }
- }
- /// <summary>
- /// 消息消失
- /// </summary>
- public void remove()
- {
- animate(true, 0, this);
- }
- /// <summary>
- /// 显示窗体出现
- /// </summary>
- /// <param name="UJE"></param>
- 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(); }
- }
- /// <summary>
- /// 动画函数
- /// </summary>
- /// <param name="tf"></param>
- /// <param name="c"></param>
- /// <param name="uf"></param>
- 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();
- }
- /// <summary>
- /// 查看html内容
- /// </summary>
- /// <param name="tf"></param>
- /// <param name="ue"></param>
- public void Look(string tf, string ue)
- {
- _UPW.OpenLook(new object[] { tf, ue }, null);
- }
- /// <summary>
- /// 获取ID
- /// </summary>
- /// <returns></returns>
- public string GetId()
- {
- return (string)this.Ne.Document.InvokeScript("GetID");
- }
- /// <summary>
- /// 设置最新Id
- /// </summary>
- public void SetId(string id)
- {
- USMain.id = id;
- }
- /// <summary>
- /// 拖动函数
- /// </summary>
- public void Drag()
- {
- BLL.WindowHWND._Main_Drag(this);
- }
- }
- }
|