xlAutoClose

2 篇文章 0 订阅

xlAutoClose

任何时候XLL 被去激活都会调用此函数。当Excel会话正常结构时会去激活add-in。add-in 也可以由用户在Excel会话期间去激活,调用此函数。

Excel没有规定XLL必需实现和输出此函数,尽管它是明智的,如XLL去激活函数和命令,释放资源,撤销定制,等等。如果函数和命令没有由XLL明确要求释放,Excel会在调用xlAutoClose函数后,再进行此操作。

参数

此函数没有参数

属性值和返回值

你实现了此函数后,必需返回1(int)

备注

每当XLL从内存中卸载去激活后,Excel调用xlAutoClose函数。XLL会在以下情形中去激活:

  • Excel会话正常结束时。
  • 在Excel会话过程中明确卸载XLL
  • XLL可以使用以下几种方法卸载
  • 使用 Add-In 管理器。
  • 从其它的XLL中调用 xlfUnregister函数,使用这个DLL做为唯一的参数名。
  • 从XLM宏表中调用UNREGISTER,以这个DLL名称作为唯的参数名

这个函数可以作以下几种操作:

  • 移除由这个XLL添加和菜单和菜单项。
  • 执行任意必要的全局清理
  • 删除任意创建的任意名称,尤其是函数输出的名称。这里需要注意的是注册的函数可能引起一些名称被创建,如果第4个参数 REGISTER 呈现出来。

实例

int WINAPI xlAutoClose(void)
{
   int i;
   XLOPER12 xRes;

//
// This block first deletes all names added by xlAutoOpen or
// xlAutoRegister12. Next, it checks if the drop-down menu Generic still
// exists. If it does, it is deleted using xlfDeleteMenu. It then checks
// if the Test toolbar still exists. If it is, xlfDeleteToolbar is
// used to delete it.
//
// The following code to delete the defined names
// does not work in the current version of Excel. 
// You cannot delete these names once they are Registered.
// The code is left here in case the functionality becomes 
// available in a future version.
//

   for (i = 0; i < g_rgWorksheetFuncsRows; i++)
      Excel12f(xlfSetName, 0, 1, TempStr12(g_rgWorksheetFuncs[i][2]));

   for (i = 0; i < g_rgCommandFuncsRows; i++)
      Excel12f(xlfSetName, 0, 1, TempStr12(g_rgCommandFuncs[i][2]));
//
// Everything else works as documented.
//
   Excel12f(xlfGetBar, &xRes, 3, TempInt12(10), TempStr12(L"Generic"), TempInt12(0));

   if (xRes.xltype != xltypeErr)
   {
      Excel12f(xlfDeleteMenu, 0, 2, TempNum12(10), TempStr12(L"Generic"));

      // Free the XLOPER12 returned by xlfGetBar //
      Excel12f(xlFree, 0, 1, (LPXLOPER12) &xRes);
   }

   Excel12f(xlfGetToolbar, &xRes, 2, TempInt12(7), TempStr12(L"Test"));

   if (xRes.xltype != xltypeErr)
   {
      Excel12f(xlfDeleteToolbar, 0, 1, TempStr12(L"Test"));

      // Free the XLOPER12 returned by xlfGetToolbar //
      Excel12f(xlFree, 0, 1, (LPXLOPER12) &xRes);
   }

   return 1;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值