Register Window Message

M

Mircea Pleteriu

Hi All,

Here it is what I want to do
..
I have a Windows Form application (app1) which at a certain moment sends a
registered windows message to other Windows Form application (app2) which
only listen for this window message. When app2 catches the message it
performs some task and then wait again for the message.

All fine by now. Because the app2 does not expose any interaction with the
user (the main window of app2 is minimized to sys tray) I'd like to have the
app running as a .NET Windows service.

Is it possible somehow to have a Windows service application listening to a
registered window message?

Thanks,
Mircea
 
B

Bob Powell [MVP]

You don't "register" windows messages. You can specify any value for the
messsage including a user-defined one that doesn't have some other meaning.
You normally specify the window handle to which the message is to be sent or
you can "broadcast" a message but this isn't a good idea in case other
applications happen to have used the same user-defines messages as you.

I think that the best ways to do what you want would be either through
remoting or to get the window handle of the application you want to
communicate with through the Process class using GetProccesesByName and then
find the window handle for that process and send it a user defined message
directly.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
H

Herfried K. Wagner [MVP]

Bob Powell said:
You don't "register" windows messages. You can specify any value for the
messsage including a user-defined one that doesn't have some other
meaning.

That's true. If more than one application should deal with the message, use
'RegisterWindowMessage' (p/invoke). The documentation of this method
includes information on how to compose user-defined window messages.
 
J

Jeffrey Tan[MSFT]

Hi Mircea,

Thanks for your post.

I am not sure if you are familiar with Windows Security Programming, the
answer is no.
For windows services and for security reason, it actually runs under
another windows station and has its own desktop. We can not send message or
use hook across the desktop boundary(app1 and app2 runs in different
windows desktop), so the windows message way will fail.

We have to resort to some other inter-process communication technology. In
win32 world, we usually use Named Pipe to do this, below is a good article
talks about using Named pipe for inter-process communication in .Net:
"Inter-Process Communication in .NET Using Named Pipes"
http://www.codeproject.com/csharp/DotNetNamedPipesPart1.asp

Furthermore, .Net introduced another wonderful build-in technology named
Net Remoting to do the cross-appdomain communication, and it can be used
in windows service to achieve the same result, please refer to the links
below:
"How To Host .NET Remoting Objects In Windows Service "
http://www.codeproject.com/Purgatory/winservicehost.asp
"How To: Host a Remote Object in a Windows Service"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/ht
ml/SecNetHT15.asp

Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi Mircea,

Does my reply make sense to you? Is your problem resolved? Please feel free
to tell me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top