⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 atlword03.h

📁 word 插件 在word2003+ vc6.0 条件下运行 可以单击弹出atl 的窗口 简单可实现
💻 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 + -