Word2007菜单控制的有关问题
Word2007菜单控制的问题
最近有一个需求,需要对Office类的应用程序的保存和另存按钮做状态的控制。
在Outlook2007中,那些按钮都成功的被我置成灰色了。但是在Word2007中,尽管函数返回成功,但是却没有任何效果。我怀疑这个跟Ribbon有一定的关系,但是自己搞不定。特求助各位大神。
OutLook中的相关代码:
Word2007中的关键代码:
------最佳解决方案--------------------
奉劝楼主不要把有限的生命浪费在无限的加密解密死循环中!
------其他解决方案--------------------
最近有一个需求,需要对Office类的应用程序的保存和另存按钮做状态的控制。
在Outlook2007中,那些按钮都成功的被我置成灰色了。但是在Word2007中,尽管函数返回成功,但是却没有任何效果。我怀疑这个跟Ribbon有一定的关系,但是自己搞不定。特求助各位大神。
OutLook中的相关代码:
CComPtr < Office::_CommandBars> spCmdBars;
// Outlook应用接口_Application
CComQIPtr <Outlook::_Application> spApp(Application);
ATLASSERT(spApp);
// 获取CommandBars接口
CComPtr<Outlook::_Explorer> spExplorer;
spApp->ActiveExplorer(&spExplorer);
HRESULT hr = spExplorer->get_CommandBars(&spCmdBars);
CComPtr < Office::CommandBar> spCmdBar;
// 通过CommandBar获取Outlook主菜单
hr = spCmdBars->get_ActiveMenuBar(&spCmdBar);
if (FAILED(hr))
return hr;
// 获取菜单条的CommandBarControls
spCmdCtrls = spCmdBar->GetControls();
ATLASSERT(spCmdCtrls);
CComVariant vItem_fILE(1);
CComPtr< Office::CommandBarControl> spCmdFileCtrl= spCmdCtrls->GetItem(vItem_fILE);
ATLASSERT(spCmdFileCtrl);
IDispatchPtr spFileDisp;
spFileDisp = spCmdFileCtrl->GetControl();
CComQIPtr < Office::CommandBarPopup> ppCmdFilePopup(spFileDisp);
ATLASSERT(ppCmdFilePopup);
CComPtr< Office::CommandBarControls> spCmdBarFileCtrls = ppCmdFilePopup->GetControls();
ATLASSERT(spCmdBarFileCtrls);
int count = spCmdBarFileCtrls->GetCount();
for (int i = 1; i <= count; i++)
{
CComVariant vItem_temp(i);
spCmdBarFileCtrls->GetItem(vItem_temp)->PutEnabled(VARIANT_FALSE);
OutputDebugStringW(spCmdBarFileCtrls->GetItem(vItem_temp)->GetCaption());
}
Word2007中的关键代码:
CComQIPtr <Word::_Application> spApp(Application);
ATLASSERT(spApp);
CComPtr <Office::_CommandBars> spCmdBars;
HRESULT hr = spApp->get_CommandBars(&spCmdBars);
if(FAILED(hr))
return hr;
ATLASSERT(spCmdBars);
CComPtr < Office::CommandBar> spCmdBar;
hr = spCmdBars->get_ActiveMenuBar(&spCmdBar);
if (FAILED(hr))
return hr;
CComPtr< Office::CommandBarControls> spCmdCtrls = spCmdBar->GetControls();
ATLASSERT(spCmdCtrls);
CComVariant vItem_fILE(1);
CComPtr< Office::CommandBarControl> spCmdFileCtrl= spCmdCtrls->GetItem(vItem_fILE);
ATLASSERT(spCmdFileCtrl);
OutputDebugStringW(spCmdFileCtrl->GetCaption());
IDispatchPtr spFileDisp;
spFileDisp = spCmdFileCtrl->GetControl();
CComQIPtr < Office::CommandBarPopup> ppCmdFilePopup(spFileDisp);
ATLASSERT(ppCmdFilePopup);
CComPtr< Office::CommandBarControls> spCmdBarFileCtrls = ppCmdFilePopup->GetControls();
ATLASSERT(spCmdBarFileCtrls);
int count = spCmdBarFileCtrls->GetCount();
for (int i = 1; i <= count; i++)
{
CComVariant vItem_temp(i);
spCmdBarFileCtrls->GetItem(vItem_temp)->PutEnabled(VARIANT_FALSE);
OutputDebugStringW(spCmdBarFileCtrls->GetItem(vItem_temp)->GetCaption());
}
------最佳解决方案--------------------
奉劝楼主不要把有限的生命浪费在无限的加密解密死循环中!
------其他解决方案--------------------