Re: wm_message
You could pass the pointer array instead.
CMyDialog MyDialog(GetDocument()->GetPtrArray());
or, you could access the view by setting the Parent or Owner as the view.
CMyDialog MyDialog()
MyDialog.SetOwner(this); //This being the view.
Then in your dialog method, you would have
GetOwner()->GetDocument()->GetPtrArray();
If you pass the Ptr Array to your Dialog
class CMyDialog
{
CTypedPtrArray* pMyTypedPtrArray;
CMyDialog(CTypedPtrArray* pArray){ pMyTypedPtrArray = pArrary; }
}
You could also keep the dialog "Totally" seperated from the Object by
sending messages back and forth.
I believe you are doing it this way?
CTypedPtrArray* ptr = (CTypedPtrArray
*)GetOwner()->SendMessage(MSG_GET_PTRARRAY, 0, 0);
Then do something else?
GetOwner()->SendMessage(MSG_SOME_MESSAGE, SomeValue, SomeValue)
In the View Class...
//MessageMap Declaration
ON_MESSAGE(MSG_SOME_MESSAGE, MsgMappedFunction)
// Function Declaration (H File)
afx_msg LRESULT MsgMappedFunction(WPARAM wParam, LPARAM lParam)
(Note: Careful with the ";" at the end. It is not needed in the Message Map)
//Function Implementation (CPP File)
LRESULT SomeClass::MsgMappedFunction(WPARAM wParam, LPARAM lParam)
{
int a = wParam
int b = lParam;
return true; //Or false
}
//Omitted the MessageMap and Function delcaration as shown above.
//It looks as though you might have done this already?
LRESULT SomeClass::MsgMappedFunctionGetArray(WPARAM wParam, LPARAM lParam)
{
return (LRESULT)GetDocument()->GetMyTypedPtrArray();.
}
And lastly when I close the dialog object will it affect the array in some
way like deleting it?
No. Your getting a pointer to the object, not the object itself.
CDocument
{
CMyTypedPtr Array; //This is the Object
CMyTypedPtrArray* GetMyTypedPtrArray(){ return &Array; } //This is
getting a pointer to the object.
}
Your just getting a pointer to the Object, not the object itself.
You can mess with your array as much as you want.
Once the dialog is closed, The pointer goes away and the Object still
remains in your Document.
Also, since you are unfamiliar with messages, you can pass values other than
ints.
You would send pointers instead.
SendMessage((WPARAM)&SomeObject, 0);
You'll find that you might have to new and delete objects, depending on the
circumstances.
SomeFunc()
{
CMyObject MyObject;
SendMessage((WPARAM)&MyObject, 0);
//The above method will fail, because MyObject goes out of scope after
the function exists, so you will have to use new and delete.
CMyObject* pMyObject = new CMyObject;
SendMessage((WPARAM)pMyObject, 0);
}
OnMsg(WPARAM wParam, LPARAM lParam)
{
CMyObject MyObject;
CMyObject* pMyObject = (CMyObject*)wParam;
MyObject = *pMyObject; //Dereference so it is an object, instead of a
pointer.
delete pMyObject; //It was newed before the message was sent, so we
delete it here.
}
Well, that is a lot to read and digest.
Hopefully I have cleared it up a little bit.
I don't send messages all the time.
I suppose you could do that for complete separation of the dialog and the
view.
To me, it is too much trouble.
It is your choice as to what you do, but "hopefully" by my reply, you
understand just how it works.