Link to home
Start Free TrialLog in
Avatar of Sintax
Sintax

asked on

Sending a user defined message to a Process ?

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
Avatar of migel
migel

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?
Avatar of Sintax

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sintax

ASKER

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?
>>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?
Hi!
can you run SPY++ and watch what message come to the B app main window?
Avatar of Sintax

ASKER

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?
Try press F5 in the spy before dragging cross to the window (this updates windows list in the SPY)
Avatar of Sintax

ASKER

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