vb.net WPF WebBrowser Window.close does not trigger windowclosing event WndProc solution after shutdown

Source: Internet
Author: User



vb.net WPF WebBrowser Window.close does not trigger windowclosing event WndProc solution after shutdown


#Region "WPF triggers the Quit event when the browser window closes" #If onsourceinitialized then Protected Overrides Sub onsourceinitialized (e as EventArg    s) ' OnLoad and other handles created after reference 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 = PRESENTATIONSOURC E.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> <permissi OnSet (SecurityAction.LinkDemand, name:= "FullTrust") > _ Protected Overloads Function WndProc (hwnd as INTPTR, MSG as I Nt32, WParam as IntPtr, LParam as INTPTR, ByRef handledAs Boolean) as IntPtr ' (ByRef m as Forms.message) ' Protected Overloads Sub WndProc ((ByRef m as Forms.message) ' WI Nform mode ' If m.msg = DirectCast (windowsmessages.wm_parentnotify, Integer) then If MSG = DirectCast (windowsmes Sages.              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 A              nd &hffff ' int Y = (wp >> x) & 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 Availab Le 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_capture        CHANGED = &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_CTLCO        Lorscrollbar = &h137 Wm_ctlcolorstatic = &h138 Wm_cut = &h300 Wm_deadchar = &h103 Wm_deleteitem = &h2d Wm_destroy = &h2 Wm_destroyclipboard = &h307 Wm_devicechange = & Amp 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_exitmenu        LOOP = &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 = &H3         Wm_handheldlast = &h35f Wm_help = &h53 Wm_hotkey = &h312 Wm_hscroll = &h114 Wm_hscrollclipboard = &h30e Wm_iconerasebkgnd = &h27 Wm_ime_char = &h286 Wm_ime_c  Omposition = &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 = &A mp        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 = &am P H209 Wm_mbuttondown = &h207 Wm_mbuttonup = &h208 wm_mdiactivate = &h222 WM_MDICASC    ADE = &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 = &A mp H124 Wm_menurbuttonup = &h122 Wm_menuselect = &h11f wm_mouseactivate = &h21 Wm_mou        Sefirst = &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 = &amP H84 WM_NCLBUTTONDBLCLK = &ha3 Wm_nclbuttondown = &ha1 Wm_nclbuttonup = &ha2 WM_NCM BUTTONDBLCLK = &ha9 Wm_ncmbuttondown = &ha7 Wm_ncmbuttonup = &ha8 Wm_ncmousehover = & h2a0 Wm_ncmouseleave = &h2a2 Wm_ncmousemove = &ha0 Wm_ncpaint = &h85 Wm_ncrbuttond        BLCLK = &ha6 Wm_ncrbuttondown = &ha4 Wm_ncrbuttonup = &ha5 Wm_nextdlgctl = &h28 Wm_nextmenu = &h213 Wm_notify = &h4e Wm_notifyformat = &h55 Wm_null = &h0 WM        _paint = &AMP;HF Wm_paintclipboard = &h309 Wm_painticon = &h26 wm_palettechanged = &H311 wm_paletteischanging = &h310 Wm_parentnotify = &h210 Wm_paste = &h302 Wm_penwinfir ST = &h380 Wm_penwinlast = &h38f Wm_power = &h48 Wm_print = &h317 Wm_printclie        NT = &h318Wm_querydragicon = &h37 Wm_queryendsession = &h11 Wm_querynewpalette = &h30f WM_QUERYOPEN = &h13 Wm_queuesync = &h23 Wm_quit = &h12 WM_RBUTTONDBLCLK = &h206 Wm_rbutton         Down = &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 = &AMP;HB Wm_settext = &AMP;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_s  Ysdeadchar = &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> Protec Ted Sub OnQuit () #If onsourceinitialized then commandbinding_close_executed (Me, nothing) #Else MENUCLOSETAB_CL  Ick (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 DWEBBR Owserevents2.quit ... ThaT ' s something else. ' </remarks> public Event Quit as Eventhandler#end region

The original content is C # code WinForm Search under it, tentatively

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.