Post by amccombsI am using VC6. I have a dialog box application. I used Class Wizard and
added OnCopyData. The wizard added
[code]
return CDialog::OnCopyData(pWnd, pCopyDataStruct);
[/code]
I have read the MSDN,
http://msdn2.microsoft.com/en-us/library/5hcat2sc(VS.80).aspx
I wanted to know the details of what this function does. Does it send a
message back to the sending app saying that it received the message or just
tells windows that it can free the memory?
It responds to a WM_COPYDATA message. There should be an ON_WM_COPYDATA()
in your message map, which ensures it gets called.
So when you receive such a message you use this function to do what you need
to do with the data encapsulated in *pCopyDataStruct. It does what you
program it it to do.
I don't think the base class implementation does anything. It should surely
NOT free the data, as you are being sent something which may still be needed
by the sender. Typically the sender will do something like
COPYDATASTRUCT cds;
// fill in cds
pRecipientWnd->SendMessage( WM_COPYDATA, WPARAM(hWndSender),
(LPARAM)(&cds) );
// allow cds to go out of scope.
and if the recipient tries to destroy the pointer it gets, I'd anticipate
deep trouble!
Post by amccombsWhat happens if pWnd is NULL?
pWnd is a pointer to the Window which sent the WM_COPYDATA message. I
assume it is constructed from the WPARAM of the message. I pass NULL
regularly when the recipient doesn't need to know where the message comes
from.
By the by:
A common use of this message for main application windows in MDI programs is
as follows:
User double clicks on a document file name.
Application checks to see if an instance of the same program is already
running.
If so it parcels the double-clicked filename in a COPYDATA struct and sends
a WM_COPYDATA to the main window of th existing instance, and then exits
silently.
On receipt of a WM_COPYDATA the application opens the file.
In this way double clicking a document file in explorer opens it in a new
view window in an already-running instance of the application. You don't
get a second instance of the program.
Dave
--
David Webber
Author of 'Mozart the Music Processor'
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mozartists/mailinglist.htm