[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to communicate between two applications with SendMessage() ?

Posted on 1998-02-28
6
Medium Priority
?
210 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
[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
  • 3
  • 3
6 Comments
 
LVL 4

Accepted Solution

by:
jtwine100697 earned 320 total points
ID: 1316667
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
ID: 1316668
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
ID: 1316669
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
Industry Leaders: 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!

 
LVL 1

Author Comment

by:atari
ID: 1316670
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
ID: 1316671
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
ID: 1316672
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

Industry Leaders: 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

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

650 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