home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / activedocument / framer / readme.txt < prev    next >
Text File  |  1997-05-28  |  10KB  |  193 lines

  1. ======================================================
  2. Notes for Active Documents "Framer" (Container) Sample
  3. ======================================================
  4.  
  5. Framer is intended to demonstrate simple Active Document Objects hosting as
  6. a container.  That is, Framer demonstrates the basic support necessary to
  7. host Active Documents.  It is implemented according to the guidlines in the
  8. "Active Documents Specification" document and has been tested against
  9. Microsoft Word and Microsoft Excel as well as a few other OLE-enabled
  10. applications that do not support Active Documents.
  11.  
  12.  
  13. Framer itself has almost nothing in the way of its own user interface such
  14. as a more complete host would, such as the Office Binder.  Framer has these
  15. menu commands available:
  16.  
  17.     Command     Description
  18.     ----------------------------------------------------------------------
  19.     File Open   Displays a File Open dialog and allows the user to select
  20.                 a file.  Framer will attempt to activate the file as an 
  21.                 Active Document.  Failing that it will create a standard
  22.                 embedded object and activate it in a separate window.
  23.                 This command is disabled when an object already exists.
  24.                 File/Close must be used before creating another object.
  25.  
  26.     File Close  Closes the document that is currently open; if the object
  27.                 is just an embedding it will destroy that object which has
  28.                 the effect of closing the server as well.  Try opening
  29.                 a .BMP file (which should activate PaintBrush, for instance)
  30.                 and use Close to see the effect.  There are some variations to
  31.         this behavior (see next section below).
  32.  
  33.     File Exit   Performs File/Close if necessary and terminates Framer.
  34.  
  35.     Help About  Displays Framer's About box.  This command exists to
  36.                 demonstrate Active Document Help menu merging.
  37.  
  38.  
  39. Whenever Framer knows it has an object it displays a small message in its
  40. client area to remind you that you have to File/Close before creating another.
  41.  
  42.  
  43. Creating and Activating an Object
  44. ---------------------------------
  45.  
  46. Framer allows you to open documents regardless of whether or not
  47. there is a server that supports Active Documents for the document
  48. type and regardless of whether or not the document server even knows
  49. about Active Documents at all.  
  50.  
  51. When you "Open" a file in Framer, the code call OleCreateFromFile to create
  52. an embedded object from the contents of the file.  This has two possible
  53. results:
  54.  
  55.     1.  If there is an Active Documents server associated with the file,
  56.         an embedded object initialized with the file contents is created.
  57.  
  58.     2.  If there is not an Active Documents server associated with the file,
  59.         a package object is created.
  60.  
  61. Immediately after creation, Framer activates the object with IOleObject::DoVerb
  62. passing OLEIVERB_SHOW.
  63.  
  64. If the object is a true embedding with server support, one of two things
  65. will happen:
  66.  
  67.     1a. If the object doesn't know about Active Documents, it is activated in
  68.         another window.  Using File/Close in this case will close the server.
  69.         Closing the server itself will cause Framer to do the equivalent
  70.         of File/Close, which frees the object and re-enables File/Open.
  71.         See CImpIIAdviseSink::OnClose in iadvsink.cpp.  The closing
  72.         sequence is in CFrame::Close in framer.cpp.  Using Framer with the
  73.         Paint application will demonstrate this behavior.
  74.  
  75.     1b. If the object has Active Document support, then its server will start
  76.         activation sequence, primarily by calling IOleDocumentSite::ActivateMe
  77.         which is found in idocsite.cpp.  Inside this member, Framer
  78.         then performs the standard sequence of document object activation
  79.         steps.  After these steps the Active Document will be fully
  80.         interactive; using File/Close on the menu, which Framer still owns,
  81.         will deactivate the object through CFrame::Close which performs the
  82.         same set of steps as in #1b above.  Using Framer with Microsoft Word
  83.         will demonstrate this behavior.
  84.  
  85.  
  86. If you activate a package object, the result is that you launch an application
  87. and have it open the file.  Since the application has no OLE support in it
  88. whatsoever, there is no communication link between Framer and that application.
  89. This means that closing Framer will not close that other application.  This is
  90. what one observes with opening a .TXT file in Framer which will launch Notepad.
  91. Once Notepad is running, it's separate and disconnected from Framer.  You have
  92. to close Notepad manually.
  93.  
  94. Framer might have been written to disallow insertion of files that do not have
  95. Active Documents support.  Framer rather demonstrates how to view any file
  96. regardless of server support.
  97.  
  98.  
  99.  
  100. Help Menu Merging
  101. -----------------
  102.  
  103. Framer implements the container side of the Help menu merging protocol
  104. described in the Active Documents Specification.  This involves the members
  105. CFrame::InsertMenus, CFrame::SetMenu, and CFrame::RemoveMenus.  The
  106. InsertMenus method will install Framer's Help menu in the correct location
  107. on the shared menu.  The container-side popup used here is loaded from
  108. Framer's resources on startup in CFrame::Init.
  109.  
  110. Inside CFrame::SetMenu, Framer checks if there's more than one item on
  111. the menu added in InsertMenus.  If so, then Framer remembers this fact
  112. for later message handling.  Otherwise Framer removes this menu from the
  113. shared menu entirely as the dicument object itself isn't using this shared
  114. capability.
  115.  
  116. Inside CFrame::RemoveMenus, Framer simply makes sure that its own Help
  117. menu is removed as it should be.
  118.  
  119. The really interesting stuff happens in FrameWndProc (framer.cpp) in the
  120. WM_INITMENU, WM_INITMENUPOPUP, WM_MENUSELECT, and WM_COMMAND cases.  Inside
  121. WM_INITMENU Framer clears a flag that indicates whether the last popup menu
  122. that was being used was the object's additions to the Help menu.  Inside
  123. WM_MENUSELECT, Framer checks if the originating menu is a popup and if so,
  124. it checks if that popup is on the shared "Help" popup, and if that is also
  125. true then Framer checks if the item being used is the first one or some
  126. other one.  The first item is what Framer knows to be its own Help item, so
  127. it just handles the messages as usual.  Otherwise the user is working with
  128. an Active Document-owned menu, so Framer sets the flag m_fInObjectHelp variable
  129. to TRUE and forwards the message to the object's window (available from
  130. IOleInPlaceObject::GetWindow).
  131.  
  132. As long as m_fInObjectHelp is set, Framer will forward WM_COMMAND,
  133. WM_INITMENUPOPUP, and WM_MENUSELECT messages.  As soon as another
  134. WM_MENUSELECT message is seen for another non-object menu, then Framer
  135. will reset the flag and begin processing messages once again itself.
  136.  
  137. In this way you'll see, with Microsoft Word for example, the correct
  138. behavior of a shared Help popup.  Note that Microsoft Excel does not
  139. exhibit this shared Help menu behavior as it only displays its own
  140. Help menus.
  141.  
  142.  
  143.  
  144. Known Feature Limitations
  145. -------------------------
  146. 1.  Framer does not print so it does not use the IPrint interface nor does
  147.     it implement IContinueCallback.
  148.  
  149. 2.  Framer does nothing with command targets.
  150.  
  151. 3.  Framer does not forward owner-draw menu messages to the object which
  152.     means that if owner-draw menus are used in a DocObject help menu,
  153.     this sample will not work correctly.
  154.  
  155. 4.  Framer does not provide for actually saving any changes made to an
  156.     Active Document.  Because an Active Document is an embedding, Framer has
  157.     to provide an instance of IStorage through IPersistStorage::InitNew
  158.     or IPersistStorage::Load.  It does this using a temporary Compound File
  159.     that is deleted when Framer exits.  Therefore any changes made to the data
  160.     in the Active Document will simply be discarded.
  161.  
  162.  
  163. Potential for Better UI
  164. -----------------------
  165.  
  166. The item #4 above takes a little more explanation.  When OleCreateFromFile is
  167. used in the File/Open command, Framer is making a COPY of the file contents.
  168. When an Active Document is activated with this content, the document has a copy
  169. of the file contents, not the contents of the file itself.  Therefore any
  170. changes made there will not be reflected back into the original file, although
  171. Framer's UI suggests that this should happen.
  172.  
  173. A real Active Document container like the Office Binder actually stores all the
  174. object data in its own Compound File, not as separate files.  If one needs
  175. to have an Active Document save into a separate file, then the container needs
  176. to either use command-targets or has to call IPersistFile::Save to accomplish
  177. this step.
  178.  
  179. In short, Active Documents is not about activating the apps that manipulate
  180. files; it's about activating embedded *documents* saved within the container
  181. file *as if* those documents were stand alone.
  182.  
  183. Framer's UI, which is really inappropriate for DocObjects, exists as it does
  184. for simplicity's sake.
  185.  
  186. A more appropraite container application would maintain its own "files" in
  187. which it collected data from a number of other "documents" which are stored
  188. simply as embedded objects.  The Office Binder does exactly this, where
  189. a "Binder" is a Compound File with sub-storages for each "section" in the
  190. document.
  191.  
  192. Certainly with some more work on UI, Framer could become such an application.
  193.