📄 excelexport.cpp
字号:
// ExcelExport.cpp: implementation of the ExcelExport class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ExcelExport.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CATID CATID_MyCategory = __CATALOGID__;
ExcelExport::ExcelExport()
{
}
ExcelExport::~ExcelExport()
{
}
void ExcelExport::ErrorMessage(LPCTSTR message, HRESULT hr)
{
const char* sz ;
if (message == NULL)
sz = "The following error occured." ;
else
sz = message;
void* pMsgBuf;
::FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
hr,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &pMsgBuf,
0,
NULL
);
TCHAR buf[1024];
wsprintf(buf, "%s\r\nError: (0x%x) - %s", sz, hr, (LPTSTR) pMsgBuf);
MessageBox(NULL, buf, "Utility Error Message Box.", MB_OK);
LocalFree(pMsgBuf);
}
void ExcelExport::SpecialReg(GUID ID_SubItem,BOOL bRegister)
{
ICatRegister* pICatRegister = NULL ;
HRESULT hr = ::CoCreateInstance( CLSID_StdComponentCategoriesMgr,
NULL, CLSCTX_ALL, IID_ICatRegister,
(void**)&pICatRegister) ;
if (FAILED(hr))
{
ErrorMessage("Could not create the ComCat component.", hr);
return ;
}
CATEGORYINFO CatInfo ;
CatInfo.catid = CATID_MyCategory ;
CatInfo.lcid = LOCALE_SYSTEM_DEFAULT ;
wcscpy(CatInfo.szDescription,sCateGoryName) ;
if (bRegister)
{
hr = pICatRegister->RegisterCategories(1, &CatInfo) ;
hr = pICatRegister->RegisterClassImplCategories(ID_SubItem,1, &CATID_MyCategory) ;
}
else
{
hr = pICatRegister->UnRegisterClassImplCategories(ID_SubItem,1, &CATID_MyCategory);
ICatInformation* pICatInformation = NULL ;
hr = pICatRegister->QueryInterface(IID_ICatInformation, (void**)&pICatInformation) ;
IEnumCLSID* pIEnumCLSID = NULL ;
hr = pICatInformation->EnumClassesOfCategories(1, &CATID_MyCategory, 0, NULL, &pIEnumCLSID) ;
CLSID clsid ;
hr = pIEnumCLSID->Next(1, &clsid, NULL) ;
if (hr == S_FALSE)
{
hr = pICatRegister->UnRegisterCategories(1, &CATID_MyCategory) ;
}
pIEnumCLSID->Release() ;
pICatInformation->Release() ;
}
if (pICatRegister)
{
pICatRegister->Release() ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -