We help IT Professionals succeed at work.

Send HWND_BROADCAST Message with text

Mi-Jack
Mi-Jack used Ask the Experts™
on
Hi all,

I need to send a message containing text to another application.
I will not have that application's handle, so I have to use
HWND_BROADCAST.

I am familiar with SendMessage,

private static extern int SendMessage(IntPtr hWnd, int wMsg, int
        wParam, [MarshalAs(UnmanagedType.LPStr)] string lParam);

        private const int HWND_BROADCAST = 0xffff;

        SendMessage(HWND_BROADCAST, ?, 0, "some text");

but I'm not sure which message to use.

Please help - an example of both send and receive will
greatly speed things up for me.

Thank you,

Gene
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
a little bit of p/invoke is required, here is an example that broadcasts message to all the top level windows using C# and Send Message method, hope it helps:-

http://www.sanity-free.org/143/csharp_dotnet_single_instance_application.html

Author

Commented:
>>BuggyCoder
Thank you for your input, but this is exactly the point - I need to send
text, not just any message. The example in your link just sends an empty message (no data).

Which message do I use to send text?

Is it WM_SETTEXT? Will it work?
Application-Defined Messages

An application can create messages to be used by its own windows or to communicate with windows in other processes. If an application creates its own messages, the window procedure that receives them must interpret the messages and provide appropriate processing.

Message-identifier values are used as follows:

1. The system reserves message-identifier values in the range 0x0000 through 0x03FF (the value of WM_USER  – 1) for system-defined messages. Applications cannot use these values for private messages.
2. Values in the range 0x0400 (the value of WM_USER) through 0x7FFF are available for message identifiers for private window classes.
3. If your application is marked version 4.0, you can use message-identifier values in the range 0x8000 (WM_APP) through 0xBFFF for private messages.
   
The system returns a message identifier in the range 0xC000 through 0xFFFF when an application calls the RegisterWindowMessage function to register a message. The message identifier returned by this function is guaranteed to be unique throughout the system. Use of this function prevents conflicts that can arise if other applications use the same message identifier for different purposes.

Read here for more detail:-

http://msdn.microsoft.com/en-us/library/windows/desktop/ms644927%28v=vs.85%29.aspx#app_defined

And here as well:-
http://stackoverflow.com/questions/3289321/c-sharp-capturing-windows-messages-from-a-specific-application
Freelance programmer / Consultant
Commented:
An application sends the WM_COPYDATA message to pass data to another application

You need to look into the help files, there are examples there for classical programs - I don't have any example of using it with the source program that is a .net (eg. C#) application, I've only used it with C++ (which does not have dynamic memory management).

Author

Commented:
Exactly what I was asking for