INTERACT FORUM

Windows => Plug-in Development => Topic started by: Reonekot on December 16, 2010, 05:21:25 am

Title: Receive Windows broadcast messages from plugin
Post by: Reonekot on December 16, 2010, 05:21:25 am
I'm playing around with a MediaJukeboxAutomation plug-in for the Snarl notification system and have run into a small problem I can't seem to solve. When Snarl is started or exits it sends a global Window message to all top level Windows. In my plug-in I need to catch this message, so I can register with Snarl. But since my MJ UserControl (C#) isn't a top level Window, the control doesn't get the message. I tried creating a new form and setting it's TopLevel property to true, but that didn't work either for some reason.

Anyone has an idea to how I can get the global broadcast message from .NET, without hooking MJ's message loop?
Title: Re: Receive Windows broadcast messages from plugin
Post by: danrien on June 18, 2011, 06:22:43 pm
I have a similar issue :(
Title: Re: Receive Windows broadcast messages from plugin
Post by: Reonekot on June 19, 2011, 03:07:50 am
My problem actually mostly boiled down to me running MJ as administrator (because I launched it from an elevated Visual Studio) and Snarl running non elevated. What I have now is a .NET NativeWindow (http://msdn.microsoft.com/en-us/library/system.windows.forms.nativewindow.aspx) and that works fine when both sender and receiver runs non elevated.
Title: Re: Receive Windows broadcast messages from plugin
Post by: danrien on June 20, 2011, 11:28:06 pm
I fixed it by using user32.dll's, and intercepting the WindProc messages, doing what I need with them, and then returning them to MC.

Did you just make your plug-in inherit the NativeWindow class, instead of the UserControl class?
Title: Re: Receive Windows broadcast messages from plugin
Post by: danrien on June 20, 2011, 11:40:08 pm
Ohhhh nevermind, I thought you meant intercept Media Center's messages. You just want to intercept the messages sent to your control, from looking at the NativeWindow class... unless I'm making a fool of myself here....
Title: Re: Receive Windows broadcast messages from plugin
Post by: Reonekot on June 21, 2011, 02:17:03 am
My problem was about getting my plugin to catch global windows broadcast messages (messages registered through RegisterWindowMessage()) - a it all boiled down to running receiver and sender running under different user rights. (Elevate vs. non elevated)

Anyway, to hook MJ/MC can't you just create a NativeWindow and Attach it via the MJ/MC window handle? (Don't know if this is what you already did...)
Title: Re: Receive Windows broadcast messages from plugin
Post by: danrien on June 22, 2011, 08:20:42 pm
Perhaps... I looked into using NativeWindow, didn't really seem to be many obvious examples that do something like intercept a different handle's messages (although a few intercept their parent forms messages), but the examples I found for doing it with user32.dll were all over the place, so I guess that's what I went with... seems to work very well though, and basically allows me to intercept messages for any window handle I have (obviously, when I need messages for the plug-in, I just override WndProc, however).

Also, NativeWindow seems to be for pop-up windows, am I incorrect on this?  I don't need a pop-up window, so if that was the case it wouldn't be necessary.  IDK, MSDN is a little sketchy on this....
Title: Re: Receive Windows broadcast messages from plugin
Post by: Reonekot on June 23, 2011, 02:38:23 am
Looking at the documentation it looks like NativeWindow will only allow you to hook a window in the same process, but if the window is in the same process it should work fine I think. (Not sure where you found it only works for windows with POPUP style?) Anyway, NativeWindow is probably just a wrapper around P/Invoke stuff.