473,228 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,228 software developers and data experts.

Not getting all window messages from IMessageFilter?

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 PreFilterMessage(ref Message m)
{
if m.Msg == WM_POWERBROADCAST)
{
Console.WriteLine("Power Broadcast recieved.");
}
return false;
}
}
class MainForm : Form
{

public MainForm() //MainForm's constructor
{
}
public static void Main()
{

Application.AddMessageFilter(new MyFilter());
Application.Run(new MainForm());
}
}

Jun 27 '08 #1
4 3713
On Fri, 16 May 2008 11:21:27 -0700, johnf
<jo***@discussions.microsoft.comwrote:
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?
It's been awhile since I did lots of Win32 stuff, so this is just a
guess. But WM_POWERBROADCAST is probably sent by the system using
HWND_BROADCAST and SendMessage(), bypassing the message queue. At the
same time, message filtering is as I understand it done through the
message dispatch system, which would apply only to messages going through
the thread's message queue.

If that's all correct, that would explain why you aren't seeing that
particular message in the IMessageFilter implementation.

It's probably better to use the WndProc() override anyway. Using the
message filtering is a pretty broad brush, as you wind up looking at
_every_ single message that goes through the queue. The message you're
looking for will never be seen by most of the window instances in your
application (it's only sent to top-level windows) so even if filtering did
work, it's a waste of time. I think it's better to just watch for it in a
top-level window you have in your application, using WndProc().

Pete
Jun 27 '08 #2
Hi Pete,
Thanks for the response, however ultimately I am incorporating this into a
service, so it wont be possible to override wndproc. According to this doc
(about halfway down)
http://msdn.microsoft.com/en-us/libr...47(VS.85).aspx
It suggests for console / service apps it is possible to get these msgs.
-John

"Peter Duniho" wrote:
On Fri, 16 May 2008 11:21:27 -0700, johnf
<jo***@discussions.microsoft.comwrote:
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?

It's been awhile since I did lots of Win32 stuff, so this is just a
guess. But WM_POWERBROADCAST is probably sent by the system using
HWND_BROADCAST and SendMessage(), bypassing the message queue. At the
same time, message filtering is as I understand it done through the
message dispatch system, which would apply only to messages going through
the thread's message queue.

If that's all correct, that would explain why you aren't seeing that
particular message in the IMessageFilter implementation.

It's probably better to use the WndProc() override anyway. Using the
message filtering is a pretty broad brush, as you wind up looking at
_every_ single message that goes through the queue. The message you're
looking for will never be seen by most of the window instances in your
application (it's only sent to top-level windows) so even if filtering did
work, it's a waste of time. I think it's better to just watch for it in a
top-level window you have in your application, using WndProc().

Pete
Jun 27 '08 #3
On Fri, 16 May 2008 12:00:02 -0700, johnf
<jo***@discussions.microsoft.comwrote:
Hi Pete,
Thanks for the response, however ultimately I am incorporating this into
a
service, so it wont be possible to override wndproc.
Win32 services can create a message-only window. At the very least, you
should be able to accomplish the same in your service via p/invoke. I
don't know of any .NET support for that, but it might exist.
According to this doc
(about halfway down)
http://msdn.microsoft.com/en-us/libr...47(VS.85).aspx
It suggests for console / service apps it is possible to get these msgs.
Well, that page is for Windows Mobile (CE). It's possible that the
technique works on Windows Mobile but not regular Windows. What platform
are you testing this on? It's also possible that the documentation is
simply incorrect. That could either be an error in the documentation, or
some bug in .NET.

Sorry I don't have anything more detailed.

Pete
Jun 27 '08 #4
Actually the link is for Mobile PC's (laptops?) not CE. The topic covers
Power Management in Windows XP and Vista. Thanks for the input Pete, if
anyone has anything else, greatly appreciated...

"Peter Duniho" wrote:
On Fri, 16 May 2008 12:00:02 -0700, johnf
<jo***@discussions.microsoft.comwrote:
Hi Pete,
Thanks for the response, however ultimately I am incorporating this into
a
service, so it wont be possible to override wndproc.

Win32 services can create a message-only window. At the very least, you
should be able to accomplish the same in your service via p/invoke. I
don't know of any .NET support for that, but it might exist.
According to this doc
(about halfway down)
http://msdn.microsoft.com/en-us/libr...47(VS.85).aspx
It suggests for console / service apps it is possible to get these msgs.

Well, that page is for Windows Mobile (CE). It's possible that the
technique works on Windows Mobile but not regular Windows. What platform
are you testing this on? It's also possible that the documentation is
simply incorrect. That could either be an error in the documentation, or
some bug in .NET.

Sorry I don't have anything more detailed.

Pete
Jun 27 '08 #5

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

Similar topics

3
by: NeverLift | last post by:
But, if it's not open, I don't want to open it . . . using window.open will open it if it doesn't exist, even if the url in that open is null (the window is then empty -- but it's open). The...
18
by: lawrence | last post by:
If I'm pretty sure there is just one form on the page, can i do this? var myForm = document.forms; If I'm not sure about the form, is it safer to do this? if (document.forms) { var myForm =...
2
by: Flo | last post by:
Hi all, i am trying to catch system message to be notified when any window would be created or even closed. I've looked at the API messages sent, but it appears that the messages (WM_CREATE or...
4
by: KlassifiedBBS | last post by:
I want to create a game bot for a video chat program with a closed API. I can see the windows messages when I hook up Spy++ to the window in question. I have done numerous Googles for some kind...
14
by: | last post by:
Hi All, I am little confused here, hope you can help me. While processing WM_POWERBROADCAST (wParam=PBT_APMQUERYSUSPEND), I MUST to do some lengthy operation(30 sec) before system Suspends or...
3
by: feng | last post by:
In our VB.Net Windows application we need to implement a "timeout" type of funtionality - If the the user leave the application idle for certain peroid of time, depending on configureable setting,...
4
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...
1
by: news.microsoft.com | last post by:
Hello How can I write a C# Windows Forms application so that it tells if it receives foreign windows messages. Foreign, say something like when another application takes its HWND and issues a...
2
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...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...

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.