Click here to Skip to main content
16,007,932 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: A intresting problem,hope any Felloow Programmer solve it Pin
Johan Rosengren10-Jul-04 22:38
Johan Rosengren10-Jul-04 22:38 
GeneralRe: A intresting problem,hope any Felloow Programmer solve it Pin
ThatsAlok10-Jul-04 23:09
ThatsAlok10-Jul-04 23:09 
GeneralRe: A intresting problem,hope any Felloow Programmer solve it Pin
Johan Rosengren10-Jul-04 23:15
Johan Rosengren10-Jul-04 23:15 
GeneralRe: A intresting problem,hope any Felloow Programmer solve it Pin
ThatsAlok10-Jul-04 23:52
ThatsAlok10-Jul-04 23:52 
GeneralRe: A intresting problem,hope any Felloow Programmer solve it Pin
ThatsAlok10-Jul-04 23:00
ThatsAlok10-Jul-04 23:00 
GeneralRe: A intresting problem,hope any Felloow Programmer solve it Pin
Johan Rosengren10-Jul-04 23:10
Johan Rosengren10-Jul-04 23:10 
GeneralRe: A intresting problem,hope any Felloow Programmer solve it Pin
ThatsAlok10-Jul-04 23:45
ThatsAlok10-Jul-04 23:45 
GeneralRe: A intresting problem,hope any Felloow Programmer solve it Pin
Johan Rosengren11-Jul-04 0:16
Johan Rosengren11-Jul-04 0:16 
Alok the programmer wrote:
you quoted " How do you identify the window you are sending it to?"
what that's


The window you send the message to. If you don't get this right, you'll of course never receive any messages in your application.

Now, for practicalities:

Create a dialog application called "Sender". Add a button and a button handler. In the button handler, add the following code:

void CSenderDlg::OnButton1() 
{
  HWND hwnd = ::FindWindow( _T( "#32770" ), _T( "Receiver" ) );
  UINT hello = ::RegisterWindowMessage( _T( "TEST_MESSAGE" ) );

  if( hwnd )
    ::PostMessage( hwnd, hello, 0, 0 );
}


You don't have to register the message everytime, and should use something more sensible as the id string. FindWindow is the interesting part here, it looks for a dialog (window class "#32770") with the title "Receiver".

Create another dialog application, called "Receiver". Either create it modeless, pumping messages yourself or a modal dialog. Let's start with a modal one (the default).

Register the message so:

UINT hello = ::RegisterWindowMessage( _T( "TEST_MESSAGE" ) );


Add a messsage map entry:

<pre
on_registered_message(="" hello,="" onhello="" )
<="" pre="">

Declare <code>OnHello </code>in the header:

<pre>
LRESULT OnHello( WPARAM, LPARAM );


Implement OnHello:

LRESULT CReceiverDlg::OnHello( WPARAM, LPARAM )
{

  AfxMessageBox( _T( "Message received" ) );
  return 0;

}


Now, start the application. Also start Sender. Press the button in Sender, and you'll see the message box pop up.

If you want it modeless, you must pump your own messages, use this in the application InitInstance:

CReceiverDlg dlg;
m_pMainWnd = &dlg;
dlg.Create( CReceiverDlg::IDD );
while ( PumpMessage() )
;


You'll also need to override OnCancel in the dialog class, calling DestroyWindow instead of the base class implementation.

Finally, make the window invisible. You'll now have to enumerate all the windows on the desktop, as you don't have the title to look for. You can also start by broadcasting the HWND from receiver as the application starts - and handle this message in Sender, this depends on the final structure of the application.

Alok the programmer wrote:
one note also,when i give it curent desktop pointer,it working fine in non service based application.

I can make no sense out of this, what are you giving the desktop window?
GeneralRe: A intresting problem,hope any Felloow Programmer solve it Pin
ThatsAlok11-Jul-04 0:42
ThatsAlok11-Jul-04 0:42 
GeneralRe: A intresting problem,hope any Felloow Programmer solve it Pin
Johan Rosengren11-Jul-04 1:10
Johan Rosengren11-Jul-04 1:10 
GeneralRe: A intresting problem,hope any Felloow Programmer solve it Pin
ThatsAlok11-Jul-04 2:06
ThatsAlok11-Jul-04 2:06 
GeneralRe: A intresting problem,hope any Felloow Programmer solve it Pin
Johan Rosengren11-Jul-04 2:48
Johan Rosengren11-Jul-04 2:48 
GeneralRe: A intresting problem,hope any Felloow Programmer solve it Pin
ThatsAlok11-Jul-04 3:07
ThatsAlok11-Jul-04 3:07 
GeneralRe: A intresting problem,hope any Felloow Programmer solve it Pin
Johan Rosengren11-Jul-04 5:58
Johan Rosengren11-Jul-04 5:58 
GeneralRe: A intresting problem,hope any Felloow Programmer solve it Pin
ThatsAlok11-Jul-04 6:10
ThatsAlok11-Jul-04 6:10 
GeneralRe: A intresting problem,hope any Felloow Programmer solve it Pin
Johan Rosengren11-Jul-04 6:15
Johan Rosengren11-Jul-04 6:15 
GeneralAtlast Our Discussion End. Pin
ThatsAlok11-Jul-04 21:45
ThatsAlok11-Jul-04 21:45 
GeneralRe: Atlast Our Discussion End. Pin
Johan Rosengren11-Jul-04 21:52
Johan Rosengren11-Jul-04 21:52 
GeneralRe: A intresting problem,hope any Felloow Programmer solve it Pin
parths11-Jul-04 0:36
parths11-Jul-04 0:36 
GeneralRe: A intresting problem,hope any Felloow Programmer solve it Pin
ThatsAlok11-Jul-04 0:54
ThatsAlok11-Jul-04 0:54 
GeneralRe: A intresting problem,hope any Felloow Programmer solve it Pin
bikram singh11-Jul-04 3:59
bikram singh11-Jul-04 3:59 
GeneralRe: A intresting problem,hope any Felloow Programmer solve it Pin
Michael P Butler10-Jul-04 3:42
Michael P Butler10-Jul-04 3:42 
GeneralRe: A intresting problem,hope any Felloow Programmer solve it Pin
ThatsAlok10-Jul-04 5:00
ThatsAlok10-Jul-04 5:00 
GeneralRe: A intresting problem,hope any Felloow Programmer solve it Pin
bikram singh11-Jul-04 3:53
bikram singh11-Jul-04 3:53 
GeneralRe: A intresting problem,hope any Felloow Programmer solve it Pin
ThatsAlok11-Jul-04 6:04
ThatsAlok11-Jul-04 6:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.