Solved

How to communicate between two applications with SendMessage() ?

Posted on 1998-02-28
6
203 Views
Last Modified: 2013-11-20
Hi,
I want to communicate between two applications with calling of ::SendMessage(). Where can I find the parameter description for SendMessage, which are allowed. And where must I implement the Message-Handler in my main program, that is getting the message, in CMainFrame or in one of the CView's and how must I implement this Message-Handler ?

Thanks.
0
Comment
Question by:atari
  • 3
  • 3
6 Comments
 
LVL 4

Accepted Solution

by:
jtwine100697 earned 80 total points
Comment Utility
First, create a custom message by either #define-ing a message value (WM_USER + 0x24), or by using RegisterWindowMessage(...).

Then create an ON_MESSAGE, or ON_REGISTERED_MESSAGE, (see help for ON_MESSAGE/ON_REGISTERED_MESSAGE) handler.  Depending on how you want the application to respond determines where to place the handler:  If you want the app to respond when it is up, place it in CMainFrame.  If you want it to respond "while it has a document open", place it in the View class.

It would also help to know what type of data you wish to send between the applications.

-=- James.
0
 
LVL 1

Author Comment

by:atari
Comment Utility
I have found an example on codeguru-website under MISC for RegisterWindowMessage(). I have programmed a main-mdi-application and if i push a button in the toolbar of CMainFrame a second sdi-application will be launched implement as CListView. If the user select some items of this CListView and right-click on it a popup-menu appears with some options, maybe open a new CMDIChildWnd or a new View of my main-mdi-application. Also the sdi-application should be, after sending a SendMessage() to my main-application disappear to the task-bar in order to show my main-application again. I also implemented some drag-and-drop-operations by clicking on an item in my launched sdi-ListView-program to any of my mdi-windows in my main-program.

that's what I wanted to do. It's nearly the same as the 'history-window' called, if you press Strg-H in the Netscape browser.

Maybe you have still further ideas. Maybe I increase the points for it, if I get any good answer.
0
 
LVL 4

Expert Comment

by:jtwine100697
Comment Utility
I am still not fully clear on what exactly you are trying to communicate between both applications.  Sounds like simple values will work fine, if you need to pass strings, register them as Atoms, and pass the Atom value between applications.

-=- James.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:atari
Comment Utility
My application, that I have launched, shows items in a CListView as a list. If the user clicks one or several items in this list and then right click with the mouse on one of these selected items, a popup-menu appears, in which the user can select a menu-item, which creates a new child-window in my main-mdi-application, from where the CListView had been launched, showing in the new child-window the items as graphic-objects, that I selected. This is one way, that I want to communicate between my two applications. Also if I close my main-application the main-application must send a WM_CLOSE-message to my launched application and so on.
I used #define WM_MYMESSAGE   (WM_USER+0x0200) and send the message with
::SendMessage(hwndlaunchedprogram,WM_MYMESSAGE,0,0) and after some try and error work everything works fine. But there is a new problem. ::FindWindow(Null,"applicationname");
is very difficult to handle if you have a mdi-application with several windows, having all their own names, and can be maximized or not, so the CMainFrame-name of the application can change in many ways. I don't know the correct way for implementing AfxRegisterWindowClass, because I created with template-structure and not dynamically with Create(), so do you know, if there is another way to receive the window-handle of a mdi-application ? The CMainFrame-Name of my application never changes, but if there are mdi-child-windows maximized then their name is added to the CMainFrame-name and the ::FindWindow()-function is always searching for the whole CMainFrame-name. Is there any other way to find out a running application ?
After this I will grade your answer. Thank you so far.
0
 
LVL 4

Expert Comment

by:jtwine100697
Comment Utility
Override CFrameWnd::PreCreateWindow(), in your worker (display) applications.

   To create, and use, a new (custom) WNDCLASS, do something like this:

static   CString gs_sNewClassName = "atari_MyDisplayAppFrameClass";

BOOL    CMainFrame::PreCreateWindow( CREATESTRUCT cs )
{
   WNDCLASS    wcOldWndClass;
   WNDCLASS    wcNewWndClass;

   GetClassInfo( NULL, AfxGetInstanceHandle(), &wcOldWndClass );
   wcNewWndClass = wcOldWndClass;

   wcNewWndClass.lpszClassName = gs_sNewClassName;

   if( AfxRegisterClass( wcNewWndClass ) )
      cs.lpszClass = gs_sNewClassName;

   return( CMDIFrameWnd::PreCreateWindow( cs ) );
}

   Then, when looking for your worker/display app's windows, use FindWindow( gs_sNewClassName, NULL );

-=- James.
0
 
LVL 1

Author Comment

by:atari
Comment Utility
Hi, this was a great information. How did you find out that source code ?

I will try it and hope that it will work. Using ::FindWindow with application-name was hard work, because I had to loop all the possible names of my mdi-child-windows. The above code should be much easier.

Thank you, I will increase the points for this helpful answer since a lot of time, that I'm waiting  for other answers, that didn't come until yet.

I believe there is always a way in MFC, but you must find out in every specific case, what's the best way to do.

Thank you very much.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 74
Login Script to Copy Folders 12 21
cat dog challenge 18 122
wordappend challenge 8 84
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

17 Experts available now in Live!

Get 1:1 Help Now