首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

Word2007菜单控制的有关问题

2012-12-16 
Word2007菜单控制的问题最近有一个需求,需要对Office类的应用程序的保存和另存按钮做状态的控制。在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());
}

[最优解释]
奉劝楼主不要把有限的生命浪费在无限的加密解密死循环中!

------其他解决方案--------------------


顶一下,这么快就沉了。。。
[其他解释]
再顶。求高手解答。
[其他解释]
关键是我没有做加密和解密呀。我仅仅就是想控制Office2007的弹出菜单。

热点排行