/************************************************************************
*
* Resource ID Organiser Add-In
*
* (c) Copyright 2000-2002 by Anna-Jayne Metcalfe (resorg@annasplace.me.uk)
* All rights reserved.
*
************************************************************************
*
* Filename : DSAddIn.cpp
*
* Description : CDSAddIn - Add-In implementation class
*
* Compiler : Microsoft Visual C++ 6.0, Service Pack 3 or later
*
* Target
* Environment : Windows 98/NT/2000/XP
*
* NOTE:
*
* This software is provided "as is" free for personal use. All
* title and copyrights in and to the software, including but not
* limited to any images, text, etc. incorporated into it, are
* owned by Anna-Jayne Metcalfe, except where acknowledged otherwise.
*
* Your may freely to use this code in your own products, PROVIDED
* this notice is not removed or modified.
*
*
* Visit http://www.annasplace.me.uk/resorg for latest updates
*
************************************************************************
*
* MODIFICATION HISTORY:
*
* This is a controlled document. See project configuration
* control tool for latest version and full version history.
*
* $Archive: /Projects/AddIns/ResOrg/ResOrgAddIn/DSAddIn.cpp $
* $Revision: 10 $
* $Date: 25/11/02 16:52 $
* $Author: Anna $
*
* $History: DSAddIn.cpp $
*
* ***************** Version 10 *****************
* User: Anna Date: 25/11/02 Time: 16:52
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* Changed website address in banner
*
* ***************** Version 9 *****************
* User: Anna Date: 22/10/02 Time: 13:34
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* Changed name/mail address (at last!)
*
* ***************** Version 8 *****************
* User: Andy Date: 12/29/01 Time: 11:42p
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* Got rid of compiler warnings
*
* ***************** Version 7 *****************
* User: Andy Date: 24/04/01 Time: 0:19
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* Modified startup to prevent the wrong window being identified as the
* DevStudio window if another window was active.
*
* The active window is now checked when a command on the toolbar is
* activated instead
*
* ***************** Version 6 *****************
* User: Andy Date: 5/04/01 Time: 6:15
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* Fix a very silly bug
*
* ***************** Version 5 *****************
* User: Andy Date: 5/04/01 Time: 6:09
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* Added check for version expiry (conditional compilation)
*
* ***************** Version 4 *****************
* User: Andy Date: 2/03/01 Time: 17:38
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* 1. Toolbar creation is now done by CDSAddIn::CreateToolbar(), in
* response to a call from the (hidden) window CTBAdderWnd. This prevents
* toolbar creation from failing in OnConnection(). Thanks to Oz
* (osolo@wndtabs.com) for this tip
* 2. Tidied up the code a bit
*
* ***************** Version 3 *****************
* User: Andy Date: 29/11/00 Time: 18:37
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* 1. Moved Office2KDlg code to its own DLL
* 2. Added file banners
*
* $Nokeywords: $
*
************************************************************************/
// DSAddIn.cpp : implementation file
//
#include "StdAfx.h"
#include "TBAdderWnd.h"
#include "ResOrgAddIn.h"
#include "ResOrgAddInApp.h"
#include "DSAddIn.h"
#include "Commands.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static TCHAR szShowCommand[] = _T("ResOrg Show");
static TCHAR szOptionsCommand[] = _T("ResOrg Options");
static TCHAR szAboutCommand[] = _T("ResOrg About");
CDSAddIn* g_pDSAddin = NULL;
CDSAddIn::CDSAddIn(void)
{
m_pApplication = NULL;
m_pCommands = NULL;
}
// 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());
// Check the version of the common controls library.
// (we need at least v5.80 to support Wizard97)
CNGModuleVersion ver;
ver.GetFileVersionInfo( _T("comctl32.dll") );
DWORD dwTargetVerMS = MAKELONG(80, 5);
if (ver.dwFileVersionMS < dwTargetVerMS)
{
CString sVersion = ver.GetValue( _T("FileVersion") );
DoCommonControlsVersionPrompt(sVersion);
*OnConnection = VARIANT_FALSE;
return S_OK;
}
#ifdef _RESORG_EXPIRY_DATE
::DoVersionExpiryCheck();
#endif
// Store info passed to us
if (FAILED( pApp->QueryInterface( IID_IApplication,
(void**)&m_pApplication) )
|| (NULL == m_pApplication) )
{
*OnConnection = VARIANT_FALSE;
return S_OK;
}
m_dwCookie = dwCookie;
// Create command dispatch, send info back to DevStudio
CCommandsObj::CreateInstance(&m_pCommands);
ASSERT(m_pCommands != NULL);
m_pCommands->AddRef();
// The QueryInterface above AddRef'd the Application object. It will
// be Release'd in CCommand's destructor.
m_pCommands->SetApplicationObject(m_pApplication);
// (see stdafx.h for the definition of VERIFY_OK)
VERIFY_OK(m_pApplication->SetAddInInfo( (long)AfxGetInstanceHandle(),
(LPDISPATCH)m_pCommands,
IDR_TOOLBAR_MEDIUM,
IDR_TOOLBAR_LARGE,
m_dwCookie));
// Inform DevStudio of the commands we implement
// 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 (e.g. IDS_RESORG_SHOW_CMD) and should
// be localized.
VARIANT_BOOL bRet;
CString strCmdString;
CComBSTR bszShowCmdName(szShowCommand);
strCmdString.LoadString(IDS_RESORG_SHOW_CMD);
strCmdString = szShowCommand + strCmdString;
CComBSTR bszShowCmdString(strCmdString);
CComBSTR bszShowMethod(_T("ResOrgShowMethod"));
VERIFY_OK(m_pApplication->AddCommand(bszShowCmdString, bszShowMethod, 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;
}
CComBSTR bszOptionsCmdName(szOptionsCommand);
strCmdString.LoadString(IDS_RESORG_OPTIONS_CMD);
strCmdString = szOptionsCommand + strCmdString;
CComBSTR bszOptionsCmdString(strCmdString);
CComBSTR bszOptionsMethod(_T("ResOrgOptionsMethod"));
VERIFY_OK(m_pApplication->AddCommand(bszOptionsCmdString, bszOptionsMethod, 1, m_dwCookie, &bRet));
if (VARIANT_FALSE == bRet)
{
// 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;
}
CComBSTR bszAboutCmdName(szAboutCommand);
strCmdString.LoadString(IDS_RESORG_ABOUT_CMD);
strCmdString = szAboutCommand + strCmdString;
CComBSTR bszAboutCmdString(strCmdString);
CComBSTR bszAboutMethod(_T("ResOrgAboutMethod"));
VERIFY_OK(m_pApplication->AddCommand(bszAboutCmdString, bszAboutMethod, 2, m_dwCookie, &bRet));
if (VARIANT_FALSE == bRet)
{
// 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;
}
g_pDSAddin = this;
// 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.
//
// The following is a trick that will allow up to add a toolbar even
// if bFirstTime is false. Thanks to Oz (osolo@wndtabs.com) for this one!)
BOOL bCreateToolbar = (BOOL)_ttoi( AfxGetApp()->GetProfileString( _T("Options"),
_T("CreateToolbar"),
_T("0") ) );
if (bCreateToolbar || bFirstTime)
{
CTBAdderWnd* pAdder = new CTBAdderWnd();
pAdder->CreateEx( 0,
NULL,
"",
WS_CHILD,
CRect(0, 0, 1, 1),
CWnd::GetDesktopWindow(),
0);
pAdder->PostMessage(WM_CLOSE);
}
#pragma warning(push, 3)
*OnConnection = VARIANT_TRUE;
#pragma warning(pop)
// Initialise the document manager and create the mainframe
GetApp()->OnConnection();
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());
UNREFERENCED_PARAMETER(bLastTime);
GetApp()->OnDisconnection();
if (m_pCommands != NULL)
{
m_pCommands->UnadviseFromEvents();
m_pCommands->Release();
m_pCommands = NULL;
}
return S_OK;
}
void CDSAddIn::CreateToolbar(void) const
{
CComBSTR bszShowCmdName(szShowCommand);
CComBSTR bszOptionsCmdName(szOptionsCommand);
CComBSTR bszAboutCmdName(szAboutCommand);
VERIFY_OK(m_pApplication->AddCommandBarButton(dsGlyph, bszShowCmdName, m_dwCookie) );
VERIFY_OK(m_pApplication->AddCommandBarButton(dsGlyph, bszOptionsCmdName, m_dwCookie) );
VERIFY_OK(m_pApplication->AddCommandBarButton(dsGlyph, bszAboutCmdName, m_dwCookie) );
// Reset the flag in the registry, so that we don't try to
// create the toolbar unnecessarily on subsequent connection
// events
AfxGetApp()->WriteProfileString(_T("Options"),
_T("CreateToolbar"),
_T("0"));
}