Click to See Complete Forum and Search --> : RegisterWindowMessage


mambohoe81
February 14th, 2006, 12:14 PM
Hi all,
I was trying to use the code at http://www.codeproject.com/internet/SocketFileTransfer.asp and i encountered this declaration:

const UINT UWM_FILESENDEVENT= ::RegisterWindowMessage(_T( "UWM_FILESENDEVENT_27580DB4_1360_4062_BB4E_C5C894E90CCC" ) );

Putting this in my code does not seem to work. How do i change the address accordingly? Cos everything else i've used is the same so i suspect its this declaration which is not updating the changes to the threads accordingly. Any remedies for this?

kirants
February 14th, 2006, 12:31 PM
Please explain what you mean by code does not seem to work.
Is it a compilation problem, if so what is the error ?
Is it a runtime problem, if so what sort of problem ?
And what threads are you talking of.. there is so much fundamental info that is missing in your post that it is difficult for anyone to be able to help you.

ovidiucucu
February 14th, 2006, 12:35 PM
RegisterWindowMessage defines a window message that is guaranteed to be unique throughout the system.
It is typically used to register messages for communicating between applications.

So, what's not working?
Please, details.

MikeAThon
February 14th, 2006, 12:56 PM
I authored the code you are questioning. It's a technique for assigning a unique value to a UINT for a message which will be used for inter-thread communication. The message signifies that there has been a "file send event"; hence the name UWM_FILESENDEVENT.

The long sequence of digits at the end (i.e., "27580DB4_1360_4062_BB4E_C5C894E90CCC") is an arbitrary but unique GUID.

For a more detailed description of this technique, see the "Message Management" essay by Joseph M. Newcomer at http://www.flounder.com/messages.htm

Mike

ovidiucucu
February 14th, 2006, 01:18 PM
I authored the code you are questioning. It's a technique for assigning a unique value to a UINT for a message which will be used for inter-thread communication.Better said is for "inter-process communication". That's is usual but not absolutely required.
The message signifies that there has been a "file send event"; hence the name UWM_FILESENDEVENT.
Just naming convention, don't trust in it. Better take a look in it's handler function to see what really does.
The long sequence of digits at the end (i.e., "27580DB4_1360_4062_BB4E_C5C894E90CCC") is an arbitrary but unique GUID.
Yes, indeed looks like a "GUID" but can be "the quick brown fox jumps over the lazy dog" as well ;). Just you have somehow to assure it's unique (for that somebody used Guidgen tool), and identical in RegisterWindowMessage call for the sender and receiver application.

MrViggy
February 14th, 2006, 04:27 PM
Better said is for "inter-process communication". That's is usual but not absolutely required.

Just naming convention, don't trust in it. Better take a look in it's handler function to see what really does.

Yes, indeed looks like a "GUID" but can be "the quick brown fox jumps over the lazy dog" as well ;). Just you have somehow to assure it's unique (for that somebody used Guidgen tool), and identical in RegisterWindowMessage call for the sender and receiver application.
Heh, since MikeAThon said he authored the code, I think I can believe him without having to read the code.

:cool:

Viggy

MikeAThon
February 14th, 2006, 04:35 PM
Hehe ;)

mambohoe81
February 15th, 2006, 12:41 AM
Sorry for the lack of info, this was not a compilation error. It is just that when i use the PostMessage function like what Mike did, the application does not update itself like what its supposed to do. I have already included a declaration to the handler section of the file in the .h file. I just did not know why it was not updating and so i suspected its the RegisterWindowMessage. Below is the part of the code used :

afx_msg LRESULT CSockDlg::OnFileSendEvent(WPARAM wParam, LPARAM lParam)
{
switch ( wParam )
{
case FSE_THREADSTART:

m_ctlStatus.SetWindowText( "Waiting for file acceptance ..." );
break;

case FSE_THREADCOMPLETE:

m_ctlStatus.SetWindowText( "Status: Idle" );
m_ctlProgress.SetPos( 0 );
m_pThread = NULL;
break;

case FSE_UPDATECONTROLS:
{
}
break;

case FSE_STATUSCONNECTED:

m_ctlStatus.SetWindowText( "Connection accepted -- sending file ..." );
break;

default:
ASSERT( FALSE ); // shouldn't get here
}

return 0L;
}


PostMessage was called in another function in this kind of format:

pThis->PostMessage( UWM_FILESENDEVENT, FSE_THREADSTART, 0L );
pThis->PostMessage( UWM_FILESENDEVENT, FSE_STATUSCONNECTED, 0L );

kirants
February 15th, 2006, 11:40 AM
DO you have a message map entry like this in your CSockDlg class

ON_MESSAGE(UWM_FILESENDEVENT,OnFileSendEvent)

mambohoe81
February 15th, 2006, 01:11 PM
Oh yes you hit on the right spot! Seems like i missed out the message map entry. When i put this in:

ON_REGISTERED_MESSAGE( UWM_FILESENDEVENT, OnFileSendEvent )


everything was fine! Thank you all for the valuable help. Sorry i led all of you to the wrong direction initially.

MikeAThon
February 15th, 2006, 03:42 PM
Thanks, Kiran, for solving this so efficiently ;)

Mike

kirants
February 15th, 2006, 03:53 PM
You are welcome, Mike :wave:
I solved it erratically, though :)
Mentioned ON_MESSAGE when it should've been ON_REGISTERED_MESSAGE ;)
Anyways, all's well that ends well !!