/***************************************************************************/
/* NOTE: */
/* This document is copyright (c) by Oz Solomonovich, and is bound by the */
/* MIT open source license (www.opensource.org/licenses/mit-license.html). */
/* See License.txt for more information. */
/***************************************************************************/
// AddInMod.cpp : implementation file
//
#include "stdafx.h"
#include "WTSDK_Samp.h"
#include "DSAddIn.h"
#include "Commands.h"
#include "AddInInt.h"
#include "Config.h"
#include "TBAdderWnd.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define ADDIN_NAME "WTSDK_Samp" // for AddInComm
int g_iVerMin;
int g_iVerMaj;
CDSAddIn *g_pDSAddin = NULL;
WTSDK_CommandDef Commands_For_WT[] =
{
{ idCmdShowDialog, "Show WTSDK_Samp Dialog", IDB_MAIN, UI_AlwaysAvailable },
{ idCmdEnable, "Enable Transforms", -1, UI_UseCallback },
{ idCmdShowContext, "Show Command Context", IDB_INFO, UI_AlwaysAvailable },
{ idCmdFileInfo, "Show File Information", IDB_FILEINFO, UI_MustHaveFile }
};
// This is called when the user first loads the add-in, and on start-up
// of each subsequent Developer Studio session
STDMETHODIMP CDSAddIn::OnConnection(IApplication* pApp, VARIANT_BOOL bFirstTime,
long dwCookie, VARIANT_BOOL* OnConnection)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
m_pApplication = pApp;
GetConfiguration();
// Store info passed to us
IApplication* pApplication = NULL;
if (FAILED(pApp->QueryInterface(IID_IApplication, (void**) &pApplication))
|| pApplication == NULL)
{
*OnConnection = VARIANT_FALSE;
return S_OK;
}
m_dwCookie = dwCookie;
// Create command dispatch, send info back to DevStudio
CCommandsObj::CreateInstance(&m_pCommands);
m_pCommands->AddRef();
// The QueryInterface above AddRef'd the Application object. It will
// be Release'd in CCommand's destructor.
m_pCommands->SetApplicationObject(pApplication);
// (see stdafx.h for the definition of VERIFY_OK)
VERIFY_OK(pApplication->SetAddInInfo((long) AfxGetInstanceHandle(),
(LPDISPATCH) m_pCommands, IDR_TOOLBAR_MEDIUM, IDR_TOOLBAR_LARGE, m_dwCookie));
// Inform DevStudio of the commands we implement
// TODO: Replace the AddCommand call below with a series of calls,
// one for each command your add-in will add.
// The command name should not be localized to other languages. The
// tooltip, command description, and other strings related to this
// command are stored in the string table (IDS_CMD_STRING) and should
// be localized.
LPCTSTR szCommand = _T("WTSDK_SampCommand");
VARIANT_BOOL bRet;
CString strCmdString;
strCmdString.LoadString(IDS_CMD_STRING);
strCmdString = szCommand + strCmdString;
CComBSTR bszCmdString(strCmdString);
CComBSTR bszMethod(_T("WTSDK_SampCommandMethod"));
CComBSTR bszCmdName(szCommand);
VERIFY_OK(pApplication->AddCommand(bszCmdString, bszMethod, 0, m_dwCookie, &bRet));
if (bRet == VARIANT_FALSE)
{
// AddCommand failed because a command with this name already
// exists. You may try adding your command under a different name.
// Or, you can fail to load as we will do here.
*OnConnection = VARIANT_FALSE;
return S_OK;
}
// Add toolbar buttons only if this is the first time the add-in
// is being loaded. Toolbar buttons are automatically remembered
// by Developer Studio from session to session, so we should only
// add the toolbar buttons once.
if (bFirstTime == VARIANT_TRUE)
{
AddToolbarCmds();
}
IconsInit();
////////////////////////////////////////////////////////////////////////
// WndTabs SDK Support
// Register with AddInComm
aiclUseDebugLibrary(FALSE);
aiclLoadAICLibrary(AfxGetInstanceHandle());
// Use loader facilities to read own version resource...
char buf[64];
aiclGetModuleVersion("WTSDK_Samp.dll", buf);
// Extract it numerically
sscanf(buf, "%d, %d", &g_iVerMaj, &g_iVerMin);
// Do actual registration
m_hAddin = AICRegisterAddIn(ADDIN_NAME, g_iVerMaj, g_iVerMin, 0,
AddInCallback);
AICSetAddInVersionString(m_hAddin, buf);
// Register with WndTabs
InitWndTabsIntegration(
// addon identification
ADDIN_NAME,
// tab update functionality
OnTabUpdate,
// command and command ui update information
OnWTCommand,
OnWTCommandUpdateUI,
Commands_For_WT,
countof(Commands_For_WT),
// event notification handling
OnWTEvent,
WndTabs_Ev_WindowChanged | WndTabs_Ev_TabClicked // want these events
);
// ends - SDK support
////////////////////////////////////////////////////////////////////////
g_pDSAddin = this;
// the following is a trick that will allow up to add a toolbar even
// if bFirstTime is false
if (cfg_bForceAddToolbar)
{
CTBAdderWnd *pAdder = new CTBAdderWnd();
pAdder->CreateEx(0, NULL, "", WS_CHILD, CRect(0, 0, 1, 1),
CWnd::GetDesktopWindow(), 0);
pAdder->PostMessage(WM_CLOSE);
}
*OnConnection = VARIANT_TRUE;
return S_OK;
}
// This is called on shut-down, and also when the user unloads the add-in
STDMETHODIMP CDSAddIn::OnDisconnection(VARIANT_BOOL bLastTime)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
m_pCommands->Release();
m_pCommands = NULL;
////////////////////////////////////////////////////////////////////////
// WndTabs SDK Support
EndWndTabsIntegration(); // Unregister from WndTabs
AICUnregisterAddIn(m_hAddin); // Unregister from AddInComm
// ends - SDK support
////////////////////////////////////////////////////////////////////////
IconsCleanup();
WriteConfiguration();
return S_OK;
}
void CDSAddIn::AddToolbarCmds() const
{
LPCTSTR szCommand = _T("WTSDK_SampCommand");
CComBSTR bszCmdName(szCommand);
VERIFY_OK(m_pApplication->
AddCommandBarButton(dsGlyph, bszCmdName, m_dwCookie));
cfg_bForceAddToolbar = FALSE;
}