HOWTO: Retrieve Dialog Info from Word Using an MFC AppID: Q152070
|
This article describes how to retrieve values from Word's dialog boxes using OLE Automation in an MFC-based application. To retrieve values, the client application must create a CurValues object and an object that will represent the data in one of Word's dialogs.
Using Visual C++, it is possible to create a wrapper class for a Word type
library. This wrapper class represents a WordBasic object. Using the
WordBasic class, it is possible to call many methods of the WordBasic
object from within an MFC application. However, it is not possible to get
the settings of any of the Word dialogs using the WordBasic object's
methods directly. You can get information such as Summary Info and Word
Count from Word's dialogs by using a CurValues object. To accomplish this
in an MFC application, you must take the following steps:
WordBasic wb;
wb.CreateDispatch("Word.Basic");
OLECHAR* lpszCurValues = L"CurValues";
DISPID dispidCurValues;
wb.m_lpDispatch->GetIDsOfNames( IID_NULL, &lpszCurValues, 1,
LOCALE_SYSTEM_DEFAULT, &dispidCurValues )
COleDispatchDriver dispdrvrCurValues;
LPDISPATCH resultDispatch;
wb.GetProperty(dispidCurValues, VT_DISPATCH,
(void*)&resultDispatch);
dispdrvrCurValues.AttachDispatch(resultDispatch);
OLECHAR* lpszFileSummaryInfo = L"FileSummaryInfo";
DISPID dispidFileSummaryInfo;
dispdrvrCurValues.m_lpDispatch->GetIDsOfNames( IID_NULL,
&lpszFileSummaryInfo, 1,
LOCALE_SYSTEM_DEFAULT,&dispidFileSummaryInfo)
COleDispatchDriver dispdrvrFileSummaryInfo;
LPDISPATCH resultDispatch;
dispdrvrCurValues.GetProperty(dispidFileSummaryInfo, VT_DISPATCH,
(void*)&resultDispatch);
dispdrvrFileSummaryInfo.AttachDispatch(resultDispatch);
OLECHAR* lpszTitle = L"Title";
DISPID dispidDocProperty;
CString Result;
dispdrvrFileSummaryInfo.m_lpDispatch->GetIDsOfNames( IID_NULL,
&lpszTitle, 1, LOCALE_SYSTEM_DEFAULT, &dispidDocProperty);
dispdrvrFileSummaryInfo.GetProperty,
(dispidDocProperty,VT_BSTR,&Result);
WordBasic Help, shipped with Microsoft Word versions 6.0, 7.0
Additional query words:
Keywords : kbole kbMFC kbVC kbx86
Version : WINDOWS NT:2.0,2.1,2.2,4.0,4.1
Platform : NT WINDOWS
Issue type : kbhowto
Last Reviewed: August 3, 1999