Solved

How to communicate between two applications with SendMessage() ?

Posted on 1998-02-28
6
204 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand LInux Boot partition remotly 3 86
Add content to output file 4 62
Named range not carried over 10 62
mapBully challenge 6 115
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

896 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

13 Experts available now in Live!

Get 1:1 Help Now