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

#Region "WPF 当浏览器窗体关闭时触发 Quit事件 "

#If OnSourceInitialized Then
Protected Overrides Sub OnSourceInitialized(e As EventArgs) 'onload 等句柄创建后引用WSInitialized(Me, e)
WSInitialized(Me, e)
MyBase.OnSourceInitialized(e)
End Sub
#Else Private Sub LyWebTabItem_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
WSInitialized(sender, e)
End Sub
#End If Sub WSInitialized(sender As Object, e As EventArgs)
Dim hs As HwndSource = PresentationSource.FromVisual(Me) '=HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
hs.AddHook(New HwndSourceHook(AddressOf WndProc))
End Sub ''' <summary>
''' Overridden
''' </summary>
''' <param name="m">The <see cref="Message"/> send to this procedure</param>
<PermissionSet(SecurityAction.LinkDemand, Name:="FullTrust")> _
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)
'Protected Overloads sub WndProc((ByRef m As Forms.Message)) 'winform方式
'If m.Msg = DirectCast(WindowsMessages.WM_PARENTNOTIFY, Integer) Then
If msg = DirectCast(WindowsMessages.WM_PARENTNOTIFY, Integer) Then
'int lp = m.LParam.ToInt32();
'Dim wp As Integer = m.WParam.ToInt32()
Dim wp As Integer = wParam.ToInt32() Dim X As Integer = wp And &HFFFF
'int Y = (wp >> 16) & 0xFFFF;
If X = DirectCast(WindowsMessages.WM_DESTROY, Integer) Then
Me.OnQuit()
End If
End If
Return IntPtr.Zero
'MyBase.WndProc(m)
End Function
''' <summary>
''' A list of all the available window messages
''' </summary>
Enum WindowsMessages
WM_ACTIVATE = &H6
WM_ACTIVATEAPP = &H1C
WM_AFXFIRST = &H360
WM_AFXLAST = &H37F
WM_APP = &H8000
WM_ASKCBFORMATNAME = &H30C
WM_CANCELJOURNAL = &H4B
WM_CANCELMODE = &H1F
WM_CAPTURECHANGED = &H215
WM_CHANGECBCHAIN = &H30D
WM_CHAR = &H102
WM_CHARTOITEM = &H2F
WM_CHILDACTIVATE = &H22
WM_CLEAR = &H303
WM_CLOSE = &H10
WM_COMMAND = &H111
WM_COMPACTING = &H41
WM_COMPAREITEM = &H39
WM_CONTEXTMENU = &H7B
WM_COPY = &H301
WM_COPYDATA = &H4A
WM_CREATE = &H1
WM_CTLCOLORBTN = &H135
WM_CTLCOLORDLG = &H136
WM_CTLCOLOREDIT = &H133
WM_CTLCOLORLISTBOX = &H134
WM_CTLCOLORMSGBOX = &H132
WM_CTLCOLORSCROLLBAR = &H137
WM_CTLCOLORSTATIC = &H138
WM_CUT = &H300
WM_DEADCHAR = &H103
WM_DELETEITEM = &H2D
WM_DESTROY = &H2
WM_DESTROYCLIPBOARD = &H307
WM_DEVICECHANGE = &H219
WM_DEVMODECHANGE = &H1B
WM_DISPLAYCHANGE = &H7E
WM_DRAWCLIPBOARD = &H308
WM_DRAWITEM = &H2B
WM_DROPFILES = &H233
WM_ENABLE = &HA
WM_ENDSESSION = &H16
WM_ENTERIDLE = &H121
WM_ENTERMENULOOP = &H211
WM_ENTERSIZEMOVE = &H231
WM_ERASEBKGND = &H14
WM_EXITMENULOOP = &H212
WM_EXITSIZEMOVE = &H232
WM_FONTCHANGE = &H1D
WM_GETDLGCODE = &H87
WM_GETFONT = &H31
WM_GETHOTKEY = &H33
WM_GETICON = &H7F
WM_GETMINMAXINFO = &H24
WM_GETOBJECT = &H3D
WM_GETTEXT = &HD
WM_GETTEXTLENGTH = &HE
WM_HANDHELDFIRST = &H358
WM_HANDHELDLAST = &H35F
WM_HELP = &H53
WM_HOTKEY = &H312
WM_HSCROLL = &H114
WM_HSCROLLCLIPBOARD = &H30E
WM_ICONERASEBKGND = &H27
WM_IME_CHAR = &H286
WM_IME_COMPOSITION = &H10F
WM_IME_COMPOSITIONFULL = &H284
WM_IME_CONTROL = &H283
WM_IME_ENDCOMPOSITION = &H10E
WM_IME_KEYDOWN = &H290
WM_IME_KEYLAST = &H10F
WM_IME_KEYUP = &H291
WM_IME_NOTIFY = &H282
WM_IME_REQUEST = &H288
WM_IME_SELECT = &H285
WM_IME_SETCONTEXT = &H281
WM_IME_STARTCOMPOSITION = &H10D
WM_INITDIALOG = &H110
WM_INITMENU = &H116
WM_INITMENUPOPUP = &H117
WM_INPUTLANGCHANGE = &H51
WM_INPUTLANGCHANGEREQUEST = &H50
WM_KEYDOWN = &H100
WM_KEYFIRST = &H100
WM_KEYLAST = &H108
WM_KEYUP = &H101
WM_KILLFOCUS = &H8
WM_LBUTTONDBLCLK = &H203
WM_LBUTTONDOWN = &H201
WM_LBUTTONUP = &H202
WM_MBUTTONDBLCLK = &H209
WM_MBUTTONDOWN = &H207
WM_MBUTTONUP = &H208
WM_MDIACTIVATE = &H222
WM_MDICASCADE = &H227
WM_MDICREATE = &H220
WM_MDIDESTROY = &H221
WM_MDIGETACTIVE = &H229
WM_MDIICONARRANGE = &H228
WM_MDIMAXIMIZE = &H225
WM_MDINEXT = &H224
WM_MDIREFRESHMENU = &H234
WM_MDIRESTORE = &H223
WM_MDISETMENU = &H230
WM_MDITILE = &H226
WM_MEASUREITEM = &H2C
WM_MENUCHAR = &H120
WM_MENUCOMMAND = &H126
WM_MENUDRAG = &H123
WM_MENUGETOBJECT = &H124
WM_MENURBUTTONUP = &H122
WM_MENUSELECT = &H11F
WM_MOUSEACTIVATE = &H21
WM_MOUSEFIRST = &H200
WM_MOUSEHOVER = &H2A1
WM_MOUSELAST = &H20A
WM_MOUSELEAVE = &H2A3
WM_MOUSEMOVE = &H200
WM_MOUSEWHEEL = &H20A
WM_MOVE = &H3
WM_MOVING = &H216
WM_NCACTIVATE = &H86
WM_NCCALCSIZE = &H83
WM_NCCREATE = &H81
WM_NCDESTROY = &H82
WM_NCHITTEST = &H84
WM_NCLBUTTONDBLCLK = &HA3
WM_NCLBUTTONDOWN = &HA1
WM_NCLBUTTONUP = &HA2
WM_NCMBUTTONDBLCLK = &HA9
WM_NCMBUTTONDOWN = &HA7
WM_NCMBUTTONUP = &HA8
WM_NCMOUSEHOVER = &H2A0
WM_NCMOUSELEAVE = &H2A2
WM_NCMOUSEMOVE = &HA0
WM_NCPAINT = &H85
WM_NCRBUTTONDBLCLK = &HA6
WM_NCRBUTTONDOWN = &HA4
WM_NCRBUTTONUP = &HA5
WM_NEXTDLGCTL = &H28
WM_NEXTMENU = &H213
WM_NOTIFY = &H4E
WM_NOTIFYFORMAT = &H55
WM_NULL = &H0
WM_PAINT = &HF
WM_PAINTCLIPBOARD = &H309
WM_PAINTICON = &H26
WM_PALETTECHANGED = &H311
WM_PALETTEISCHANGING = &H310
WM_PARENTNOTIFY = &H210
WM_PASTE = &H302
WM_PENWINFIRST = &H380
WM_PENWINLAST = &H38F
WM_POWER = &H48
WM_PRINT = &H317
WM_PRINTCLIENT = &H318
WM_QUERYDRAGICON = &H37
WM_QUERYENDSESSION = &H11
WM_QUERYNEWPALETTE = &H30F
WM_QUERYOPEN = &H13
WM_QUEUESYNC = &H23
WM_QUIT = &H12
WM_RBUTTONDBLCLK = &H206
WM_RBUTTONDOWN = &H204
WM_RBUTTONUP = &H205
WM_RENDERALLFORMATS = &H306
WM_RENDERFORMAT = &H305
WM_SETCURSOR = &H20
WM_SETFOCUS = &H7
WM_SETFONT = &H30
WM_SETHOTKEY = &H32
WM_SETICON = &H80
WM_SETREDRAW = &HB
WM_SETTEXT = &HC
WM_SETTINGCHANGE = &H1A
WM_SHOWWINDOW = &H18
WM_SIZE = &H5
WM_SIZECLIPBOARD = &H30B
WM_SIZING = &H214
WM_SPOOLERSTATUS = &H2A
WM_STYLECHANGED = &H7D
WM_STYLECHANGING = &H7C
WM_SYNCPAINT = &H88
WM_SYSCHAR = &H106
WM_SYSCOLORCHANGE = &H15
WM_SYSCOMMAND = &H112
WM_SYSDEADCHAR = &H107
WM_SYSKEYDOWN = &H104
WM_SYSKEYUP = &H105
WM_TCARD = &H52
WM_TIMECHANGE = &H1E
WM_TIMER = &H113
WM_UNDO = &H304
WM_UNINITMENUPOPUP = &H125
WM_USER = &H400
WM_USERCHANGED = &H54
WM_VKEYTOITEM = &H2E
WM_VSCROLL = &H115
WM_VSCROLLCLIPBOARD = &H30A
WM_WINDOWPOSCHANGED = &H47
WM_WINDOWPOSCHANGING = &H46
WM_WININICHANGE = &H1A
End Enum ''' <summary>
''' Raises the <see cref="Quit"/> event
''' </summary>
Protected Sub OnQuit()
#If OnSourceInitialized Then
CommandBinding_Close_Executed(Me, Nothing)
#Else
MenuCloseTab_Click(Me, Nothing)
#End If
RaiseEvent Quit(Me, EventArgs.Empty)
End Sub ''' <summary>
''' Raised when the browser application quits
''' </summary>
''' <remarks>
''' Do not confuse this with DWebBrowserEvents2.Quit... That's something else.
''' </remarks>
Public Event Quit As EventHandler
#End Region

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

vb.net WPF webbrowser window.close 关闭后不触发 WindowClosing 事件 WNDPROC解决方式的更多相关文章

  1. c#winform关闭窗口时触发的事件

    用户关闭软件时,软件一般会给“是否确认关闭”的提示. 通常,我们把它写在FormClosing 事件中,如果确定关闭,就关闭:否则把FormClosingEventArgs 的 Cancel 属性设置 ...

  2. 解决移动端页面滚动后不触发touchend事件

    解决移动端页面滚动后不触发touchend事件 问题 在移动端页面进行优化时,一般使用touch事件替代鼠标相关事件.用的较多的是使用touchend事件替代PC端的click和mouseup事件. ...

  3. android:windowSoftInputMode属性;界面关闭后软键盘不隐藏的解决方法;

    stateUnspecified:软键盘的状态并没有指定,系统将选择一个合适的状态或依赖于主题的设置 stateUnchanged:当这个activity出现时,软键盘将一直保持在上一个activit ...

  4. 浏览器关闭使session失效的问题多种解决方式

    直接关闭浏览器(或者强制关闭浏览器进程.死机等),服务器无法处理用户退出网站的请求,此举将会导致session失效,下面整理了一些解决方法,感兴趣的朋友可以参考下哈   如果用户不点击网站的“退出”链 ...

  5. svn 卡死住,关闭后,用CleanUp报错解决

    一.问题描述: 经常用SVN的人都知道,有时候更新文件更新着更新一般,突然卡顿住,死在那边动都不动出现提示:svn cleanup failed–previous operation has not ...

  6. vscode关闭后未打开上次界面的解决办法

    1.更新vscode至最新版,当前时间2017-06-20,vs最新版1.13.1 2.关闭vscode的正确方式,不是点击左上角的叉叉,而是CMD+Q或者在Dock右键退出 3.这样,你在下次打开v ...

  7. redis 中的key值过期后,触发通知事件

    1.创建springboot工程,创建监听类 maven配置 <dependencies> <dependency> <groupId>org.springfram ...

  8. layui表格点击排序按钮后,表格绑定事件失效解决方法

    最近项目使用layui较为频繁,遇到了一个麻烦的问题,网上搜索也没有看到同类型的问题,故此记下来. 需求是点击上图右侧表格中某一个单元格,会触发点击事件如下代码: $("table>t ...

  9. 关于使用struts2跳转后css和js失效的解决方式

    根据观察,主要是由于通过action跳转后的url会根据命名空间,自动跳转到命名空间子目录,使得当前引用的css和js查找不到,从而失效,根据这个原因,可使用四种办法解决: 1.使用struts2.x ...

随机推荐

  1. 基于visual Studio2013解决面试题之0402合并升序链表并去重

     题目

  2. 源代码编译lamp环境

    没有办法用 rpm查询一个源代码包是否安装 因为 并不是用rpm安装的 可以先吧 selinux 给禁用掉  iptables -F 把防火墙规则全部删除 首先确保 gcc  gcc-c++   ma ...

  3. 【源代码】LinkedHashMap源代码剖析

    注:下面源代码基于jdk1.7.0_11 之前的两篇文章通过源代码分析了两种常见的Map集合,HashMap和Hashtable.本文将继续介绍还有一种Map集合--LinkedHashMap. 顾名 ...

  4. ABP启动配置

    ABP启动配置   返回ABP系列 ABP是“ASP.NET Boilerplate Project (ASP.NET样板项目)”的简称. ASP.NET Boilerplate是一个用最佳实践和流行 ...

  5. 眼见为实(2):介绍Windows的窗口、消息、子类化和超类化

    眼见为实(2):介绍Windows的窗口.消息.子类化和超类化 这篇文章本来只是想介绍一下子类化和超类化这两个比较“生僻”的名词.为了叙述的完整性而讨论了Windows的窗口和消息,也简要讨论了进程和 ...

  6. 【ASP.NET Web API教程】5.5 ASP.NET Web API中的HTTP Cookie

    原文:[ASP.NET Web API教程]5.5 ASP.NET Web API中的HTTP Cookie 5.5 HTTP Cookies in ASP.NET Web API 5.5 ASP.N ...

  7. 《Head First 设计模式》学习笔记——模板方法模式

    模板方法模式是类的行为模式.准备一个抽象类,将部分逻辑以详细方法以及详细构造函数的形式实现.然后声明一些抽象方法来迫使子类实现剩余的逻辑.不同的子类能够以不同的方式实现这些抽象方法,从而对剩余的逻辑有 ...

  8. [Windows Phone]AnimationHelper管理分散的Storyboard

    问题描述: 在Windows Phone开发时候,可能存在这样的问题: 某一个控件需要一个特定的展现(这里假定是一个特定动画),那么我们会这么解决这个问题呢? 打开Blend,根据需求需求给控件添加动 ...

  9. shodan

    https://www.shodan.io/ from:http://www.exploit-db.com/wp-content/themes/exploit/docs/33859.pdf 0x00 ...

  10. linux内核基础(系统调用,简明)

    内核基础(系统调用) 在说系统调用之前.先来说说内核是怎么和我们交互的.或者说是怎么和我们产生交集的. 首先,内核是用来控制硬件的仅仅有内核才干直接控制硬件,所以说内核非常重要,假设内核被控制那么电脑 ...