Click here to Skip to main content
15,894,362 members
Home / Discussions / C#
   

C#

 
Generalbarcode Pin
tonaxxl22-Mar-04 13:56
tonaxxl22-Mar-04 13:56 
GeneralRe: barcode Pin
John Kuhn22-Mar-04 14:04
John Kuhn22-Mar-04 14:04 
GeneralMultiple message filters Pin
bisquic22-Mar-04 11:44
bisquic22-Mar-04 11:44 
GeneralRe: Multiple message filters Pin
Nick Parker22-Mar-04 16:02
protectorNick Parker22-Mar-04 16:02 
GeneralRe: Multiple message filters Pin
bisquic22-Mar-04 16:16
bisquic22-Mar-04 16:16 
GeneralRe: Multiple message filters Pin
Heath Stewart23-Mar-04 4:21
protectorHeath Stewart23-Mar-04 4:21 
GeneralRe: Multiple message filters Pin
bisquic28-Mar-04 19:07
bisquic28-Mar-04 19:07 
GeneralRe: Multiple message filters Pin
Heath Stewart29-Mar-04 3:06
protectorHeath Stewart29-Mar-04 3:06 
Works fine for me. Internally, when you add an IMessageFilter implementation it gets added to an ArrayList, so it doesn't even matter if you add the same instance more than once. If you return true from your PreFilterMessage method (not "function", objects have "methods", btw), then the message does not get dispatched. I looked quickly and didn't find whether or not it is sent to remaining message filters or not right away. More than likely it is.

If you want, verify that things are working with my little test app which adds three message filters, 2 in the static entry point and another in one of the constructors, which makes 2 filters added using the same instance of a class:
using System;
using System.Windows.Forms;

public class Test : Form, IMessageFilter
{
  static void Main()
  {
    Test t = new Test();
    Application.AddMessageFilter(t);
    Application.AddMessageFilter(new MessageFilter());
    Application.Run(t);
  }

  public Test()
  {
    Application.AddMessageFilter(this);
    Text = "Test";
  }

  public bool PreFilterMessage(ref Message m)
  {
    Print(this, m);
    return false;
  }

  internal static void Print(object obj, Message m)
  {
    Console.WriteLine("[{0}] 0x{1:x2} -> 0x{2:x2}",
      obj.GetType().Name, m.Msg, m.HWnd);
  }
}

public class MessageFilter : IMessageFilter
{
  public bool PreFilterMessage(ref Message m)
  {
    Test.Print(this, m);
    return false;
  }
}
Like me, you should get three lines with each message sent to the application pump, like so:
[Test] Message.Msg -> Message.HWnd
[MessageFilter] Message.Msg -> Message.HWnd
[Test] Message.Msg -> Message.HWnd


 

Microsoft MVP, Visual C#
My Articles
GeneralRe: Multiple message filters Pin
bisquic29-Mar-04 3:14
bisquic29-Mar-04 3:14 
GeneralDatagrid to text (values only) Pin
jazzle22-Mar-04 10:42
jazzle22-Mar-04 10:42 
GeneralRe: Datagrid to text (values only) Pin
Nick Parker22-Mar-04 18:02
protectorNick Parker22-Mar-04 18:02 
GeneralRe: Datagrid to text (values only) Pin
jazzle22-Mar-04 21:37
jazzle22-Mar-04 21:37 
GeneralRe: Datagrid to text (values only) Pin
Heath Stewart23-Mar-04 4:24
protectorHeath Stewart23-Mar-04 4:24 
GeneralConverting strings to DateTime structs Pin
profoundwhispers22-Mar-04 10:38
profoundwhispers22-Mar-04 10:38 
GeneralRe: Converting strings to DateTime structs Pin
Edbert P22-Mar-04 12:19
Edbert P22-Mar-04 12:19 
GeneralRe: Converting strings to DateTime structs Pin
profoundwhispers22-Mar-04 12:39
profoundwhispers22-Mar-04 12:39 
GeneralRe: Converting strings to DateTime structs Pin
Edbert P22-Mar-04 13:18
Edbert P22-Mar-04 13:18 
GeneralRe: Converting strings to DateTime structs Pin
Bryan White31-Mar-04 9:59
Bryan White31-Mar-04 9:59 
GeneralEvents in Datagrid Pin
Anonymous22-Mar-04 10:30
Anonymous22-Mar-04 10:30 
GeneralRe: Events in Datagrid Pin
Ruchi Gupta22-Mar-04 11:55
Ruchi Gupta22-Mar-04 11:55 
GeneralRe: Events in Datagrid Pin
Anonymous23-Mar-04 11:15
Anonymous23-Mar-04 11:15 
GeneralSocket Programming - How Do I Send and Receive a Class or Structure Pin
goodpilot22-Mar-04 10:25
goodpilot22-Mar-04 10:25 
GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
Corinna John22-Mar-04 19:48
Corinna John22-Mar-04 19:48 
GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
Heath Stewart23-Mar-04 3:18
protectorHeath Stewart23-Mar-04 3:18 
GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
goodpilot23-Mar-04 4:42
goodpilot23-Mar-04 4:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.