Solved

Send a Message to an Application

Posted on 1998-04-14
6
201 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
6 Comments
 
LVL 5

Expert Comment

by:yonat
Comment Utility
In MS Windows, use SendMessage() or PostMessage().
0
 

Author Comment

by:khs
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

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

Expert Comment

by:alexo
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Quicksort a dynamic deque 33 57
C++ assignment question 7 127
Writing a parser for java language 4 60
Unable to start eclipse ? 17 82
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now