Solved

Send a Message to an Application

Posted on 1998-04-14
6
206 Views
Last Modified: 2010-04-10
I'd like to send a message in my application to other
applications.
my application receives data from serial port and process
these data. once i finish this process  i want to notify
 any other applications of getting theses data or use theses data.how can i send message to other application.
0
Comment
Question by:khs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 5

Expert Comment

by:yonat
ID: 1184288
In MS Windows, use SendMessage() or PostMessage().
0
 

Author Comment

by:khs
ID: 1184289
sorry! your answer is not suite for me. i'd like to konw detailed
example code.
I already know SendMessage() and PostMessage() functions.


0
 

Accepted Solution

by:
gds earned 100 total points
ID: 1184290
In 32-bit Windows there are several ways of doing an inter-process communication:

1.  You can set up a piece of global shared memory, using CreateFileMapping, OpenFileMapping and MapViewOfFile.  Then use a named mutex to control access to the shared memory, and a global named event to signal from the source to the client that new data is available.

2.  Use a named pipe.  Make the client app listen on a pipe, and have the source app stuff data into the pipe.  This has the advantage over (1) that the two processes can be on separate computers.

3.  Use an RPC call from the source to the client.  You can configure an RPC to work purely locally using a lightweight RPC, so the processes can be on the same computer.

4.  Failing all of that, use

PostMessage(HWND_BROADCAST,msgMyMessage,0,0)

where msgMyMessage is a userdefined message ID obtained from a call to RegisterWindowMessage.  All top-level windows will receive the message, but (presumably) only your client apps will understand the registered message.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:khs
ID: 1184291
I don't understand your answer.I am a novice.
I am using now MFC 5.0 .
0
 
LVL 11

Expert Comment

by:alexo
ID: 1184292
Sending messages to other applications is easy.  You need to aquire the window handle of the other application window you'd like to send messages to.  For example, you can use:

    hwnd = FindWindow(NULL, "the title of the window");
    if (hwnd != NULL)
        PostMessage(hwnd, message, 0, 0);

Or, you can broadcast a message to all windows in the system:

    PostMessage(HWND_BROADCAST, message, 0, 0);

Where "message" is either one of the standard messages (WM_xxx) or a user-defined one.

You can define messages for inter-application communications by asking Windows to provide a unique message number:

    message = RegisterWindowMessage("Message ID string");

Note that the program that receives the message should now how to deal with it :-)

Is this a satisfactory answer?

0
 

Expert Comment

by:Skrobotz
ID: 1184293
Use the Command:

In the Sending Program use
RegisterWindowMessage(..)
and
PostMessage(..)

In the program that must recieve the message use the command
RegisterWindowMessage(..) and wrote a Routine to process the Message.


0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question