Re: Homework question relating to docview
Joseph M. Newcomer wrote:
It doesn't. It is primarily a CCmdTarget because it is responding to requests to do
document-relative things, such as saving its contents. These are commands sent to the
document to do document things, as opposed to the document INITIATING spontaneously an
action such as popping up a dialog box. Note that again the document is a passive
recipient of requests, not an initiator of user interactions.
Joe:
This is the message map for CDocument.
BEGIN_MESSAGE_MAP(CDocument, CCmdTarget)
//{{AFX_MSG_MAP(CDocument)
ON_COMMAND(ID_FILE_CLOSE, OnFileClose)
ON_COMMAND(ID_FILE_SAVE, OnFileSave)
ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
These are handlers for menu items. If I have another menu item that
brings up the color picker, and the selected color is stored in the
document, then I do not see anything wrong with the document containing
the handler.
Or another, IMHO less ambiguous, example. In my application the input
data for the application is obtained from (or modified by) the user via
a modal dialog (the view is used just to display the output). This data
is saved with the document (the data *is* the document). The modal
dialog is brought up by a menu item (and a toolbar button). Do you think
the document should not handle this item? I must say that it never
occurred to me to do otherwise.
--
David Wilkinson
Visual C++ MVP