News.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Runtime.InteropServices;
  9. using System.Reflection;
  10. namespace US.Browser.IE
  11. {
  12. [ComVisible(true)]
  13. public partial class News : Form
  14. {
  15. WebBrowser _UWB; RespondWeb _UPW;
  16. bool _UTF = true;
  17. #region
  18. /// <summary>
  19. /// 设置聚焦
  20. /// </summary>
  21. /// <param name="m"></param>
  22. protected override void WndProc(ref Message m)
  23. {
  24. if (m.Msg == BLL.WindowHWND.WM_MOUSEACTIVATE)//鼠标事件
  25. {
  26. m.Result = new IntPtr(BLL.WindowHWND.MA_NOACTIVATE);
  27. _UTF = false; return;
  28. }
  29. else if (m.Msg == BLL.WindowHWND.WM_NCACTIVATE) //聚焦
  30. {
  31. if (((int)m.WParam & 0xFFFF) != BLL.WindowHWND.WA_INACTIVE)
  32. {
  33. if (_UTF) { BLL.WindowHWND.SetActiveWindow(m.LParam); } _UTF = true;
  34. }
  35. }
  36. base.WndProc(ref m);
  37. }
  38. #endregion
  39. /// <summary>
  40. /// 初始化窗体
  41. /// </summary>
  42. public News(BrowserDAO UBE)
  43. {
  44. _UPW = new RespondWeb(null, UBE); InitializeComponent(); InitBrower();
  45. }
  46. /// <summary>
  47. /// 初始化窗体
  48. /// </summary>
  49. void InitBrower()
  50. {
  51. this.Ne.Url = new System.Uri(Application.StartupPath + "\\html\\News.htm"); this.Ne.IsWebBrowserContextMenuEnabled = false;
  52. this.Ne.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(Ne_DocumentCompleted);
  53. this.Ne.ObjectForScripting = this; Ne.ScriptErrorsSuppressed = true;
  54. }
  55. /// <summary>
  56. /// 初始化成功
  57. /// </summary>
  58. /// <param name="sender"></param>
  59. /// <param name="e"></param>
  60. void Ne_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
  61. {
  62. 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; }
  63. }
  64. /// <summary>
  65. /// 这里是传参交互
  66. /// </summary>
  67. /// <param name="Json"></param>
  68. public void TFP(string Json, WebBrowser UWB, RespondWeb UPW)
  69. {
  70. if ((bool)this.Ne.Document.InvokeScript("Init", new object[] { Json }))
  71. {
  72. if (StaticClass.UCON != "Teacher") { init(false); }
  73. _UWB = UWB; _UPW = UPW;
  74. }
  75. }
  76. /// <summary>
  77. /// 消息消失
  78. /// </summary>
  79. public void remove()
  80. {
  81. animate(true, 0, this);
  82. }
  83. /// <summary>
  84. /// 显示窗体出现
  85. /// </summary>
  86. /// <param name="UJE"></param>
  87. public void init(bool UTF)
  88. {
  89. if (this.Visible == false)
  90. {
  91. Point _UPE = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width - 20, Screen.PrimaryScreen.WorkingArea.Height - this.Height - 1);
  92. this.PointToScreen(_UPE); this.Location = _UPE; this.Opacity = 0; this.Visible = true; if (!UTF) { this.SendToBack(); } else { this.BringToFront(); } animate(false, 1, this);
  93. }
  94. else if (UTF) { this.BringToFront(); }
  95. }
  96. /// <summary>
  97. /// 动画函数
  98. /// </summary>
  99. /// <param name="tf"></param>
  100. /// <param name="c"></param>
  101. /// <param name="uf"></param>
  102. public static void animate(bool tf, int c, Form uf)
  103. {
  104. int i = 0; System.Windows.Forms.Timer _tt = new System.Windows.Forms.Timer(); double k = c == 0 ? -0.2 : 0.2;
  105. _tt.Tick += new EventHandler(delegate(object sender, EventArgs g)
  106. {
  107. uf.Opacity += k;
  108. if (i++ == 10) { _tt.Stop(); _tt.Dispose(); _tt = null; if (tf) { uf.Hide(); } };
  109. });
  110. _tt.Interval = 100; _tt.Start();
  111. }
  112. /// <summary>
  113. /// 查看html内容
  114. /// </summary>
  115. /// <param name="tf"></param>
  116. /// <param name="ue"></param>
  117. public void Look(string tf, string ue)
  118. {
  119. _UPW.OpenLook(new object[] { tf, ue }, null);
  120. }
  121. /// <summary>
  122. /// 获取ID
  123. /// </summary>
  124. /// <returns></returns>
  125. public string GetId()
  126. {
  127. return (string)this.Ne.Document.InvokeScript("GetID");
  128. }
  129. /// <summary>
  130. /// 设置最新Id
  131. /// </summary>
  132. public void SetId(string id)
  133. {
  134. USMain.id = id;
  135. }
  136. /// <summary>
  137. /// 拖动函数
  138. /// </summary>
  139. public void Drag()
  140. {
  141. BLL.WindowHWND._Main_Drag(this);
  142. }
  143. }
  144. }