Microsoft KB Archive/264487

= 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 &quot;ID_FILE_PRINT&quot; 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.