Re: Serialize puzzle
From: Joseph M. Newcomer (newcomer_at_flounder.com)
Date: 02/14/05
- Next message: Joseph M. Newcomer: "Re: WM_KILLFOCUS doesn´t appear in PreTranslateMessage"
- Previous message: David Lowndes: "Re: Checkbox behavior different in Windows XP and Windows 2000"
- In reply to: Denis Gleeson: "Re: Serialize puzzle"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 14 Feb 2005 12:45:12 -0500
See below...
On 14 Feb 2005 04:22:16 -0800, dgleeson-2@utvinternet.com (Denis Gleeson) wrote:
>Hi Joe
>
>BTW thanks for your excellent advice.
>
>Ignore my use of the term visible I simply want to save all documents and
>associated views.
>
>Let me see if Ive got this.
>
>1. First off create a SAVE ALL menu item.
>
>2. Sequence through the list of pointers to documents and call serialize for
> each to save their details. Use GetWindowPlacement to retrieve view
> position details and save them also.
>
>3. I must also save a list of views. You suggest the registry. However I need
> all details to be saved to disk for transfer to another machine running
> the same appliaction.
****
Actually, you need to save a list of the documents. The list of views is saved for each
document. In the case where you need to transport it across machines, you will need a file
to save everything. I would strongly suggest looking at XML for this; of all the
techniques, it is one of the best available. Look into 3rd-party open-source libraries
such as ExPat (google will find this). Avoid DOM stuff; the DOM model is so fundamentally
wrong that it is hard to imagine why anyone would want to use it. This means to avoid most
of the Microsoft support for XML.
I have done this by having an "export" function that saves the Registry subtree, and an
"import" function that imports the Registry subtree, mostly because in the application I
was working on this was the simpler approach. However, I would also consider XML as the
representation of information in a document.
****
>
>4. To reload the documents. I would first off reload the list of documents
> (from where ever) and sequence through serialize for each one.
>
> Can I assume that reloading a document's data will cause the document
> to be instantiated automatically? And also its view ?
> Or must I code the creation of the documents associated views?
****
No, you have it backwards. You create the document, which causes the document's data to be
reloaded. If the file cannot be found, you probably need to verify this and take the
appropriate action. And you will get the default view; if you want other views, you will
have to instantiate them yourself, and, as I pointed out, if the default view did not
exist at the time, you will then have to destroy it.
*****
>
> What coding is required to reposition the view to be created?
*****
SetWindowPlacement. This is based on the premise that you have saved the
GetWindowPlacement data as the information about the window.
*****
>
>Regards
>
>Denis
>
>
>Joseph M. Newcomer <newcomer@flounder.com> wrote in message news:<r8dt015ptbt3gsq09lrr2d5753r2knctcs@4ax.com>...
>> Save and Save As are defined to operate on the current document. To redefine these would
>> make no sense. In particular, what does "Save As" mean if there are six unsaved documents?
>>
>> If you want, add a Save All item. This would be intercepted by the CWinApp class, which
>> could then iterate over the list of document templates and locate all the documents and
>> ask them to save. Views are never saved, and it makes no sense to save a view (if it is a
>> CFormView, the document has to extract the data from the view and save it. I do this by
>> doing an UpdateAllViews with an lHint that says "save your state to the document" then
>> save the document). There is no semantics to saving a view; only documents are saved. If
>> you have three views on the screen, and they all represent a single document, the document
>> is what is saved. If you have three views representing three different documents, Save and
>> Save As do not make sense (in particular, Save As does not make sense); in fact, as a
>> user, I would be very upset if a document I did not want saved got saved. On the other
>> hand, if I do a Save All, I'm expecting all active documents to be saved; it is not clear
>> why visibility has anything to do with it. What does "visible" mean? If I have a large
>> view covering a small view, that is just an accident of how they are currently arranged;
>> if I have a maximized view, it doesn't mean all the other views are second-class citizens.
>> And if a view is minimized, but its icon is seeable by the user, is it a "visible view"?
>> What if the maximized view was one of three different views on the document? The other two
>> are, at this instant, "invisible", but it doesn't mean the user doesn't want to have them
>> available when the document is restored. Saving the "visible" views would mean that you
>> couldn't really tell what was going to be saved, which is a very poor design indeed.
>>
>> To reload all the documents and views, you need to save the state of the relevant views.
>> GetWindowPlacement will retrieve the current state of a view window (including those which
>> are minimized), and you can save this information. One way to approach this is to have
>> each document save, as part of the document file, the current state of the views
>> associated with it. Then loading the document will cause the views to be instantiated,
>> which is not all that hard. Then you have to save a list of all the documents, and the
>> Registry is often where that is maintained, although you could have some other means of
>> doing it if you want. I usually use the Registry. If any of the views are CFormViews,
>> then you must ask the view to intialize its controls from the document contents. If you
>> avoid UpdateData, this is actually not terribly hard (UpdateData often returns completely
>> useless information, such as what is in combo boxes or list boxes; the index of the
>> current selection is largely meaningless, because the control has been destroyed, so who
>> cares what the index is?) Note that you need something that will properly select an item
>> in a listbox or combo box, even if the program has changed (e.g., the number of items has
>> changed, or the actual strings are different, or the sort algorithm has changed...you
>> can't just save the index, that is equally useless for a restart).
>>
>> I did it like this: each document first erases its list of view information, then does an
>> UpdateAllViews with an lHint that says "Save your view information". Each view has an
>> operation which causes its information to be saved to the document. Each view does this in
>> turn, so after the UpdateAllViews the document has a list of all views, which consists of
>> a description of the view to be re-created--I use a GUID name for the view--and the
>> GetWindowPlacement information. This information is written to the document when it is
>> saved. When the document is loaded, this information comes back in. I do an UpdateAllViews
>> with an lHint that asks the current view to identify itself. If it is in the list of views
>> to create, I remove it from the list of views to be created, and create whatever views are
>> left. If it is not in the list of views to be created, create all the views in the list,
>> and then destroy the original view that the document started up with. I do this whenever
>> the OnExit handler is called. In addition, whenever OnClose is called on a view, if the
>> last view is being closed, I save its information as the only view. The File menu has a
>> Close, but it is called Close Document and it closes all views and the document. The
>> document is no longer in the list of documents to be restored on startup, because I only
>> save this list when the program closes. My Registry subroutines support getting and
>> setting window placement as a single entity.
>>
>> I actually have done this, and it works quite well. But I save all documents and all
>> views, and restore them all. I wouldn't use a criterion such as "visible", since that
>> would invariably do the wrong thing.
>> joe
>>
>>
>> On 12 Feb 2005 05:45:09 -0800, dgleeson-2@utvinternet.com (Denis Gleeson) wrote:
>>
>> >Hello All
>> >
>> >I have an MDI application which has three documents each with an
>> >associated single view. When my application is running I may have all
>> >three views visible. What I need to do when the user requests to Save
>> >or Save As is to save all documents and views which are currently visible.
>> >
>> >What I find with serialize is that the framework saves the document whos
>> >view has the focus. So If I had three views on the screen I only get one
>> >saved and when opening the saved file I only get back one doc+view pair.
>> >
>> >What I have done so far is to create a list of visible views and when
>> >the framwork calls any serialize function my code goes through the list
>> >of visible views and calls the serialize function of associated documents.
>> >
>> >So I think I have managed to save the details of all docs whos view is
>> >visible.
>> >
>> >Now I need some help.
>> >
>> >How do I get to where when I load the saved file all views are recreated.
>> >
>> >Do I have to save the view list?
>> >
>> >
>> >
>> >All help appreciated.
>> >
>> >
>> >Denis
>>
>> Joseph M. Newcomer [MVP]
>> email: newcomer@flounder.com
>> Web: http://www.flounder.com
>> MVP Tips: http://www.flounder.com/mvp_tips.htm
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
- Next message: Joseph M. Newcomer: "Re: WM_KILLFOCUS doesn´t appear in PreTranslateMessage"
- Previous message: David Lowndes: "Re: Checkbox behavior different in Windows XP and Windows 2000"
- In reply to: Denis Gleeson: "Re: Serialize puzzle"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|