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 PreFilterMessage(ref Message m)
{
if(m.Msg == 15)
{
Console.WriteLine("Paint");
}
return false;
}
}
and
Application.AddMessageFilter(new MF());
I've tried putting this in different locations, such as void Main, Form_Load etc
--
Michael Culley 7 6429
Hi,
A simple test runs fine here, can't say what you're doing wrong.
There must be a message loop (Application.Run/ Modal form). Try putting
this in the static main method:
Application.AddMessageFilter( 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.AddMessageFilter from any
control/form event.
HTH
greetings
"Michael Culley" <mc*****@NOSPAMoptushome.com.au> wrote in message
news:OP**************@TK2MSFTNGP12.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 PreFilterMessage(ref Message m) { if(m.Msg == 15) { Console.WriteLine("Paint"); } return false; } }
and
Application.AddMessageFilter(new MF());
I've tried putting this in different locations, such as void Main,
Form_Load etc -- Michael Culley
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********************@phobos.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.Run/ Modal form). Try putting this in the static main method:
Application.AddMessageFilter( 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.AddMessageFilter from any control/form event.
HTH greetings
"Michael Culley" <mc*****@NOSPAMoptushome.com.au> wrote in message news:OP**************@TK2MSFTNGP12.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 PreFilterMessage(ref Message m) { if(m.Msg == 15) { Console.WriteLine("Paint"); } return false; } }
and
Application.AddMessageFilter(new MF());
I've tried putting this in different locations, such as void Main, Form_Load etc -- Michael Culley
"Michael Culley" <mc*****@NOSPAMoptushome.com.au> wrote in message
news:eF**************@TK2MSFTNGP09.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********************@phobos.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.Run/ Modal form). Try putting this in the static main method:
Application.AddMessageFilter( 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.AddMessageFilter from any control/form event.
HTH greetings
"Michael Culley" <mc*****@NOSPAMoptushome.com.au> wrote in message news:OP**************@TK2MSFTNGP12.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 PreFilterMessage(ref Message m) { if(m.Msg == 15) { Console.WriteLine("Paint"); } return false; } }
and
Application.AddMessageFilter(new MF());
I've tried putting this in different locations, such as void Main, Form_Load etc -- Michael Culley
"BMermuys" <bm**************@hotmail.com> wrote in message news:q3*********************@phobos.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
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*********************@phobos.telenet-ops.be... "Michael Culley" <mc*****@NOSPAMoptushome.com.au> wrote in message news:eF**************@TK2MSFTNGP09.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********************@phobos.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.Run/ Modal form). Try putting this in the static main method:
Application.AddMessageFilter( 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.AddMessageFilter from any control/form event.
HTH greetings
"Michael Culley" <mc*****@NOSPAMoptushome.com.au> wrote in message news:OP**************@TK2MSFTNGP12.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 PreFilterMessage(ref Message m) > { > if(m.Msg == 15) > { > Console.WriteLine("Paint"); > } > return false; > } > } > > and > > Application.AddMessageFilter(new MF()); > > I've tried putting this in different locations, such as void Main, Form_Load etc > > -- > Michael Culley > >
"Michael Culley" <mc*****@NOSPAMoptushome.com.au> wrote in message
news:ef**************@TK2MSFTNGP12.phx.gbl... "BMermuys" <bm**************@hotmail.com> wrote in message
news:q3*********************@phobos.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
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*********************@phobos.telenet-ops.be... "Michael Culley" <mc*****@NOSPAMoptushome.com.au> wrote in message news:ef**************@TK2MSFTNGP12.phx.gbl... "BMermuys" <bm**************@hotmail.com> wrote in message news:q3*********************@phobos.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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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.
...
|
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:
...
|
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...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
| |