Window messages

  • Thread starter Thread starter Darren Mar-Elia
  • Start date Start date
D

Darren Mar-Elia

I have an app I'm writing in .net 2.0. Basically all I want visible in the
app is a system tray icon, that then launches a Windows form for
configuration. I want to trap Window messages and, when I see a particular
message, do some work. It works fine if a Windows form is up and visible but
I don't want any visible forms on the screen, yet I still want to capture
the messages. Is there a best practice on doing this? Right now I'm
basically overriding WndProc in my form code. I tried starting the app with
the form not visible but that doesn't appear to work. Not sure why.So, I
guess the question is, what is the best way to wait for window messages
without having a visible form?

--
Darren Mar-Elia
MS-MVP-Windows Server--Group Policy
http://www.gpoguy.com -- The Windows Group Policy Information Hub:
FAQs, Training Videos, Whitepapers and Utilities for all things Group
Policy-related

Speed Group Policy Troubleshooting with the NEW GPHealth Reporter tool at
http://www.sdmsoftware.com/products.php
 
I am not sure this will serve your needs or not, but one way you can
catch messages is to use an object that implements IMessageFilter. In
your code, you use

Application.AddMessageFilter(new MessageFilter());

to indicate your want window messages to be looked at by the
MessageFilter object defined by a class such as:

public class MessageFilter : IMessageFilter
{
#region IMessageFilter Members

public bool PreFilterMessage(ref Message m)
{
Console.WriteLine(m);
return false; //not handled
}

#endregion
}

===================
Clay Burch
Syncfusion, Inc.
 
Thanks for this. I actually tried this approach but for some reason, I am
not getting the window message code I'm expecting. The code I'm getting is
not even found in the winuser.h file and so I'm wondering if I'm getting
multiple messages at once using this approach and the codes are being OR'd
or AND'd in the message filter? Otherwise, it works great in terms of
catching message without an active form up.
 
Back
Top