?? atlword03.h
字號:
// AtlWord03.h : Declaration of the CAtlWord03
#ifndef __ATLWORD03_H_
#define __ATLWORD03_H_
#include "resource.h" // main symbols
#import "C:\Program Files\Common Files\Designer\MSADDNDR.DLL" raw_interfaces_only, raw_native_types, no_namespace, named_guids
extern _ATL_FUNC_INFO OnClickButtonInfo;
/////////////////////////////////////////////////////////////////////////////
// CAtlWord03
class ATL_NO_VTABLE CAtlWord03 :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CAtlWord03, &CLSID_AtlWord03>,
public ISupportErrorInfo,
public IDispatchImpl<IAtlWord03, &IID_IAtlWord03, &LIBID_ATL21Lib>,
public IDispatchImpl<_IDTExtensibility2, &IID__IDTExtensibility2, &LIBID_AddInDesignerObjects>,
public IDispEventSimpleImpl<1,CAtlWord03,&__uuidof(Office::_CommandBarButtonEvents)>
{
typedef IDispEventSimpleImpl</*nID =*/ 1,CAtlWord03, &__uuidof(Office::_CommandBarButtonEvents)> CommandButton1Events;
public:
CAtlWord03()
{
m_spApp = NULL;
m_spButton = NULL;
}
DECLARE_REGISTRY_RESOURCEID(IDR_ATLWORD03)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CAtlWord03)
COM_INTERFACE_ENTRY(IAtlWord03)
//DEL COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
COM_INTERFACE_ENTRY2(IDispatch, IAtlWord03)
COM_INTERFACE_ENTRY(_IDTExtensibility2)
END_COM_MAP()
BEGIN_SINK_MAP(CAtlWord03)
SINK_ENTRY_INFO(1,__uuidof(Office::_CommandBarButtonEvents),/*dispid*/ 0x01,OnClickButton1, &OnClickButtonInfo)
END_SINK_MAP()
// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
// IAtlWord03
public:
void __stdcall OnClickButton1(IDispatch * /*Office::_CommandBarButton**/ Ctrl,VARIANT_BOOL * CancelDefault);
// _IDTExtensibility2
STDMETHOD(OnConnection)(IDispatch * Application, ext_ConnectMode ConnectMode, IDispatch * AddInInst, SAFEARRAY * * custom)
{
CComPtr< Office::_CommandBars> spCmdBars;
CComQIPtr<MSWORD::_Application> spApp(Application);
ATLASSERT(spApp);
HRESULT hr = spApp->get_CommandBars(&spCmdBars);
if(FAILED(hr))
return hr;
ATLASSERT(spCmdBars);
CComVariant vName("All is Made By my Self");
CComPtr<Office::CommandBar> spNewCmdBar;
CComVariant vPos(1);
CComVariant vTemp(VARIANT_TRUE);
CComVariant vEmpty(DISP_E_PARAMNOTFOUND,VT_ERROR);
spNewCmdBar = spCmdBars->Add(vName,vPos,vEmpty,vTemp);
_bstr_t bstrNewCaption(OLESTR("Liaozhen1"));
_bstr_t bstrTipText(OLESTR("Tool tip for liaozhen"));
CComPtr<Office::CommandBarControls> spBarControls;
spBarControls = spNewCmdBar->GetControls();
ATLASSERT(spBarControls);
CComVariant vToolBarType(1);
CComVariant vShow(VARIANT_TRUE);
CComPtr<Office::CommandBarControl> spNewbar;
spNewbar = spBarControls->Add(vToolBarType,vEmpty,vEmpty,vEmpty,vShow);
ATLASSERT(spNewbar);
CComQIPtr<Office::_CommandBarButton> spCmdButton(spNewbar);
HBITMAP hBmp = (HBITMAP)::LoadImage(_Module.GetResourceInstance(),
MAKEINTRESOURCE(IDB_BITMAP2),IMAGE_BITMAP,0,0,LR_LOADMAP3DCOLORS);
//usr the clipboard to send some message
::OpenClipboard(NULL);
::EmptyClipboard();
::SetClipboardData(CF_BITMAP,(HANDLE)hBmp);
::CloseClipboard();
::DeleteObject(hBmp);
spCmdButton->PutStyle(Office::msoButtonIconAndCaption);
hr = spCmdButton->PasteFace();
if(FAILED(hr))
return hr;
spCmdButton->PutVisible(VARIANT_TRUE);
spCmdButton->PutCaption(OLESTR("Button 1"));
spCmdButton->PutEnabled(VARIANT_TRUE);
spCmdButton->PutTooltipText(OLESTR("Button1 Info"));
spCmdButton->PutTag(OLESTR("Button 1 tag"));
spNewCmdBar->PutVisible(VARIANT_TRUE);
m_spButton = spCmdButton;
m_spApp = spApp;
//發送消息時候用
//鏈接上
hr = CommandButton1Events::DispEventAdvise((IDispatch*)m_spButton);
if(FAILED(hr))
return hr;
::EmptyClipboard();
return E_NOTIMPL;
}
STDMETHOD(OnDisconnection)(ext_DisconnectMode RemoveMode, SAFEARRAY * * custom)
{
// 斷開新增的工具條按鈕的事件連接點
HRESULT hr = CommandButton1Events::DispEventUnadvise((IDispatch*)m_spButton);
if(FAILED(hr))
return hr;
m_spButton = NULL;
m_spApp = NULL;
return E_NOTIMPL;
}
STDMETHOD(OnAddInsUpdate)(SAFEARRAY * * custom)
{
return E_NOTIMPL;
}
STDMETHOD(OnStartupComplete)(SAFEARRAY * * custom)
{
return E_NOTIMPL;
}
STDMETHOD(OnBeginShutdown)(SAFEARRAY * * custom)
{
return E_NOTIMPL;
}
public:
// new the bar and button
CComPtr<Office::_CommandBarButton> m_spButton;
CComPtr<MSWORD::_Application> m_spApp;
};
#endif //__ATLWORD03_H_
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -