Article ID: 180312
Article Last Modified on 1/22/2007
178749 HOWTO: Create an Automation Project Using MFC and a Type Library
#include "msword8.h"
For Word 2000, include msword9.h. For Word 2002, include msword.h.
CWaitCursor begin; // Hourglass.
{
_Application objApp; // You need an application's typelib;
// therefore, you need an object.
// You can use any application that has an IDispatch
// interface containing SetActivePrinter()
// and GetActivePrinter() member functions.
objApp.CreateDispatch("Word.Application");
// This could be objApp.CreateDispatch("Excel.Application");
// For a network printer, use:
// objApp.SetActivePrinter("\\\\PrnServr\\HP3SI@1134 on NE01");
// For a local printer, use:
objApp.SetActivePrinter("HP LaserJet IIISi");
::Sleep(10000); // You need to provide a considerable wait if
// you are using a network printer.
CString thePrinter = objApp.GetActivePrinter(); // Verify the new
// setting.
MessageBox(thePrinter, "The Active Printer Is",
MB_SETFOREGROUND | MB_OK);
// Release the objApp object and close Word.
objApp.Quit(COleVariant((short)FALSE), // VARIANT* SaveChanges
COleVariant((short)TRUE), // VARIANT* OriginalFormat
COleVariant((short)FALSE) // VARIANT* RouteDocument
);
// If you use Excel for its IDispatch interface functions,
// objApp.Quit() takes no parameters.
}
222101 HOWTO: Find and Use Office Object Model Documentation
Keywords: kbhowto KB180312