PC Review


Reply
Thread Tools Rate Thread

Cannot catch WM_CLOSE in IMessageFilter.PreFilterMessage

 
 
ah.ping.luk@gmail.com
Guest
Posts: n/a
 
      12th Aug 2007
Dear All,

i want to catch the application event (WM_CLOSE) in a user control.

i create a class that implement the IMessageFIlter interface as
follow:

'===================================================
Imports System.Windows.Forms


Public Class ClosingControl
Inherits System.Windows.Forms.UserControl
Implements IMessageFilter

Private gbClosed As Boolean = False

Function PreFilterMessage(ByRef m As Message) As Boolean Implements
IMessageFilter.PreFilterMessage

Dim WM_CLOSE As Integer = &H10

If m.Msg = WM_CLOSE Then

gbClosed = True

MsgBox("close")

End If

Return False

End Function

Private Sub UserControl1_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load

Application.AddMessageFilter(me)

End Sub

End Class

'===================================================

in a window form, i add an instance of the ClosingControl
(ClosingControl1) to the window form (say Form1).


but when i press the upper right 'X' close button of the window form,
Form1, the PreFilterMessage can't catch the WM_CLOSE message..

i check that there is no such message passing into the function
PreFilterMessage...

can anybody tell me why?
how can i catch the application exit signal in a user control?
(for some reason, i can't use the Form.close event, as the user
control
will be hosted in internet explorer)

thank you very much

lsp

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How to catch WM_CLOSE and other WM_ messages? Chris Tacke, eMVP Microsoft Dot NET Compact Framework 0 7th Mar 2005 08:26 PM
Re: How to catch WM_CLOSE and other WM_ messages? Daniel Moth Microsoft Dot NET Compact Framework 0 7th Mar 2005 08:26 PM
Using PostMessage to send a WM_CLOSE message to an Access Application Window versus using DoCmd.Quit? Wayne Pearson Microsoft Access Form Coding 1 19th Mar 2004 06:06 AM
Re: WM_CLOSE Alex Feinman [MVP] Microsoft Dot NET Compact Framework 2 9th Mar 2004 10:39 PM
Re: WM_ClOSE Chris Tacke, eMVP Microsoft Dot NET Compact Framework 0 9th Mar 2004 08:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:14 AM.