//----------------公共功能库-----------------*/
#ifndef FUNC_DZ
#define FUNC_DZ
#pragma pack(1)
//OFFICE类型
typedef enum _ragEAppType
{
OFFICE_APP_WORD = 0,
OFFICE_APP_EXCEL,
}EAppType;
//OFFICE版本返回信息
#define OFFICE_ERROR (-1)
#define OFFICE_UNKNOWN_ERROR (-2)
#define OFFICE_VERSION_LOWER (0)
#define OFFICE_VERSION_2003 (11)
#define OFFICE_VERSION_2007 (12)
#define OFFICE_VERSION_HIGNER (99)
int GetOfficeVersion(EAppType type);
#pragma pack()
#endif
//----------------公共功能库-----------------*/
//#include <afxv_w32.h>
#include <Windows.h>
#include "TheFunc.h"
//获取当前系统OFFICE版本
int GetOfficeVersion(EAppType type)
{
HKEY hKey;
CHAR dir[MAX_PATH] = {0};
switch(type)
{
case OFFICE_APP_WORD:
strcat(dir , TEXT("\\Word.Application\\CurVer\\"));
break;
case OFFICE_APP_EXCEL:
strcat(dir , TEXT("\\Excel.Application\\CurVer\\"));
break;
default:
return OFFICE_ERROR;
}
if(::RegOpenKeyExA(HKEY_CLASSES_ROOT , dir , 0 , KEY_READ , &hKey) == ERROR_SUCCESS)
{
DWORD type = REG_SZ;
char value[MAX_PATH]={0};
DWORD len = MAX_PATH;
::RegQueryValueExA(hKey , "" , NULL , &type , (LPBYTE)value , &len);
::RegCloseKey(hKey);
//判断值
TCHAR tmp[MAX_PATH] = {0};
int i = strlen(value);
while(value[i--] !='.')
;
strcpy(tmp , &(value[i + 2]));
int ver = atoi(tmp);
switch(ver)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
return OFFICE_VERSION_LOWER;
case 11:
return OFFICE_VERSION_2003;
case 12:
return OFFICE_VERSION_2007;
default:
return OFFICE_VERSION_HIGNER;
}
}
else
return OFFICE_ERROR;
}
具体应用:
//监测本机OFFICE(excel)版本
m_bOffice = TRUE;
int ver = GetOfficeVersion(OFFICE_APP_EXCEL);
if(ver == OFFICE_VERSION_2003 || ver == OFFICE_VERSION_LOWER)
m_OfficeVersion = OFFICE_VERSION_2003;
else if(ver == OFFICE_VERSION_2007 || ver == OFFICE_VERSION_HIGNER)
m_OfficeVersion = OFFICE_VERSION_2007;
else
m_bOffice = FALSE;