Solved

Sending a user defined message to a Process ?

Posted on 2001-06-28
9
254 Views
Last Modified: 2013-11-20
Hi,

I have an application which calls another EXE using CreateProcess(..). This EXE is a standard window which can have multiple views. What I want is to be able to send a message to the EXE  telling it to do something.  I managed to get the HANDLE of the Window by searching for the title of the dialog. I issued a ::PostMessage(hWnd,WM_MYMESSAGE,0,0) to it, and have an ON_MESSAGE(WM_MESSAGE..) in the EXE source, but nothing happens. Could someone give precise answers to what could be wrong and how to solve it?

Thanks,
Sintax
0
Comment
Question by:Sintax
  • 4
  • 3
  • 2
9 Comments
 
LVL 12

Expert Comment

by:migel
ID: 6234593
Hi!
show your code for OnMessage handler in the target app.
In what message map you add such haandler?
Are you shure that  finded HWND hwnd of the Main Window of your application?
0
 
LVL 1

Author Comment

by:Sintax
ID: 6234613
hi,
To be simple, let's call "A" the application which needs to mesasge the other ("B")

In "A":
HWND hWnd;

hWnd =  ::FindWindow(NULL,"Database Window");
if (hWnd != NULL)
{
  ::PostMessage(m_hWnd,WM_MYMESSAGE,0,0);
}

The handle IS correct since If I issue a WM_QUIT then B closes.

In "B" the main class has the following:
BEGIN_MESSAGE_MAP(CBApp, CWinApp)
...
     ON_MESSAGE(WM_MYMESSAGE, WMDOSG)
END_MESSAGE_MAP()

and WMDOSG() is defined as follows:
void CBApp::WMDOSG()
{
  AfxMessageBox("I GOT THE MESSAGE");
}

but the message box is never displayed, so it doesn't get the message. Maybe because its a separate process??

Sintax
0
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 6234797
That is done by using 'ON_REGISTERED_MESSAGE()':

// example for ON_REGISTERED_MESSAGE
const UINT    wm_CustomMessage = RegisterWindowMessage( CUSTOMMSGSTRING );
BEGIN_MESSAGE_MAP( CMyWnd, CMyParentWndClass )
    //{{AFX_MSG_MAP( CMyWnd )
    ON_REGISTERED_MESSAGE( wm_CustomMessage, OnCustomMessage )
    // ... Possibly more entries to handle additional messages
    //}}AFX_MSG_MAP
END_MESSAGE_MAP( )

The 1st app would the use

const UINT    wm_CustomMessage = RegisterWindowMessage( CUSTOMMSGSTRING );

PostMessage ( hTargetWnd, wm_CustomMessage, wParam, lParam);

Feel free to ask if you need more information or would need another example!
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 1

Author Comment

by:Sintax
ID: 6234962
I already tried registering the message (both sides, same string), but it seems that the messages are NOT getting to the window. Is there a reason that it doesn't get there?
0
 
LVL 86

Expert Comment

by:jkr
ID: 6235020
>>Is there a reason that it doesn't get there?

There shouldn't be one, if the MSG strings passed to 'RegisterWindowsMessage()' are identical - could you post more of your code?
0
 
LVL 12

Expert Comment

by:migel
ID: 6235436
Hi!
can you run SPY++ and watch what message come to the B app main window?
0
 
LVL 1

Author Comment

by:Sintax
ID: 6237066
I tried Spy++, I moved the cross in find window over B, it was able to get the handle and the title, but when I said OK, it displayed "No window matches search criteria!". This is weird.. since it found the window. What could be wrong?
0
 
LVL 12

Expert Comment

by:migel
ID: 6237118
Try press F5 in the spy before dragging cross to the window (this updates windows list in the SPY)
0
 
LVL 1

Author Comment

by:Sintax
ID: 6244146
Thanx jkr and everybody who helped me !! It works now. I had to use the mainframe. Although now I have another problem. I need to acess the View's public function. How can I access this from MainFrm ???


Sintax
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
viewing source code from eclipse 13 107
no14 challenge 14 67
wordmultiple challenge 12 133
Trying to run powershell  in a batch file. How do I do this? 8 92
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

777 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