调用PowerPoint的Dispatch接口,将PPT装换为图片

来源:百度文库 编辑:神马文学网 时间:2024/04/18 23:20:40
//首先导入一堆的东西
#import "MSO9.DLL" named_guids, rename("RGB", "MsoRGB")
#import "VBE6EXT.OLB"
#import "MSPPT9.OLB" \
rename("RGB", "MsoRGB") \
rename("DialogBox",  "MsoDialogBox")  \
rename("CopyFile",  "MsoCopyFile")  \
rename("ReplaceText",  "MsoReplaceText") \
rename("ExitWindows", "MsoExitWindows"), \
rename("FindText", "MsoFindText")
// 然后使用VS生成MSPPT9.OLB中的Dispatch包装类,当然,你也可以自己用最原始的接口写。
{
CApplication oApp;
if( !oApp.CreateDispatch( _T("PowerPoint.Application")) )
{
AfxMessageBox( _T("无法启动PowerPoint,请确认您的机器上已经正确安装PowerPoint!") );
return;
}
{
CPresentations oPresentations(oApp.get_Presentations());
LPDISPATCH lpDispPresentation = oPresentations.Open( m_strFilePath, TRUE, 0L, FALSE);
if( lpDispPresentation == NULL )
AfxMessageBox( _T("打开文件失败!") );
else
{
CPresentation oPresentation(lpDispPresentation);
const LPCTSTR OUTPUT_FILE_FORMAT = _T("png");
const long OUTPUT_IMG_WIDTH = 1024;
const long OUTPUT_IMG_HEIGHT = 768;
oPresentation.Export( strPath, OUTPUT_FILE_FORMAT, OUTPUT_IMG_WIDTH, OUTPUT_IMG_HEIGHT);
oPresentation.Close();
}
}
oApp.Quit();
}