vb.net WPF webbrowser window.close 关闭后不触发 WindowClosing 事件 WNDPROC解决方案

前端之家收集整理的这篇文章主要介绍了vb.net WPF webbrowser window.close 关闭后不触发 WindowClosing 事件 WNDPROC解决方案前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


vb.net WPF webbrowser window.close 关闭后不触发 WindowClosing 事件 WNDPROC解决方


  1. #Region "WPF 当浏览器窗口关闭时触发 Quit事件 "
  2.  
  3. #If OnSourceInitialized Then
  4. Protected Overrides Sub OnSourceInitialized(e As EventArgs) 'onload 等句柄创建后引用WSInitialized(Me,e)
  5. WSInitialized(Me,e)
  6. MyBase.OnSourceInitialized(e)
  7. End Sub
  8. #Else
  9.  
  10. Private Sub LyWebTabItem_Loaded(sender As Object,e As RoutedEventArgs) Handles Me.Loaded
  11. WSInitialized(sender,e)
  12. End Sub
  13. #End If
  14.  
  15. Sub WSInitialized(sender As Object,e As EventArgs)
  16. Dim hs As HwndSource = PresentationSource.FromVisual(Me) '=HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
  17. hs.AddHook(New HwndSourceHook(AddressOf WndProc))
  18. End Sub
  19.  
  20. ''' <summary>
  21. ''' Overridden
  22. ''' </summary>
  23. ''' <param name="m">The <see cref="Message"/> send to this procedure</param>
  24. <PermissionSet(SecurityAction.LinkDemand,Name:="FullTrust")> _
  25. Protected Overloads Function WndProc(hwnd As IntPtr,msg As Int32,wParam As IntPtr,lParam As IntPtr,ByRef handled As Boolean) As IntPtr '(ByRef m As Forms.Message)
  26. 'Protected Overloads sub WndProc((ByRef m As Forms.Message)) 'winform方式
  27. 'If m.Msg = DirectCast(WindowsMessages.WM_PARENTNOTIFY,Integer) Then
  28. If msg = DirectCast(WindowsMessages.WM_PARENTNOTIFY,Integer) Then
  29. 'int lp = m.LParam.ToInt32();
  30. 'Dim wp As Integer = m.WParam.ToInt32()
  31. Dim wp As Integer = wParam.ToInt32()
  32.  
  33. Dim X As Integer = wp And &HFFFF
  34. 'int Y = (wp >> 16) & 0xFFFF;
  35. If X = DirectCast(WindowsMessages.WM_DESTROY,Integer) Then
  36. Me.OnQuit()
  37. End If
  38. End If
  39. Return IntPtr.Zero
  40. 'MyBase.WndProc(m)
  41. End Function
  42. ''' <summary>
  43. ''' A list of all the available window messages
  44. ''' </summary>
  45. Enum WindowsMessages
  46. WM_ACTIVATE = &H6
  47. WM_ACTIVATEAPP = &H1C
  48. WM_AFXFIRST = &H360
  49. WM_AFXLAST = &H37F
  50. WM_APP = &H8000
  51. WM_ASKCBFORMATNAME = &H30C
  52. WM_CANCELJOURNAL = &H4B
  53. WM_CANCELMODE = &H1F
  54. WM_CAPTURECHANGED = &H215
  55. WM_CHANGECBCHAIN = &H30D
  56. WM_CHAR = &H102
  57. WM_CHARTOITEM = &H2F
  58. WM_CHILDACTIVATE = &H22
  59. WM_CLEAR = &H303
  60. WM_CLOSE = &H10
  61. WM_COMMAND = &H111
  62. WM_COMPACTING = &H41
  63. WM_COMPAREITEM = &H39
  64. WM_CONTEXTMENU = &H7B
  65. WM_COPY = &H301
  66. WM_COPYDATA = &H4A
  67. WM_CREATE = &H1
  68. WM_CTLCOLORBTN = &H135
  69. WM_CTLCOLORDLG = &H136
  70. WM_CTLCOLOREDIT = &H133
  71. WM_CTLCOLORLISTBox = &H134
  72. WM_CTLCOLORMSGBox = &H132
  73. WM_CTLCOLORSCROLLBAR = &H137
  74. WM_CTLCOLORSTATIC = &H138
  75. WM_CUT = &H300
  76. WM_DEADCHAR = &H103
  77. WM_DELETEITEM = &H2D
  78. WM_DESTROY = &H2
  79. WM_DESTROYCLIPBOARD = &H307
  80. WM_DEVICECHANGE = &H219
  81. WM_DEVMODECHANGE = &H1B
  82. WM_DISPLAYCHANGE = &H7E
  83. WM_DRAWCLIPBOARD = &H308
  84. WM_DRAWITEM = &H2B
  85. WM_DROPFILES = &H233
  86. WM_ENABLE = &HA
  87. WM_ENDSESSION = &H16
  88. WM_ENTERIDLE = &H121
  89. WM_ENTERMENULOOP = &H211
  90. WM_ENTERSIZEMOVE = &H231
  91. WM_ERASEBKGND = &H14
  92. WM_EXITMENULOOP = &H212
  93. WM_EXITSIZEMOVE = &H232
  94. WM_FONTCHANGE = &H1D
  95. WM_GETDLGCODE = &H87
  96. WM_GETFONT = &H31
  97. WM_GETHOTKEY = &H33
  98. WM_GETICON = &H7F
  99. WM_GETMINMAXINFO = &H24
  100. WM_GETOBJECT = &H3D
  101. WM_GETTEXT = &HD
  102. WM_GETTEXTLENGTH = &HE
  103. WM_HANDHELDFIRST = &H358
  104. WM_HANDHELDLAST = &H35F
  105. WM_HELP = &H53
  106. WM_HOTKEY = &H312
  107. WM_HSCROLL = &H114
  108. WM_HSCROLLCLIPBOARD = &H30E
  109. WM_ICONERASEBKGND = &H27
  110. WM_IME_CHAR = &H286
  111. WM_IME_COMPOSITION = &H10F
  112. WM_IME_COMPOSITIONFULL = &H284
  113. WM_IME_CONTROL = &H283
  114. WM_IME_ENDCOMPOSITION = &H10E
  115. WM_IME_KEYDOWN = &H290
  116. WM_IME_KEYLAST = &H10F
  117. WM_IME_KEYUP = &H291
  118. WM_IME_NOTIFY = &H282
  119. WM_IME_REQUEST = &H288
  120. WM_IME_SELECT = &H285
  121. WM_IME_SETCONTEXT = &H281
  122. WM_IME_STARTCOMPOSITION = &H10D
  123. WM_INITDIALOG = &H110
  124. WM_INITMENU = &H116
  125. WM_INITMENUPOPUP = &H117
  126. WM_INPUTLANGCHANGE = &H51
  127. WM_INPUTLANGCHANGEREQUEST = &H50
  128. WM_KEYDOWN = &H100
  129. WM_KEYFIRST = &H100
  130. WM_KEYLAST = &H108
  131. WM_KEYUP = &H101
  132. WM_KILLFOCUS = &H8
  133. WM_LBUTTONDBLCLK = &H203
  134. WM_LBUTTONDOWN = &H201
  135. WM_LBUTTONUP = &H202
  136. WM_MBUTTONDBLCLK = &H209
  137. WM_MBUTTONDOWN = &H207
  138. WM_MBUTTONUP = &H208
  139. WM_MDIACTIVATE = &H222
  140. WM_MDICASCADE = &H227
  141. WM_MDICREATE = &H220
  142. WM_MDIDESTROY = &H221
  143. WM_MDIGETACTIVE = &H229
  144. WM_MDIICONARRANGE = &H228
  145. WM_MDIMAXIMIZE = &H225
  146. WM_MDINEXT = &H224
  147. WM_MDIREFRESHMENU = &H234
  148. WM_MDIRESTORE = &H223
  149. WM_MDISETMENU = &H230
  150. WM_MDITILE = &H226
  151. WM_MEASUREITEM = &H2C
  152. WM_MENUCHAR = &H120
  153. WM_MENUCOMMAND = &H126
  154. WM_MENUDRAG = &H123
  155. WM_MENUGETOBJECT = &H124
  156. WM_MENURBUTTONUP = &H122
  157. WM_MENUSELECT = &H11F
  158. WM_MOUSEACTIVATE = &H21
  159. WM_MOUSEFIRST = &H200
  160. WM_MOUSEHOVER = &H2A1
  161. WM_MOUSELAST = &H20A
  162. WM_MOUSELEAVE = &H2A3
  163. WM_MOUSEMOVE = &H200
  164. WM_MOUSEWHEEL = &H20A
  165. WM_MOVE = &H3
  166. WM_MOVING = &H216
  167. WM_NCACTIVATE = &H86
  168. WM_NCCALCSIZE = &H83
  169. WM_NCCREATE = &H81
  170. WM_NCDESTROY = &H82
  171. WM_NCHITTEST = &H84
  172. WM_NCLBUTTONDBLCLK = &HA3
  173. WM_NCLBUTTONDOWN = &HA1
  174. WM_NCLBUTTONUP = &HA2
  175. WM_NCMBUTTONDBLCLK = &HA9
  176. WM_NCMBUTTONDOWN = &HA7
  177. WM_NCMBUTTONUP = &HA8
  178. WM_NCMOUSEHOVER = &H2A0
  179. WM_NCMOUSELEAVE = &H2A2
  180. WM_NCMOUSEMOVE = &HA0
  181. WM_NCPAINT = &H85
  182. WM_NCRBUTTONDBLCLK = &HA6
  183. WM_NCRBUTTONDOWN = &HA4
  184. WM_NCRBUTTONUP = &HA5
  185. WM_NEXTDLGCTL = &H28
  186. WM_NEXTMENU = &H213
  187. WM_NOTIFY = &H4E
  188. WM_NOTIFYFORMAT = &H55
  189. WM_NULL = &H0
  190. WM_PAINT = &HF
  191. WM_PAINTCLIPBOARD = &H309
  192. WM_PAINTICON = &H26
  193. WM_PALETTECHANGED = &H311
  194. WM_PALETTEISCHANGING = &H310
  195. WM_PARENTNOTIFY = &H210
  196. WM_PASTE = &H302
  197. WM_PENWINFIRST = &H380
  198. WM_PENWINLAST = &H38F
  199. WM_POWER = &H48
  200. WM_PRINT = &H317
  201. WM_PRINTCLIENT = &H318
  202. WM_QUERYDRAGICON = &H37
  203. WM_QUERYENDSESSION = &H11
  204. WM_QUERYNEWPALETTE = &H30F
  205. WM_QUERYOPEN = &H13
  206. WM_QUEUESYNC = &H23
  207. WM_QUIT = &H12
  208. WM_RBUTTONDBLCLK = &H206
  209. WM_RBUTTONDOWN = &H204
  210. WM_RBUTTONUP = &H205
  211. WM_RENDERALLFORMATS = &H306
  212. WM_RENDERFORMAT = &H305
  213. WM_SETCURSOR = &H20
  214. WM_SETFOCUS = &H7
  215. WM_SETFONT = &H30
  216. WM_SETHOTKEY = &H32
  217. WM_SETICON = &H80
  218. WM_SETREDRAW = &HB
  219. WM_SETTEXT = &HC
  220. WM_SETTINGCHANGE = &H1A
  221. WM_SHOWWINDOW = &H18
  222. WM_SIZE = &H5
  223. WM_SIZECLIPBOARD = &H30B
  224. WM_SIZING = &H214
  225. WM_SPOOLERSTATUS = &H2A
  226. WM_STYLECHANGED = &H7D
  227. WM_STYLECHANGING = &H7C
  228. WM_SYNCPAINT = &H88
  229. WM_SYSCHAR = &H106
  230. WM_SYSCOLORCHANGE = &H15
  231. WM_SYSCOMMAND = &H112
  232. WM_SYSDEADCHAR = &H107
  233. WM_SYSKEYDOWN = &H104
  234. WM_SYSKEYUP = &H105
  235. WM_TCARD = &H52
  236. WM_TIMECHANGE = &H1E
  237. WM_TIMER = &H113
  238. WM_UNDO = &H304
  239. WM_UNINITMENUPOPUP = &H125
  240. WM_USER = &H400
  241. WM_USERCHANGED = &H54
  242. WM_VKEYTOITEM = &H2E
  243. WM_VSCROLL = &H115
  244. WM_VSCROLLCLIPBOARD = &H30A
  245. WM_WINDOWPOSCHANGED = &H47
  246. WM_WINDOWPOSCHANGING = &H46
  247. WM_WININICHANGE = &H1A
  248. End Enum
  249.  
  250. ''' <summary>
  251. ''' Raises the <see cref="Quit"/> event
  252. ''' </summary>
  253. Protected Sub OnQuit()
  254. #If OnSourceInitialized Then
  255. CommandBinding_Close_Executed(Me,Nothing)
  256. #Else
  257. MenuCloseTab_Click(Me,Nothing)
  258. #End If
  259. RaiseEvent Quit(Me,EventArgs.Empty)
  260. End Sub
  261.  
  262. ''' <summary>
  263. ''' Raised when the browser application quits
  264. ''' </summary>
  265. ''' <remarks>
  266. ''' Do not confuse this with DWebBrowserEvents2.Quit... That's something else.
  267. ''' </remarks>
  268. Public Event Quit As EventHandler
  269. #End Region

内容是C#代码WINFORM 搜索下就有,暂略

猜你在找的VB相关文章