How to make inter-application communication

5 01 2009

description

Consider a situation that more than one application needs to process the same message or two cooperating applications need to communication between themselves, what will we do?

The Windows Application providing a function RegisterWindowMessage to undertake such situations. Actually this function defines a new window message that is guaranteed to be unique throughout the system. This function returns message identifier in the range 0xC000 through 0xFFFF indicates that the message is successfully registered otherwise it returns zero.

Then we can use either SendMessage or PostMessage APIs to send this messages to all top level windows with HWND_BROADCAST as the first parameter.

mycodesnippet

 

 

Application 1

void RegisterMyCustumMsg()
{
   //Register a custom message string
   UINT nMsgID = RegisterWindowMessage(_T("MyCustomMessage"); 
  
   //Assume that it successfully return a message identifier 50037
  
   //Send that message
   ::SendMessage(HWND_BROADCAST,nMsgID,NULL,NULL);
}

Application 2

LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
   //Receives the custom msg that sent from Application 1
   if(50037 == message)
   {
      AfxMessageBox("My Custom Message");
   }
  
   return CDialog::WindowProc(message, wParam, lParam);
}

mynote 

 Only use RegisterWindowMessage when more than one application must process the same message.

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: