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

Home Posts Topics Members FAQ

How To Implement IMessageFilter

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

Public Class TestMessageFilt er
Implements IMessageFilter

Public Function PreFilterMessag e(ByRef m As _
System.Windows. Forms.Message) _
As Boolean Implements IMessageFilter. PreFilterMessag e
'Blocks all the messages relating to the left mouse button.
If ((m.Msg >= 513) And (m.Msg <= 515)) Then
Console.WriteLi ne("Process messages: " & m.Msg)
Return True
End If
Return False
End Function
End Class

End Class

I have three basic questions about this code. 1.) How do I specify the
parameter ‘m’ when I call the PreFilterMessag e function? 2.) Where in my
code do I insert the PreFilterMessag e function? 3.) Where to the constants
513 and 515 in the ‘If’ statement come from and how must I change this to
block messages relating to the Mousewheel?

Thanks for your assistance and patience.
--
GrandpaB

Nov 23 '05 #1
4 16778

With a messagefilter you can catch / cancel all events sent to the window
and its controls ( equivalant of subclassing a form in VB6 )

the problem is you need to find the right event code for the message you
want to cancel

here is an example http://www.freevbcode.com/ShowCode.Asp?ID=5635 where it
is jused to dissable the webrowser control`s accelerat
or keys
regards

Michel Posseth [MCP]
"GrandpaB" <Gr******@discu ssons.microsoft .com> wrote in message
news:7E******** *************** ***********@mic rosoft.com...
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

Public Class TestMessageFilt er
Implements IMessageFilter

Public Function PreFilterMessag e(ByRef m As _
System.Windows. Forms.Message) _
As Boolean Implements IMessageFilter. PreFilterMessag e
'Blocks all the messages relating to the left mouse button.
If ((m.Msg >= 513) And (m.Msg <= 515)) Then
Console.WriteLi ne("Process messages: " & m.Msg)
Return True
End If
Return False
End Function
End Class

End Class

I have three basic questions about this code. 1.) How do I specify the
parameter 'm' when I call the PreFilterMessag e function? 2.) Where in my
code do I insert the PreFilterMessag e function? 3.) Where to the
constants
513 and 515 in the 'If' statement come from and how must I change this to
block messages relating to the Mousewheel?

Thanks for your assistance and patience.
--
GrandpaB

Nov 23 '05 #2
1. You don't call PreFilterMessag e, the framework does. You will need to
tell the framework that you have implemented it though. You do this by
calling Application.Add MessageFilter

2. You can implement IMessageFilter in any class you want. I usually do it
in the MainForm and then call AddMessageFilte r(Me) from the Load event
handler.

3. The constants can be found in one of the header files (.h) found in the
folder C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\Platfo rmSDK\Include. You will need to install the C++ part of
Visual Studio to have that directory though. If you can't do that you can
instead install the PlatformSDK which you can download from
<http://www.microsoft.com/downloads/d...128F-A770-45F1
-86F3-7AB010B398A3&di splaylang=en>. The constant you're interested in can be
found in winuser.h and is defined like this:

Private Const WM_MOUSEWHEEL As Integer = &H20A
"GrandpaB" <Gr******@discu ssons.microsoft .com> wrote in message
news:7E******** *************** ***********@mic rosoft.com...
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

Public Class TestMessageFilt er
Implements IMessageFilter

Public Function PreFilterMessag e(ByRef m As _
System.Windows. Forms.Message) _
As Boolean Implements IMessageFilter. PreFilterMessag e
'Blocks all the messages relating to the left mouse button.
If ((m.Msg >= 513) And (m.Msg <= 515)) Then
Console.WriteLi ne("Process messages: " & m.Msg)
Return True
End If
Return False
End Function
End Class

End Class

I have three basic questions about this code. 1.) How do I specify the
parameter 'm' when I call the PreFilterMessag e function? 2.) Where in my
code do I insert the PreFilterMessag e function? 3.) Where to the constants 513 and 515 in the 'If' statement come from and how must I change this to
block messages relating to the Mousewheel?

Thanks for your assistance and patience.
--
GrandpaB

Nov 23 '05 #3
"GrandpaB" <Gr******@discu ssons.microsoft .com> schrieb:
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


<URL:http://dotnet.mvps.org/dotnet/samples/operatingsystem/ScreensaverStar t.zip>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 23 '05 #4
This is a group thanks for your responses. The IMessageFilter is now working
in my application. The application creates, edits and deletes records in a
database. The user was complaining that occasionally data in some records was
changing. The only data fields with which they had difficulty had comboBoxes
as their sources. The users swore that they never touched the mousewheel so
it was my problem. I, of course, blamed Bill Gates.

The Enter and Leave events for the comboBoxes now have an AddMessageFilte r
and RemoveMessageFi lter statements. If this doesn't resolve the problem I'll
know that it really is Bill Gates' fault.

Thanks again,
--
GrandpaB

Nov 24 '05 #5

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

Similar topics

7
6461
by: Michael Culley | last post by:
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) {
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...
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?
4
3399
by: ThunderMusic | last post by:
Hi, I'm developping a form that renders differently when hovered and trigger some processing when not hovered (leaved). The thing is, when I leave my form and another form from my application is underneath, it works fine, but if I leave my form and anything that is not from my application is underneath, the Leave event does not fire until I hover something from my application. Here's my filtered code for the IMessageFilter (I did not...
0
2822
by: emin.shopper | last post by:
I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass magic, I wrote the following module. It is mainly useful as a light weight tool to help programmers catch mistakes at definition time (e.g., forgetting to implement a method required by the given interface). This is handy when unit tests or...
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...
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?
4
3754
by: =?Utf-8?B?am9obmY=?= | last post by:
Trying to get a see windows messages using IMessageFilter interface however it does not seem to get all window messages. Specifically I am looking for the WM_POWERBROADCAST. I override wndproc which shows the msg successfully but nothing shows up when using IMessageFilter. Am i misunderstanding something? Here is sample code: public class MyFilter : IMessageFilter { const int WM_POWERBROADCAST = 0x0218; public bool...
4
3399
by: Ashish Gupra | last post by:
Hi, I want to use 'IMessageFilter' interface to monitor my Key and mouse events to let me know the idle time of my application. But this interface nt works fine. 'PreFilterMessage' function of this interface shows that in every specified time 'MouseMove' event occurs even if there is not movement in mouse. Also If i open a Modal form from that application than this interface does not give messages related to mousemove event in all the...
0
8335
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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,...
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
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
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.