Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2007

Tip: Looking for answers? Try searching our database.

Window messages

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Darren Mar-Elia - 08 Feb 2007 05:27 GMT
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?

Signature

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

ClayB - 08 Feb 2007 09:20 GMT
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.
Darren Mar-Elia - 14 Feb 2007 00:01 GMT
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.

>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
[quoted text clipped - 21 lines]
> Clay Burch
> Syncfusion, Inc.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.