15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Serializing dynamically created controls

Ed Kaltenbach -- kaltenba@ataway.aptec.com
Wednesday, March 27, 1996

Hello All,

I am using MSVC++ 4.0 on Windows 95

My view is derived from CView.  I allow the user "build"
a display by adding both OLE and standard Controls to
the view at runtime.
I have derived a class from CWnd called CNewControl.
CNewControl has a m_nType variable and a few additional
methods (ShowPropertySheet,etc).  All of the dynamically
created controls are of type CNewControl.
When a control is added my view does something like:

  CNewControl *my_control;
  my_control = new CNewControl();
  my_control->Create(type,"sometext", WS_CHILD | WS_VISIBLE,
                   CRect(x,y,w,h),this, id);

  m_controlList.AddTail(my_control);

I keep all of the controls in a CObList called m_controlList.

I am having problems when I attempt to serialize/deserialize.
I assume that the serialize method in CNewControl will need 
to call Create for each control when deserializing.  This
class doesn't have anything to pass as the parent window
to Create.  I attempted to get the current view, but this
causes an ASSERT.  I assume because the view doesn't exists yet
or has not become the current.

How can I deserialize and Create() something derived from CWnd?
When do I call each specific control's Serialize to save the
control's properties? ie CButton::Serialize()
Can I call CWnd::Serialize(ar) to serialize the OCXs?

Does anybody have any ideas or can point me in the right direction?

Thanks,
Ed Kaltenbach

---------------------------------------------------------------
Ed Kaltenbach                  Email: kaltenba@ataway.aptec.com
---------------------------------------------------------------




CraigTT_at_USNELMIS@ccmail01.PE-Nelson.COM
Monday, April 01, 1996

     

Ed,

I think the place where you want to create your controls is in the View's 
OnInitialUpdate function.  At that point, your m_controlList item should have 
deserialized the information about the controls and the view exists waiting to 
be updated with the information.

It doesn't appear to me that any of the Window's control wrappers, CButton, etc,
Serialize anything.  You'll probably need to create your own classes for these 
to store enough information to recreate them.

Tim Craig
PE-Nelson
______________________________ Reply Separator _________________________________
Subject: Serializing dynamically created controls
Author:  mfc-l@netcom.com at SMTPLINK-PEN
Date:    3/27/96 9:21 AM


Hello All,
     
I am using MSVC++ 4.0 on Windows 95
     
My view is derived from CView.  I allow the user "build" 
a display by adding both OLE and standard Controls to 
the view at runtime.
I have derived a class from CWnd called CNewControl. 
CNewControl has a m_nType variable and a few additional 
methods (ShowPropertySheet,etc).  All of the dynamically 
created controls are of type CNewControl.
When a control is added my view does something like:
     
  CNewControl *my_control;
  my_control = new CNewControl();
  my_control->Create(type,"sometext", WS_CHILD | WS_VISIBLE,
                   CRect(x,y,w,h),this, id);
     
  m_controlList.AddTail(my_control);
     
I keep all of the controls in a CObList called m_controlList.
     
I am having problems when I attempt to serialize/deserialize. 
I assume that the serialize method in CNewControl will need 
to call Create for each control when deserializing.  This 
class doesn't have anything to pass as the parent window
to Create.  I attempted to get the current view, but this 
causes an ASSERT.  I assume because the view doesn't exists yet 
or has not become the current.
     
How can I deserialize and Create() something derived from CWnd? 
When do I call each specific control's Serialize to save the 
control's properties? ie CButton::Serialize()
Can I call CWnd::Serialize(ar) to serialize the OCXs?
     
Does anybody have any ideas or can point me in the right direction?
     
Thanks,
Ed Kaltenbach
     
--------------------------------------------------------------- 
Ed Kaltenbach                  Email: kaltenba@ataway.aptec.com 
---------------------------------------------------------------
     




Mike Blaszczak -- mikeblas@msn.com
Wednesday, April 03, 1996

Tim is right: you'll need to recreate your controls after the document is 
loaded.  The problem is that there's no way for you to create controls until 
the view they'll live in has been created.  During the loading serialization 
of the document, there is no view.  During the real serialization, you should 
load all the information you need: the styles, the postions, and any other 
attributes you can think of.

I don't think you'll need to create a wrapper class for each of the control 
classes you'll want to serialize, though--you should be able to write just one 
class that owns the control type in question and is capable of serializing it. 
 That is, I think you could augment your CNewControl a little to get the 
functionality you want.

I think your view should update the list of controls in the document to 
reflect any changes exactly as they are made to the control. Then, any time 
the document needs to be stored, it will have current information that it can 
correctly save.

> Can I call CWnd::Serialize(ar) to serialize the OCXs?

To write OLE controls, yes... this will work.  Loading the controls from a 
serialized data source isn't quite as easy, though.  You'll need to use the 
pStorage parameter to CWnd::CreateControl(), which, I'm afraid, is almost 
completely undocumented.

.B ekiM
TCHAR sz[] = _T("All I want to do is zoom, zoom, zoom.");

----------
From: 	owner-mfc-l@netcom.com on behalf of 
CraigTT_at_USNELMIS@ccmail01.PE-Nelson.COM
Sent: 	Monday, April 01, 1996 10:09 AM
To: 	mfc-l@netcom.com
Subject: 	Re: Serializing dynamically created controls

     

Ed,

I think the place where you want to create your controls is in the View's 
OnInitialUpdate function.  At that point, your m_controlList item should have 
deserialized the information about the controls and the view exists waiting to 

be updated with the information.

It doesn't appear to me that any of the Window's control wrappers, CButton, 
etc,
Serialize anything.  You'll probably need to create your own classes for these 

to store enough information to recreate them.

Tim Craig
PE-Nelson
______________________________ Reply Separator 
_________________________________
Subject: Serializing dynamically created controls
Author:  mfc-l@netcom.com at SMTPLINK-PEN
Date:    3/27/96 9:21 AM


Hello All,
     
I am using MSVC++ 4.0 on Windows 95
     
My view is derived from CView.  I allow the user "build" 
a display by adding both OLE and standard Controls to 
the view at runtime.
I have derived a class from CWnd called CNewControl. 
CNewControl has a m_nType variable and a few additional 
methods (ShowPropertySheet,etc).  All of the dynamically 
created controls are of type CNewControl.
When a control is added my view does something like:
     
  CNewControl *my_control;
  my_control = new CNewControl();
  my_control->Create(type,"sometext", WS_CHILD | WS_VISIBLE,
                   CRect(x,y,w,h),this, id);
     
  m_controlList.AddTail(my_control);
     
I keep all of the controls in a CObList called m_controlList.
     
I am having problems when I attempt to serialize/deserialize. 
I assume that the serialize method in CNewControl will need 
to call Create for each control when deserializing.  This 
class doesn't have anything to pass as the parent window
to Create.  I attempted to get the current view, but this 
causes an ASSERT.  I assume because the view doesn't exists yet 
or has not become the current.
     
How can I deserialize and Create() something derived from CWnd? 
When do I call each specific control's Serialize to save the 
control's properties? ie CButton::Serialize()
Can I call CWnd::Serialize(ar) to serialize the OCXs?
     
Does anybody have any ideas or can point me in the right direction?
     
Thanks,
Ed Kaltenbach
     
--------------------------------------------------------------- 
Ed Kaltenbach                  Email: kaltenba@ataway.aptec.com 
---------------------------------------------------------------
     






| Вернуться в корень Архива |