📄 addin.h
字号:
////////////////////////////////////////////////////////////////////////////
// Copyright : Amit Dey 2002
//
// Email :amitdey@joymail.com
//
// This code may be used in compiled form in any way you desire. This
// file may be redistributed unmodified by any means PROVIDING it is
// not sold for profit without the authors written consent, and
// providing that this notice and the authors name is included.
//
// This file is provided 'as is' with no expressed or implied warranty.
// The author accepts no liability if it causes any damage to your computer.
//
// Do expect bugs.
// Please let me know of any bugs/mods/improvements.
// and I will try to fix/incorporate them into this file.
// Enjoy!
//
// Description : Outlook2K Addin
////////////////////////////////////////////////////////////////////////////
// Addin.h : Declaration of the CAddin
#ifndef __ADDIN_H_
#define __ADDIN_H_
#include "stdafx.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
/////////////////////////////////////////////////////////////////////////////
// CAddin
extern _ATL_FUNC_INFO OnClickButtonInfo;
extern _ATL_FUNC_INFO OnOptionsAddPagesInfo;
class ATL_NO_VTABLE CAddin :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CAddin, &CLSID_Addin>,
public ISupportErrorInfo,
public IDispatchImpl<IAddin, &IID_IAddin, &LIBID_OUTLOOKADDINLib>,
public IDispatchImpl<_IDTExtensibility2, &IID__IDTExtensibility2, &LIBID_AddInDesignerObjects>,
public IDispEventSimpleImpl<1,CAddin,&__uuidof(Office::_CommandBarButtonEvents)>,
public IDispEventSimpleImpl<2,CAddin,&__uuidof(Office::_CommandBarButtonEvents)>,
public IDispEventSimpleImpl<3,CAddin,&__uuidof(Office::_CommandBarButtonEvents)>,
public IDispEventSimpleImpl<4,CAddin,&__uuidof(Office::_CommandBarButtonEvents)>,
public IDispEventSimpleImpl<5,CAddin,&__uuidof(Office::_CommandBarButtonEvents)>,
public IDispEventSimpleImpl<6,CAddin,&__uuidof(Office::_CommandBarButtonEvents)>,
public IDispEventSimpleImpl<7,CAddin,&__uuidof(Office::_CommandBarButtonEvents)>,
public IDispEventSimpleImpl<8,CAddin,&__uuidof(Office::_CommandBarButtonEvents)>,
public IDispEventSimpleImpl<9,CAddin,&__uuidof(Office::_CommandBarButtonEvents)>,
public IDispEventSimpleImpl<10,CAddin,&__uuidof(Outlook::ApplicationEvents)>
{
public:
typedef IDispEventSimpleImpl</*nID =*/ 1,CAddin, &__uuidof(Office::_CommandBarButtonEvents)> CommandButton1Events;
typedef IDispEventSimpleImpl</*nID =*/ 2,CAddin, &__uuidof(Office::_CommandBarButtonEvents)> CommandButton2Events;
typedef IDispEventSimpleImpl</*nID =*/ 3,CAddin, &__uuidof(Office::_CommandBarButtonEvents)> CommandButton3Events;
typedef IDispEventSimpleImpl</*nID =*/ 4,CAddin, &__uuidof(Office::_CommandBarButtonEvents)> CommandMenuEvents1;
typedef IDispEventSimpleImpl</*nID =*/ 5,CAddin, &__uuidof(Office::_CommandBarButtonEvents)> CommandMenuEvents2;
typedef IDispEventSimpleImpl</*nID =*/ 6,CAddin, &__uuidof(Office::_CommandBarButtonEvents)> CommandMenuEvents3;
typedef IDispEventSimpleImpl</*nID =*/ 7,CAddin, &__uuidof(Office::_CommandBarButtonEvents)> CommandMenuEvents4;
typedef IDispEventSimpleImpl</*nID =*/ 8,CAddin, &__uuidof(Office::_CommandBarButtonEvents)> CommandMenuEvents5;
typedef IDispEventSimpleImpl</*nID =*/ 9,CAddin, &__uuidof(Office::_CommandBarButtonEvents)> CommandMenuEvents6;
typedef IDispEventSimpleImpl</*nID =*/ 10,CAddin, &__uuidof(Outlook::ApplicationEvents)> AppEvents;
CAddin()
{
}
DECLARE_REGISTRY_RESOURCEID(IDR_ADDIN)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CAddin)
COM_INTERFACE_ENTRY(IAddin)
//DEL COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
COM_INTERFACE_ENTRY2(IDispatch, IAddin)
COM_INTERFACE_ENTRY(_IDTExtensibility2)
END_COM_MAP()
BEGIN_SINK_MAP(CAddin)
SINK_ENTRY_INFO(1, __uuidof(Office::_CommandBarButtonEvents),/*dispid*/ 0x01, OnClickButton, &OnClickButtonInfo)
SINK_ENTRY_INFO(2, __uuidof(Office::_CommandBarButtonEvents),/*dispid*/ 0x01, OnClickButton2, &OnClickButtonInfo)
SINK_ENTRY_INFO(3, __uuidof(Office::_CommandBarButtonEvents),/*dispid*/ 0x01, OnClickButton3, &OnClickButtonInfo)
SINK_ENTRY_INFO(4, __uuidof(Office::_CommandBarButtonEvents),/*dispid*/ 0x01, OnClickMenu1, &OnClickButtonInfo)
SINK_ENTRY_INFO(5, __uuidof(Office::_CommandBarButtonEvents),/*dispid*/ 0x01, OnClickMenu2, &OnClickButtonInfo)
SINK_ENTRY_INFO(6, __uuidof(Office::_CommandBarButtonEvents),/*dispid*/ 0x01, OnClickMenu3, &OnClickButtonInfo)
SINK_ENTRY_INFO(7, __uuidof(Office::_CommandBarButtonEvents),/*dispid*/ 0x01, OnClickMenu4, &OnClickButtonInfo)
SINK_ENTRY_INFO(8, __uuidof(Office::_CommandBarButtonEvents),/*dispid*/ 0x01, OnClickMenu5, &OnClickButtonInfo)
SINK_ENTRY_INFO(9, __uuidof(Office::_CommandBarButtonEvents),/*dispid*/ 0x01, OnClickMenu6, &OnClickButtonInfo)
SINK_ENTRY_INFO(10,__uuidof(Outlook::ApplicationEvents),/*dispinterface*/,0xf005,OnOptionsAddPages,&OnOptionsAddPagesInfo)
END_SINK_MAP()
// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
void __stdcall OnClickButton(IDispatch * /*Office::_CommandBarButton**/ Ctrl,VARIANT_BOOL * CancelDefault);
void __stdcall OnClickButton2(IDispatch * /*Office::_CommandBarButton**/ Ctrl,VARIANT_BOOL * CancelDefault);
void __stdcall OnClickButton3(IDispatch * /*Office::_CommandBarButton**/ Ctrl,VARIANT_BOOL * CancelDefault);
void __stdcall OnClickMenu1(IDispatch * /*Office::_CommandBarButton**/ Ctrl,VARIANT_BOOL * CancelDefault);
void __stdcall OnClickMenu2(IDispatch * /*Office::_CommandBarButton**/ Ctrl,VARIANT_BOOL * CancelDefault);
void __stdcall OnClickMenu3(IDispatch * /*Office::_CommandBarButton**/ Ctrl,VARIANT_BOOL * CancelDefault);
void __stdcall OnClickMenu4(IDispatch * /*Office::_CommandBarButton**/ Ctrl,VARIANT_BOOL * CancelDefault);
void __stdcall OnClickMenu5(IDispatch * /*Office::_CommandBarButton**/ Ctrl,VARIANT_BOOL * CancelDefault);
void __stdcall OnClickMenu6(IDispatch * /*Office::_CommandBarButton**/ Ctrl,VARIANT_BOOL * CancelDefault);
void __stdcall OnOptionsAddPages(IDispatch* /*PropertyPages**/ Ctrl);
// IAddin
public:
// _IDTExtensibility2
STDMETHOD(OnConnection)(IDispatch * Application, ext_ConnectMode ConnectMode, IDispatch * AddInInst, SAFEARRAY * * custom)
{
char szModlePath[255];
char *pResult;
int nResult;
memset(m_szPath , NULL ,sizeof(m_szPath));
//获得当前模块路径
GetModuleFileName(_Module.GetResourceInstance() , szModlePath , 255);
pResult = strrchr(szModlePath , '\\');
nResult = pResult - szModlePath + 1;
strncpy(m_szPath ,szModlePath ,nResult);
//添加控件
CComPtr < Office::_CommandBars> spCmdBars;
CComPtr < Office::CommandBar> spCmdBar;
CComQIPtr <Outlook::_Application> spApp(Application);
CComPtr<Outlook::_Explorer> spExplorer;
ATLASSERT(spApp);
m_spApp = spApp;
m_Dispatch = Application;
spApp->ActiveExplorer(&spExplorer);
HRESULT hr = spExplorer->get_CommandBars(&spCmdBars);
if(FAILED(hr))
return hr;
ATLASSERT(spCmdBars);
TCHAR szTemp[_MAX_PATH] = {0};
::LoadString(NULL, IDS_PROJNAME, szTemp, sizeof(szTemp)/sizeof(TCHAR));
CComVariant vName(szTemp);
CComPtr <Office::CommandBar> spNewCmdBar;
CComVariant vPos(1); // MsoBarPosition::msoBarTop = 1
CComVariant vTemp(VARIANT_TRUE); // menu is temporary
CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);
spNewCmdBar = spCmdBars->Add(vName, vPos, vEmpty, vTemp); //Add a new toolband through Add method
CComPtr < Office::CommandBarControls> spBarControls; //now get the toolband's CommandBarControls
spBarControls = spNewCmdBar->GetControls();
ATLASSERT(spBarControls);
CComVariant vToolBarType(1); //MsoControlType::msoControlButton = 1
CComVariant vShow(VARIANT_TRUE); //show the toolbar?
CComPtr < Office::CommandBarControl> spNewBar;
CComPtr < Office::CommandBarControl> spNewBar2;
CComPtr < Office::CommandBarControl> spNewBar3;
CComPtr < Office::CommandBarControl> spNewBar4;
//创建4个按钮
vToolBarType = 10; //MsoControlType::msoControlPopue = 10 谈弹出空件
spNewBar4 = spBarControls->Add(vToolBarType, vEmpty, vEmpty, vEmpty, vShow);
ATLASSERT(spNewBar4);
vToolBarType = 1;
spNewBar = spBarControls->Add(vToolBarType, vEmpty, vEmpty, vEmpty, vShow);
ATLASSERT(spNewBar);
spNewBar2 = spBarControls->Add(vToolBarType, vEmpty, vEmpty, vEmpty, vShow);
ATLASSERT(spNewBar2);
spNewBar3 = spBarControls->Add(vToolBarType, vEmpty, vEmpty, vEmpty, vShow);
ATLASSERT(spNewBar3);
::LoadString(NULL, IDS_MENU_MY_CARD, szTemp, sizeof(szTemp)/sizeof(TCHAR));
_bstr_t bstrNewCaption(szTemp);
::LoadString(NULL, IDS_MENU_TOOLTIPS_MY_CARD, szTemp, sizeof(szTemp)/sizeof(TCHAR));
_bstr_t bstrTipText(szTemp);
CComQIPtr < Office::_CommandBarButton> spCmdButton(spNewBar);
CComQIPtr < Office::_CommandBarButton> spCmdButton2(spNewBar2);
CComQIPtr < Office::_CommandBarButton> spCmdButton3(spNewBar3);
ATLASSERT(spCmdButton);
ATLASSERT(spCmdButton2);
ATLASSERT(spCmdButton3);
HBITMAP hBmp =(HBITMAP)::LoadImage(_Module.GetResourceInstance(),MAKEINTRESOURCE(IDB_BITMAP1),IMAGE_BITMAP,0,0,LR_LOADMAP3DCOLORS);
::OpenClipboard(NULL); // put bitmap into Clipboard
::EmptyClipboard();
::SetClipboardData(CF_BITMAP, (HANDLE)hBmp);
::CloseClipboard();
::DeleteObject(hBmp); // set style before setting bitmap
//初始化第一个按钮
spCmdButton->PutStyle(Office::msoButtonIconAndCaption);
hr = spCmdButton->PasteFace();
if (FAILED(hr))
{
return hr;
}
spCmdButton->PutVisible(VARIANT_TRUE);
::LoadString(_Module.GetResourceInstance(), IDS_MENU_MY_CARD, szTemp, sizeof(szTemp)/sizeof(TCHAR));
spCmdButton->PutCaption(szTemp);
spCmdButton->PutEnabled(VARIANT_TRUE);
::LoadString(_Module.GetResourceInstance(), IDS_MENU_TOOLTIPS_MY_CARD, szTemp, sizeof(szTemp)/sizeof(TCHAR));
spCmdButton->PutTooltipText(szTemp);
::LoadString(_Module.GetResourceInstance(), IDS_MENU_TAG_MY_CARD, szTemp, sizeof(szTemp)/sizeof(TCHAR));
spCmdButton->PutTag(szTemp);
////初始化第二个按钮
spCmdButton2->PutStyle(Office::msoButtonIconAndCaption);
spCmdButton2->PutFaceId(1758);
spCmdButton2->PutVisible(VARIANT_TRUE);
::LoadString(_Module.GetResourceInstance(), IDS_MENU_UPDATE_MAIL_LIST, szTemp, sizeof(szTemp)/sizeof(TCHAR));
spCmdButton2->PutCaption(szTemp);
spCmdButton2->PutEnabled(VARIANT_TRUE);
::LoadString(_Module.GetResourceInstance(), IDS_MENU_TOOLTIPS_UPDATE_MAIL_LIST, szTemp, sizeof(szTemp)/sizeof(TCHAR));
spCmdButton2->PutTooltipText(szTemp);
::LoadString(_Module.GetResourceInstance(), IDS_MENU_TAG_UPDATE_MAIL_LIST, szTemp, sizeof(szTemp)/sizeof(TCHAR));
spCmdButton2->PutTag(szTemp);
spCmdButton2->PutVisible(VARIANT_TRUE);
////初始化第三个按钮
spCmdButton3->PutStyle(Office::msoButtonIconAndCaption);
spCmdButton3->PutFaceId(1758);
spCmdButton3->PutVisible(VARIANT_TRUE);
::LoadString(_Module.GetResourceInstance(), IDS_MENU_UPDATE, szTemp, sizeof(szTemp)/sizeof(TCHAR));
spCmdButton3->PutCaption(szTemp);
spCmdButton3->PutEnabled(VARIANT_TRUE);
::LoadString(_Module.GetResourceInstance(), IDS_MENU_TOOLTIPS_UPDATE, szTemp, sizeof(szTemp)/sizeof(TCHAR));
spCmdButton3->PutTooltipText(szTemp);
::LoadString(_Module.GetResourceInstance(), IDS_MENU_TAG_UPDATE, szTemp, sizeof(szTemp)/sizeof(TCHAR));
spCmdButton3->PutTag(szTemp);
spCmdButton3->PutVisible(VARIANT_TRUE);
//显示工具条
spNewCmdBar->PutVisible(VARIANT_TRUE);
//////初始化第四个按钮
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -