USMain.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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.Threading;
  9. using System.Runtime.InteropServices;
  10. using System.Reflection;
  11. using System.Security.Permissions;
  12. namespace US.Browser.IE
  13. {
  14. /// <summary>
  15. /// 窗体
  16. /// </summary>
  17. [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
  18. [ComVisibleAttribute(true)]
  19. public partial class USMain : skinform
  20. {
  21. private bool _TF = false;
  22. public static List<Form> _UFL = new List<Form>();//所有的//头部
  23. public BrowserDAO _USY;
  24. private WebBrowser USBrowserNav;
  25. public static string id = Guid.Empty.ToString();
  26. private System.Windows.Forms.Timer _UT = null;
  27. #region 初始化浏览器
  28. /// <summary>
  29. /// 无参构造
  30. /// </summary>
  31. public USMain()
  32. {
  33. InitializeComponent(); AddBS(); GetTZ(); ChangeUserAgent(" usestudio/" + StaticClass.ver + ";");//初始化导航页面
  34. _USY = new BrowserDAO(USBrowserNav, this); _UFL.Add(this); //确定使用的域和网站
  35. }
  36. #region webborser导航头部
  37. /// <summary>
  38. /// 初始化窗体处理
  39. /// </summary>
  40. private void AddBS()
  41. {
  42. int W = Screen.PrimaryScreen.WorkingArea.Width, H = Screen.PrimaryScreen.WorkingArea.Height; this.Width = W / 4 * 3; this.Height = H / 4 * 3;
  43. Point _UP = new Point((W - this.Width) / 2, (H - this.Height) / 2); this.PointToScreen(_UP); this.Location = _UP; this.Visible = false;
  44. USBrowserNav.ScriptErrorsSuppressed = true;
  45. USBrowserNav.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(USBrowserNav_DocumentCompleted);//加载完毕
  46. USBrowserNav.PreviewKeyDown += new PreviewKeyDownEventHandler(USBrowserNav_PreviewKeyDown);//键盘事件
  47. FVCBrower.ChangeBrower(USBrowserNav, new Point(3, 3), new Size(this.Size.Width - 6, 61), true);//初始化收藏夹
  48. USBrowserNav.Url = new System.Uri(Application.StartupPath + "\\html\\head.html");//导航头部使用的链接
  49. }
  50. /// <summary>
  51. /// 导航窗口加载完毕
  52. /// </summary>
  53. /// <param name="sender"></param>
  54. /// <param name="e"></param>
  55. void USBrowserNav_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { }
  56. /// <summary>
  57. /// 导航键盘事件
  58. /// </summary>
  59. /// <param name="sender"></param>
  60. /// <param name="e"></param>
  61. void USBrowserNav_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
  62. {
  63. int _UKY = e.KeyValue;
  64. if (_TF == true)
  65. {
  66. switch (_UKY)
  67. {
  68. case 116: e.IsInputKey = true; USBrowserNav.Document.InvokeScript("Refresh"); break;//刷新当前页面
  69. case 122: _USY.TYUWBF11(((WebBrowser)sender)); break;//窗口变化
  70. default: break;
  71. }
  72. }
  73. _TF = _TF == false ? true : false;
  74. }
  75. #endregion
  76. #endregion
  77. #region 功能区域
  78. /// <summary>
  79. /// 获取通知公告信息
  80. /// </summary>
  81. public void GetTZ()
  82. {
  83. System.Windows.Forms.Timer _tt = new System.Windows.Forms.Timer();
  84. _tt.Tick += new EventHandler(delegate(object sender, EventArgs g)
  85. {
  86. if (BLL.USIE.isnet())
  87. {
  88. BLL.USClientCommunicate.PostPage("http://main.1473.cn/Mian.ashx?functionname=pb.Publicpage", "POST", delegate(string ue) { if (ue.Length > 6) { this.Invoke(new MethodInvoker(delegate() { StaticClass._UNE.TFP(ue, null, this._USY._UVB); })); } }, "pb.Publicpage=", "099a06fe-073b-4426-aa20-7703aa94322e", "0", "10", "1", id);
  89. }
  90. });
  91. _tt.Interval = 60000; _tt.Start();
  92. }
  93. /// <summary>
  94. /// 修改UserAgent
  95. /// </summary>
  96. public static void ChangeUserAgent(string UAE)
  97. {
  98. string _USE = GetDefaultUserAgent() + UAE;
  99. BLL.WindowHWND.UrlMkSetSessionOption(BLL.WindowHWND.URLMON_OPTION_USERAGENT, _USE, _USE.Length, 0);
  100. }
  101. /// <summary>
  102. /// 获取IE默认UserAgent的方法
  103. /// </summary>
  104. private static string GetDefaultUserAgent()
  105. {
  106. using (WebBrowser UWB = new WebBrowser())
  107. {
  108. Type _UTP, _UTE; object _UW;
  109. UWB.Navigate("about:blank"); while (UWB.IsBusy) { Application.DoEvents(); } _UW = UWB.Document.Window.DomWindow;
  110. _UTP = _UW.GetType(); object _UNE = _UTP.InvokeMember("navigator", BindingFlags.GetProperty, null, _UW, new object[] { });
  111. _UTE = _UNE.GetType(); object _UAE = _UTE.InvokeMember("userAgent", BindingFlags.GetProperty, null, _UNE, new object[] { });
  112. return _UAE.ToString();
  113. }
  114. }
  115. #endregion
  116. #region 事件区域
  117. /// <summary>
  118. /// 窗体关闭
  119. /// </summary>
  120. /// <param name="sender"></param>
  121. /// <param name="e"></param>
  122. private void USMain_FormClosed(object sender, FormClosedEventArgs e) { StaticClass.CloseSoft(this); }
  123. /// <summary>
  124. /// 关闭窗体
  125. /// </summary>
  126. /// <param name="sender"></param>
  127. /// <param name="e"></param>
  128. void USMain_Disposed(object sender, EventArgs e)
  129. {
  130. StaticClass._USE.exit_Click(sender, e); base.Dispose();
  131. }
  132. /// <summary>
  133. /// 窗口大小变化
  134. /// </summary>
  135. /// <param name="sender"></param>
  136. /// <param name="e"></param>
  137. public void USMain_Resize(object sender, EventArgs e)
  138. {
  139. if (this.WindowState != FormWindowState.Minimized)//不在最小化窗体使用
  140. {
  141. try
  142. {
  143. SetStyle(ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true); this.Refresh();//页面重绘设置
  144. this._USY._UVB.DXBH(this._USY._UF.WindowState == FormWindowState.Maximized);//页面大小设置
  145. }
  146. catch { }
  147. }
  148. }
  149. void USMain_ResizeEnd(object sender, EventArgs e) { }
  150. void USMain_Shown(object sender, EventArgs e) { }
  151. /// <summary>
  152. /// 聚焦显示
  153. /// </summary>
  154. /// <param name="sender"></param>
  155. /// <param name="e"></param>
  156. void USMain_SizeChanged(object sender, EventArgs e)
  157. {
  158. if (StaticClass._UST.IndexOf("-background") == -1 && _UT == null)
  159. {
  160. Form _UF = (Form)sender;
  161. if (_UF.WindowState != FormWindowState.Minimized)
  162. {
  163. _UT = new System.Windows.Forms.Timer();
  164. _UT.Tick += new EventHandler(_UT_Tick);
  165. _UT.Interval = 1; _UT.Start();
  166. }
  167. }
  168. }
  169. /// <summary>
  170. /// 计时器
  171. /// </summary>
  172. /// <param name="sender"></param>me
  173. /// <param name="e"></param>
  174. void _UT_Tick(object sender, EventArgs e)
  175. {
  176. if (_UT != null)
  177. {
  178. _UT.Stop(); _UT.Dispose(); _UT = null;
  179. StaticClass._USE.Show_Click();
  180. }
  181. }
  182. /// <summary>
  183. /// 聚焦显示窗体
  184. /// </summary>
  185. /// <param name="sender"></param>
  186. /// <param name="e"></param>
  187. void USMain_GotFocus(object sender, EventArgs e)
  188. {
  189. if (!this.Visible && BLL.USIE.isnet())
  190. {
  191. if (StaticClass._UST.IndexOf("-background") == -1) { USMain_SizeChanged(sender, e); }
  192. }
  193. }
  194. #endregion
  195. #region 没用区域
  196. //if (((WebBrowser)sender).DocumentText == "") USBrowserNav.Navigate(System.IO.Path.GetFullPath("html/head.html"));
  197. //WebBrowser _UWB = BrowserDAO._UBL[0];
  198. //if (UURL == "Set") { new Respond_setting(_UWB); }
  199. //else { BrowserDAO.ModifyOneBrowser(BrowserDAO._UBL[0].Name, UURL); }
  200. //UURL = "";
  201. //if (_UKY == 116)//刷新当前页面
  202. //{
  203. //}
  204. //else if (_UKY == 122)//窗口变化
  205. //{
  206. // _USY.TYUWBF11(((WebBrowser)sender));
  207. // //Point? _UP = null;
  208. // //if (this.WindowState != FormWindowState.Maximized)
  209. // //{
  210. // // //if (this.WindowState == FormWindowState.Maximized) this.WindowState = FormWindowState.Normal;
  211. // // //_USY._UWB.Visible = false;//隐藏((WebBrowser)sender).Height
  212. // // _UP = new Point(2, 2);
  213. // // _USY._UVB.BSSZ(_UP, true);
  214. // //}
  215. // //else
  216. // //{
  217. // // _UP = new Point(2, ((WebBrowser)sender).Height - 2);
  218. // // _USY._UVB.BSSZ(_UP, false);
  219. // //}
  220. //}
  221. //try
  222. //{
  223. //USBrowserNav.Navigate(Application.StartupPath + "\\html\\head.html");
  224. //MessageBox.Show("yes");
  225. //}
  226. //catch (Exception e) { MessageBox.Show(e.Message); }
  227. //[System.Runtime.InteropServices.DllImport("user32.dll")]
  228. //public static extern int PostMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
  229. //public const int WM_CLOSE = 0x10;
  230. //public const int SC_MOVE = 0xF010;//该变量表示发送消息的附加消息
  231. //public const int HTCAPTION = 0x0002;
  232. //public void LS()
  233. //{
  234. // //Message M = Message.Create(this.Handle, 0, new IntPtr(0), new IntPtr(0));
  235. // //M.Result = new IntPtr(HT_BOTTOMRIGHT);
  236. // Point screenPoint = Control.MousePosition;
  237. // PostMessage(this.Handle, WM_NCHITTEST, 0, 21299350);
  238. // //Message.Create(new IntPtr(HT_BOTTOMRIGHT),WM_NCHITTEST,
  239. // //Message.Result = ;
  240. //}
  241. //private void MainForm_Resize(object sender, EventArgs e)
  242. //{
  243. //}
  244. //[DllImport("user32.dll")]
  245. //public static extern bool ReleaseCapture();//系统接口
  246. //public const int HWND_BROADCAST = 0xFFFF;
  247. //public const int WM_FONTCHANGE = 0x1D;
  248. //[DllImport("user32.dll")]
  249. //public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
  250. //public static int WM_SYSCOMMAND = 0x0112;
  251. //public static int SC_MOVE = 0xF010;
  252. //public static int HTCAPTION = 0x0002;
  253. //protected override CreateParams CreateParams
  254. //{
  255. // get
  256. // {
  257. // CreateParams cp = base.CreateParams;
  258. // cp.Style |= 0xC0000 + 0x20000;
  259. // return cp;
  260. // }
  261. //}
  262. //private void Server_MouseMove(object sender, MouseEventArgs e)
  263. //{
  264. // ReleaseCapture();
  265. // SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
  266. //}
  267. //private void USBrowserNav_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
  268. //{
  269. // if (this.keypressed)
  270. // {
  271. // this.keypressed = false;
  272. // return;
  273. // }
  274. // switch (e.KeyCode)
  275. // {
  276. // case Keys.F5:
  277. // e.IsInputKey = true;
  278. // this.USBrowserNav.Document.InvokeScript("Refresh");
  279. // break;
  280. // case Keys.F11:
  281. // if (this.WindowState == FormWindowState.Normal)
  282. // {
  283. // this.WindowState = FormWindowState.Maximized;
  284. // }
  285. // else if (this.WindowState == FormWindowState.Maximized)
  286. // {
  287. // this.WindowState = FormWindowState.Normal;
  288. // }
  289. // WebBrowser wb = (WebBrowser)_broDao.BrowserList[0];
  290. // if (this.USBrowserNav.Dock == DockStyle.Top)
  291. // {
  292. // this.USBrowserNav.Visible = false;
  293. // a.Dock = DockStyle.Fill;
  294. // a.Document.Focus();
  295. // }
  296. // else
  297. // {
  298. // this.USBrowserNav.Visible = true;
  299. // WebBrowser a = (WebBrowser)_broDao.BrowserList[0];
  300. // a.Dock = DockStyle.None;
  301. // a.Width = this.ClientRectangle.Width - 1;
  302. // a.Height = (this.ClientRectangle.Height - 1) - this.USBrowserNav.Height;
  303. // }
  304. // break;
  305. // }
  306. // this.keypressed = true;
  307. //}
  308. //private void USMain_MouseDown(object sender, MouseEventArgs e)
  309. //{
  310. // isMouseDown = true;//表示鼠标按下了
  311. //}
  312. //private void USMain_MouseUp(object sender, MouseEventArgs e)
  313. //{
  314. // isMouseDown = false;//松开鼠标的时候 鼠标状态变回false
  315. // direction = MouseDirection.None;//鼠标松开的时候不做任何的拖动
  316. //}
  317. //public void ResizeWindow()//窗体的拉伸
  318. //{
  319. // if (!isMouseDown) return;//表示只有鼠标按下的时候才能拉伸窗体
  320. // if (direction == MouseDirection.Declining)
  321. // {
  322. // this.Cursor = Cursors.SizeNWSE;
  323. // this.Width = MousePosition.X - this.Left;
  324. // this.Height = MousePosition.Y - this.Top;
  325. // }
  326. // if (direction == MouseDirection.Herizontal)
  327. // {
  328. // this.Cursor = Cursors.SizeWE;
  329. // this.Width = MousePosition.X - this.Left;
  330. // }
  331. // else if (direction == MouseDirection.vertical)
  332. // {
  333. // this.Cursor = Cursors.SizeNS;
  334. // this.Height = MousePosition.Y - this.Top;
  335. // }
  336. // else
  337. // {
  338. // this.Cursor = Cursors.Arrow;
  339. // }
  340. //}
  341. //private void USMain_MouseMove(object sender, MouseEventArgs e)//鼠标的样式,表示鼠标移动到form窗体边缘的时候 改变鼠标的样式
  342. //{
  343. // ResizeWindow();
  344. // if (e.Location.X >= this.Width - 5 && e.Location.Y > this.Height - 5)//右边以及下面的form边缘
  345. // {
  346. // this.Cursor = Cursors.SizeNWSE;
  347. // direction = MouseDirection.Declining;
  348. // }
  349. // else if (e.Location.X >= this.Width - 5)//窗体右边的时候进行拉伸
  350. // {
  351. // this.Cursor = Cursors.SizeWE;
  352. // direction = MouseDirection.Herizontal;
  353. // }
  354. // else if (e.Location.Y >= this.Height - 5)//窗体下面的时候
  355. // {
  356. // this.Cursor = Cursors.SizeNS;
  357. // direction = MouseDirection.vertical;
  358. // }
  359. // else
  360. // {
  361. // this.Cursor = Cursors.Arrow;
  362. // }
  363. //}
  364. #endregion
  365. }
  366. }