Microsoft KB Archive/264487

From BetaArchive Wiki
Knowledge Base Articles  


HOWTO: Enable the Print Button in Microsoft Word in an Active Document Container

Q264487



The information in this article applies to:

  • Microsoft Visual C++, 32-bit Enterprise Edition, version 6.0
  • Microsoft Visual C++, 32-bit Professional Edition, version 6.0
  • Microsoft Visual C++, 32-bit Learning Edition, version 6.0
  • Microsoft Office for Windows, versions 4.3, 4.3-CD




SUMMARY

When a Microsoft Word document is embedded in an Active Document container, the Print button on the toolbar is not automatically enabled. You can use the IOleCommandTarget interface through a Microsoft Foundation Class (MFC) Library implementation to access this capability.


MORE INFORMATION

The following steps enable the Print button on the toolbar:

  1. In the header file for the COleDocObjectItem class, add the following:
  2. Declare a message map and a function declaration. For this example, a handler called DoOlePrintCmd is declared:
  3. In the implementation file, add a message map and an OLECMD_MAP. These entries map the menu option to the handler, and the OLECMDID to the menu option:
  4. The DoOlePrintCmd function calls ExecCommand, which wraps IOleCommandTarget::Exec:

The client item's instance is searched for IOleCommandTarget mappings; mapping OLECMDID_PRINT causes it to send a WM_COMMAND message to the client item to be handled. Handle the "ID_FILE_PRINT" WM_COMMAND message by mapping it to the DoOlePrintCmd function. Because COleDocObjectItem nests an IOleCommandTarget class, call ExecCommand to call its Exec method.

NOTE: The OLECMDEXECOPT_PROMPTUSER option is necessary, because the Print dialog box must be displayed. Note also that canceling the print returns a failure HRESULT from ExecCommand, so check for a true failure.

REFERENCES

The Visual C++ Programmer's Guide includes a section on Active Document Containers, with further information on related topics, including Command Targets. Look in the ActiveX Topics section under Adding Program Functionality\Details. In addition, the MFCBIND sample illustrates Active Document containers. For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:

Q173476 Active Document Container Apps Must Redistribute ACTXPRXY

Q195033 BUG: Assertion Failure When Opening a Second ActiveX Document

Q191129 BUG: Menu Merge Problem with Server in Active Doc Container

Q180152 HOWTO: Print from an Active Document Server

Additional query words: DocObject

Keywords : kbole kbActiveDocs kbContainer kbMFC kbVC600 kbDSupport kbGrpDSMFCATL
Issue type : kbhowto
Technology : kbVCsearch kbOfficeSearch kbAudDeveloper kbOffice430 kbVC600 kbVC32bitSearch



Last Reviewed: May 7, 2001