BrowerWeb.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Windows.Forms;
  5. using System.Runtime.InteropServices;
  6. namespace US.Browser.IE
  7. {
  8. /// <summary>
  9. /// webbrower 封装
  10. /// </summary>
  11. public class BrowerWeb : WebIfaces
  12. {
  13. public BrowerWeb()
  14. : base()
  15. {
  16. }
  17. //WindowClosing 活动扩展
  18. public enum GETWINDOWCMD
  19. {
  20. GW_HWNDFIRST = 0,
  21. GW_HWNDLAST = 1,
  22. GW_HWNDNEXT = 2,
  23. GW_HWNDPREV = 3,
  24. GW_OWNER = 4,
  25. GW_CHILD = 5,
  26. GW_ENABLEDPOPUP = 6
  27. }
  28. [DllImport("user32.dll")]
  29. private static extern IntPtr GetWindow(IntPtr hWnd, GETWINDOWCMD uCmd);
  30. public event EventHandler WindowClosing;
  31. protected virtual void OnWindowClosing(EventArgs e)
  32. {
  33. if (WindowClosing != null)
  34. {
  35. WindowClosing(this, e);
  36. }
  37. }
  38. protected override void WndProc(ref System.Windows.Forms.Message m)
  39. {
  40. const Int32 WM_PARENTNOTIFY = 0x210;
  41. const Int32 WM_DESTROY = 0x2;
  42. if (m.Msg == WM_PARENTNOTIFY)
  43. {
  44. if (m.WParam.ToInt32() == WM_DESTROY)
  45. {
  46. if (m.LParam == GetWindow(this.Handle, GETWINDOWCMD.GW_CHILD))
  47. {
  48. EventArgs e = new EventArgs();
  49. OnWindowClosing(e);
  50. return;
  51. }
  52. }
  53. }
  54. base.WndProc(ref m);
  55. }
  56. }
  57. }