C++判断Office版本——转载

自:http://blog.csdn.net/lpc_china/article/details/18359145

主要原理:查询windows注册表microsoft office软件项的值来判断版本。

主要源码:

头文件:

 #pragma once
#include <Windows.h>
#include <tchar.h> class CJudgeOfficeVersion
{
public:
CJudgeOfficeVersion();
~CJudgeOfficeVersion(); public:
BOOL JudgeVersion(OUT LPTSTR _lpVersion, IN DWORD _dwVersionBufferLen);
};

源码:

 #include "JudgeOfficeVersion.h"
#include <strsafe.h> /*
* 函数名称:CJudgeOfficeVersion
* 函数功能:构造函数
* 函数参数:无
* 函数返回:无
* 函数备注:无
* 编 写 人:刘鹏春
*/
CJudgeOfficeVersion::CJudgeOfficeVersion()
{ } /*
* 函数名称:~CJudgeOfficeVersion
* 函数功能:析构函数
* 函数参数:无
* 函数返回:无
* 函数备注:无
* 编 写 人:刘鹏春
*/
CJudgeOfficeVersion::~CJudgeOfficeVersion()
{ } /*
* 函数名称:JudgeVersion
* 函数功能:判断版本
* 函数参数:1字符指针;2指针长度;
* 函数返回:判断状态
* 函数备注:通过ProgID查找CLSID查询服务器中记录的Office版本信息
* 该代码源自:http://support.microsoft.com/kb/247985/zh-cn
* 编 写 人:刘鹏春
*/
BOOL CJudgeOfficeVersion::JudgeVersion(OUT LPTSTR _lpVersion, IN DWORD _dwVersionBufferLen)
{
HKEY hKey;
HKEY hSubKey;
LONG lResult = 0L; TCHAR szValueName[] = {_T("CurVer")};
TCHAR szKey[] = {_T("Excel.Application")}; lResult = RegOpenKeyEx(
HKEY_CLASSES_ROOT,
szKey,
,
KEY_ALL_ACCESS,
&hKey
);
if (ERROR_SUCCESS != lResult) {
MessageBox(NULL, _T("Could not get CLSID from ProgID, Make sure ProgID is correct."), _T("提示"), MB_OK);
return FALSE;
} lResult = RegOpenKeyEx(
hKey,
szValueName,
,
KEY_ALL_ACCESS,
&hSubKey
);
if (ERROR_SUCCESS != lResult) {
MessageBox(NULL, _T("Excel is registered, but no local server can be found!"), _T("提示"), MB_OK);
return FALSE;
} lResult = RegQueryValueEx(hSubKey, NULL, NULL, NULL, (LPBYTE)_lpVersion, &_dwVersionBufferLen); RegCloseKey(hSubKey);
RegCloseKey(hKey); if (ERROR_SUCCESS != lResult) {
return FALSE;
} PTCHAR pszVersionNumber = _tcsrchr(_lpVersion, _T('.'));
PTCHAR pVersion = (pszVersionNumber + );
INT nVersion = _ttoi(pVersion); ZeroMemory(_lpVersion, _dwVersionBufferLen);
switch (nVersion)
{
case :
case :
case :
case :
case :
StringCchCopy(_lpVersion, _dwVersionBufferLen, _T("Office 95以前版本"));
break;
case :
StringCchCopy(_lpVersion, _dwVersionBufferLen, _T("Office 95"));
break;
case :
StringCchCopy(_lpVersion, _dwVersionBufferLen, _T("Office 97"));
break;
case :
StringCchCopy(_lpVersion, _dwVersionBufferLen, _T("Office 2000"));
break;
case :
StringCchCopy(_lpVersion, _dwVersionBufferLen, _T("Office XP"));
break;
case :
StringCchCopy(_lpVersion, _dwVersionBufferLen, _T("Office 2003"));
break;
case :
StringCchCopy(_lpVersion, _dwVersionBufferLen, _T("Office 2007"));
break;
case :
case :
case :
StringCchCopy(_lpVersion, _dwVersionBufferLen, _T("Office 2010"));
break;
default:
StringCchCopy(_lpVersion, _dwVersionBufferLen, _T("Version 2010以后版本"));
} return TRUE;
}

*注:此方法还是比较简答而且容易是实现的。

上一篇:ZBrush中Magnify膨胀笔刷介绍


下一篇:CGAffineTransform与CATransform3D