473,659 Members | 2,985 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Does IMessageFilter work?

I've added an IMessageFilter to my app but I don't get messages or I get only a few and then it stops. My code is very simple. Am I
doing something wrong?

public class MF : IMessageFilter
{
public MF()
{
}
public bool PreFilterMessag e(ref Message m)
{
if(m.Msg == 15)
{
Console.WriteLi ne("Paint");
}
return false;
}
}

and

Application.Add MessageFilter(n ew MF());

I've tried putting this in different locations, such as void Main, Form_Load etc

--
Michael Culley
Nov 15 '05 #1
7 6461
Hi,

A simple test runs fine here, can't say what you're doing wrong.

There must be a message loop (Application.Ru n/ Modal form). Try putting
this in the static main method:

Application.Add MessageFilter( new MF() );
Application.Run ( new MainForm() );

You can not place AddMessage after Run, because Run is the message loop,
which doesn't stop until the app is closed.

If you only place Application.Run ( new MainForm() ) in the main method,
it should work if you call Application.Add MessageFilter from any
control/form event.
HTH
greetings

"Michael Culley" <mc*****@NOSPAM optushome.com.a u> wrote in message
news:OP******** ******@TK2MSFTN GP12.phx.gbl...
I've added an IMessageFilter to my app but I don't get messages or I get only a few and then it stops. My code is very simple. Am I doing something wrong?

public class MF : IMessageFilter
{
public MF()
{
}
public bool PreFilterMessag e(ref Message m)
{
if(m.Msg == 15)
{
Console.WriteLi ne("Paint");
}
return false;
}
}

and

Application.Add MessageFilter(n ew MF());

I've tried putting this in different locations, such as void Main, Form_Load etc
--
Michael Culley

Nov 15 '05 #2
Does it send you the paint message every time your form is painted, eg if another windows is dragged over it. On mine I get a few
paint messages at the start and then nothing.

--
Michael Culley
"BMermuys" <bm************ **@hotmail.com> wrote in message news:8B******** ************@ph obos.telenet-ops.be...
Hi,

A simple test runs fine here, can't say what you're doing wrong.

There must be a message loop (Application.Ru n/ Modal form). Try putting
this in the static main method:

Application.Add MessageFilter( new MF() );
Application.Run ( new MainForm() );

You can not place AddMessage after Run, because Run is the message loop,
which doesn't stop until the app is closed.

If you only place Application.Run ( new MainForm() ) in the main method,
it should work if you call Application.Add MessageFilter from any
control/form event.
HTH
greetings

"Michael Culley" <mc*****@NOSPAM optushome.com.a u> wrote in message
news:OP******** ******@TK2MSFTN GP12.phx.gbl...
I've added an IMessageFilter to my app but I don't get messages or I get

only a few and then it stops. My code is very simple. Am I
doing something wrong?

public class MF : IMessageFilter
{
public MF()
{
}
public bool PreFilterMessag e(ref Message m)
{
if(m.Msg == 15)
{
Console.WriteLi ne("Paint");
}
return false;
}
}

and

Application.Add MessageFilter(n ew MF());

I've tried putting this in different locations, such as void Main,

Form_Load etc

--
Michael Culley


Nov 15 '05 #3

"Michael Culley" <mc*****@NOSPAM optushome.com.a u> wrote in message
news:eF******** ******@TK2MSFTN GP09.phx.gbl...
Does it send you the paint message every time your form is painted, eg if another windows is dragged over it.

Yes, it does. With your MF class, I get correct nr of paint messages.
On mine I get a few
paint messages at the start and then nothing.
Can't help you more, is there anything special about the app ? Have you
tried it with a new project ? On a different machine, etc....

HTH
greetings


--
Michael Culley
"BMermuys" <bm************ **@hotmail.com> wrote in message

news:8B******** ************@ph obos.telenet-ops.be...
Hi,

A simple test runs fine here, can't say what you're doing wrong.

There must be a message loop (Application.Ru n/ Modal form). Try putting
this in the static main method:

Application.Add MessageFilter( new MF() );
Application.Run ( new MainForm() );

You can not place AddMessage after Run, because Run is the message loop,
which doesn't stop until the app is closed.

If you only place Application.Run ( new MainForm() ) in the main method,
it should work if you call Application.Add MessageFilter from any
control/form event.
HTH
greetings

"Michael Culley" <mc*****@NOSPAM optushome.com.a u> wrote in message
news:OP******** ******@TK2MSFTN GP12.phx.gbl...
I've added an IMessageFilter to my app but I don't get messages or I
get only a few and then it stops. My code is very simple. Am I
doing something wrong?

public class MF : IMessageFilter
{
public MF()
{
}
public bool PreFilterMessag e(ref Message m)
{
if(m.Msg == 15)
{
Console.WriteLi ne("Paint");
}
return false;
}
}

and

Application.Add MessageFilter(n ew MF());

I've tried putting this in different locations, such as void Main,

Form_Load etc

--
Michael Culley



Nov 15 '05 #4
"BMermuys" <bm************ **@hotmail.com> wrote in message news:q3******** *************@p hobos.telenet-ops.be...

Thanks for the reply.

I've found the problem, not sure if it is a bug or not. Every time I was testing the message filter I was testing it by moving the
form off the edge of the screen and back on to get it to fire paint messages. For some reason when you are moving the form the
IMessageFilter stops working and it misses all messages. If I override the WndProc of the form it gets all the messages but the
IMessageFilter does not. Any ideas what's going on?

--
Michael Culley
Nov 15 '05 #5
It doesn't seem to get WM_COPYDATA messages either or any message sent from another app. Basically it seems to drop so many messages
that it is unusable.

--
Michael Culley
"BMermuys" <bm************ **@hotmail.com> wrote in message news:q3******** *************@p hobos.telenet-ops.be...

"Michael Culley" <mc*****@NOSPAM optushome.com.a u> wrote in message
news:eF******** ******@TK2MSFTN GP09.phx.gbl...
Does it send you the paint message every time your form is painted, eg if

another windows is dragged over it.

Yes, it does. With your MF class, I get correct nr of paint messages.
On mine I get a few
paint messages at the start and then nothing.


Can't help you more, is there anything special about the app ? Have you
tried it with a new project ? On a different machine, etc....

HTH
greetings


--
Michael Culley
"BMermuys" <bm************ **@hotmail.com> wrote in message

news:8B******** ************@ph obos.telenet-ops.be...
Hi,

A simple test runs fine here, can't say what you're doing wrong.

There must be a message loop (Application.Ru n/ Modal form). Try putting
this in the static main method:

Application.Add MessageFilter( new MF() );
Application.Run ( new MainForm() );

You can not place AddMessage after Run, because Run is the message loop,
which doesn't stop until the app is closed.

If you only place Application.Run ( new MainForm() ) in the main method,
it should work if you call Application.Add MessageFilter from any
control/form event.
HTH
greetings

"Michael Culley" <mc*****@NOSPAM optushome.com.a u> wrote in message
news:OP******** ******@TK2MSFTN GP12.phx.gbl...
> I've added an IMessageFilter to my app but I don't get messages or I get only a few and then it stops. My code is very simple. Am I
> doing something wrong?
>
> public class MF : IMessageFilter
> {
> public MF()
> {
> }
> public bool PreFilterMessag e(ref Message m)
> {
> if(m.Msg == 15)
> {
> Console.WriteLi ne("Paint");
> }
> return false;
> }
> }
>
> and
>
> Application.Add MessageFilter(n ew MF());
>
> I've tried putting this in different locations, such as void Main,
Form_Load etc
>
> --
> Michael Culley
>
>



Nov 15 '05 #6

"Michael Culley" <mc*****@NOSPAM optushome.com.a u> wrote in message
news:ef******** ******@TK2MSFTN GP12.phx.gbl...
"BMermuys" <bm************ **@hotmail.com> wrote in message news:q3******** *************@p hobos.telenet-ops.be...
Thanks for the reply.

I've found the problem, not sure if it is a bug or not. Every time I was testing the message filter I was testing it by moving the form off the edge of the screen and back on to get it to fire paint messages. For some reason when you are moving the form the IMessageFilter stops working and it misses all messages. If I override the WndProc of the form it gets all the messages but the IMessageFilter does not. Any ideas what's going on?
This has to do with the difference between posting or sending messsages.

* Posted messages are added to the queue and eventually dispatched in order
by the message loop.

* Sended messages are handled differently.
- If you sent a message to a window from the thread that created the window
then the wndproc is directly called like a subroutine.

- Sended messages form different threads execute the wndproc when the
message loop queries for a new message, but they are not dispatched by the
message loop, windows does it transparantly.
HTH
greetings


--
Michael Culley

Nov 15 '05 #7
Looks like it is not going to work for me because I am after the WM_COPYDATA message and this seems to be sent on a different thread
and an IMessageFilter will only work on one thread. I am currently overriding WndProc but it seems to play funny buggers with a com
component I am using so I was looking for a different solution.

Thanks for your help.

--
Michael Culley
"BMermuys" <bm************ **@hotmail.com> wrote in message news:th******** *************@p hobos.telenet-ops.be...

"Michael Culley" <mc*****@NOSPAM optushome.com.a u> wrote in message
news:ef******** ******@TK2MSFTN GP12.phx.gbl...
"BMermuys" <bm************ **@hotmail.com> wrote in message

news:q3******** *************@p hobos.telenet-ops.be...

Thanks for the reply.

I've found the problem, not sure if it is a bug or not. Every time I was

testing the message filter I was testing it by moving the
form off the edge of the screen and back on to get it to fire paint

messages. For some reason when you are moving the form the
IMessageFilter stops working and it misses all messages. If I override the

WndProc of the form it gets all the messages but the
IMessageFilter does not. Any ideas what's going on?


This has to do with the difference between posting or sending messsages.

* Posted messages are added to the queue and eventually dispatched in order
by the message loop.

* Sended messages are handled differently.
- If you sent a message to a window from the thread that created the window
then the wndproc is directly called like a subroutine.

- Sended messages form different threads execute the wndproc when the
message loop queries for a new message, but they are not dispatched by the
message loop, windows does it transparantly.
HTH
greetings


--
Michael Culley


Nov 15 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
4846
by: Jonas | last post by:
This works fine in Win XP but does not work at all in Win 98. Private WithEvents objIExplorer As InternetExplorer I have to do it like this to get it to work in Win 98 Dim objIExplorer As InternetExplorer But then I cant see when a user exit my objIExplorer and than an error will show up when I try to open a link in the IE window that does not exist... What can I do about this and way does it not work in win 98?
1
3766
by: See Sharp | last post by:
Hello all, I have a form class that implements the imessagefilter interface public class frmMain : System.Windows.Forms.Form, IMessageFilter I also have this implemented bool IMessageFilter.PreFilterMessage( ref Message m ) This class actually interacts with the twain driver and that's why I need
1
2649
by: Neil Stevens | last post by:
Hi, I am in the process of developing a popup utility for a project i am working on, the basic idea is that when a user presses the control key a popup menu will be displayed listing the shortcut options, for example Ctrl+Q which will be used to close a window. The popup is a simple form which is configured by means of of a dictionary of values (key and description). I have a message filter running to intercept the key down presses for...
3
6454
by: John | last post by:
I get the following VB6 sample and it doesn't work in VB .Net. Can anyone help to make it work in VB .Net? Structure POINTAPI Dim x As Long Dim y As Long End Structure Structure MSG Dim hwnd As Long
4
16778
by: GrandpaB | last post by:
Hi, I recently had a post about how to block Mousewheel events. The answer was to implement an IMessageFilter. Sadly, I must report that after 24 hours of researching my library and online resources I am still stumped! I did find a promising code snippet on MSDN, but have yet to successfully implement it. Here is the code snippet: Public Class MessageFilter
1
2693
by: newscorrespondent | last post by:
I set up an IMessageFilter in an attempt to trap the WM_QUIT message from a plain C# windows forms application. I never get the WM_QUIT message. How come? I also get a number of messages that are way outside of the windows message range. (C0F0, C0F3, 2100) and others. I am guessing that these are .NET messages. Whatever they are where are they documented and what keyword can I use to search and find them?
2
3785
by: deciacco | last post by:
IMessageFilter interface allows one to capture messages before they are sent to a control or a form. Is there a way, perhaps by implementing another interface, to capture all messages to an exe. In other words, if I add a custom message filter implementing the IMessageFilter interface to my notifyicon class, I can capture messages when I display forms. If I add custom event handlers to the various events in the SystemEvents class I can...
0
1880
by: ah.ping.luk | last post by:
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
2
2104
by: bakpao | last post by:
I want to have a form that accepts keypresses. The controls other than the form should not receive any of the user input. I have implemented it using IMessageFilter but now just now I discovered about KeyPreview. What is the difference between IMessageFilter and KeyPreview? Is there a significant benefit using one way than the other?
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8747
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8528
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2752
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.