Click here to Skip to main content
15,892,005 members
Articles / Desktop Programming / MFC

Resource ID Organiser Add-In for Visual C++ 5.0/6.0/.NET

Rate me:
Please Sign up or sign in to vote.
4.98/5 (71 votes)
10 Jan 2005CPOL25 min read 532.8K   12.1K   201  
An application/add-in to organise and renumber resource symbol IDs
/************************************************************************
 *
 *            Resource ID Organiser Add-In for Visual C++ .NET
 *
 * (c) Copyright 2000-2005 by Riverblade Limited (UK). All rights reserved.
 *
 ************************************************************************
 *
 *  Description : CConnect class - primary interface to Visual Studio .NET
 *
 *  Compiler    : Microsoft Visual C++ .NET 2003
 *                                                                       
 *  Target                                                               
 *  Environment : Windows 2000/XP
 *
 *  NOTE:
 *
 *    This software is provided "as is". All title and copyrights in and
 *    to the software, including but not limited to any images, text etc.
 *    etc. incorporated into it, are the property of Anna-Jayne Metcalfe
 *    and Riverblade Limited, except where acknowledged otherwise.
 *
 *    Your may freely use this code in your own products, PROVIDED
 *    this notice is not removed or modified.
 *
 *    Please visit http://www.riverblade.co.uk/products/resorg or email
 *    support@riverblade.co.uk for latest updates and product support 
 *
 ************************************************************************
 *
 *   MODIFICATION HISTORY:
 *
 *           This is a controlled document. See project configuration
 *           control tool for latest version and full version history.
 *
 *    $Archive: /Projects/AddIns/ResOrg/ResOrgNETAddIn/Connect.h $
 *   $Revision: 13 $
 *       $Date: 28/12/04 9:40 $
 *     $Author: Anna $
 *
 *    $History: Connect.h $
 * 
 * *****************  Version 13  *****************
 * User: Anna         Date: 28/12/04   Time: 9:40
 * Updated in $/Projects/AddIns/ResOrg/ResOrgNETAddIn
 * 1.  Added satellite DLL
 * 2.  Added icon to toolwindow
 * 3.  Minor mods for stability
 * 4.  Updated banner
 * 
 * 
 * *****************  Version 12  *****************
 * User: Anna         Date: 20/12/04   Time: 10:13
 * Updated in $/Projects/AddIns/ResOrg/ResOrgNETAddIn
 * 1.  Changed the initialisation sequence to attempt to make it more
 * reliable
 * 2.  Added event unadvise during OnDisconnection()
 * 3.  Added icon to the toolwindow
 * 
 * *****************  Version 11  *****************
 * User: Anna         Date: 25/11/02   Time: 15:27
 * Updated in $/Projects/AddIns/ResOrg/ResOrgNETAddIn
 * Changed website address in banner
 * 
 * *****************  Version 10  *****************
 * User: Anna         Date: 22/10/02   Time: 14:15
 * Updated in $/Projects/AddIns/ResOrg/ResOrgNETAddIn
 * Changed name/email address (at last!)
 * 
 * *****************  Version 9  *****************
 * User: Andy         Date: 10/08/02   Time: 22:21
 * Updated in $/Projects/AddIns/ResOrg/ResOrgNETAddIn
 * 1.  Fixed OnConnection() code...commands are now only setup if the
 * add-in has just been installed or manually reloaded
 * 2.  Tidied up the code
 * 
 * *****************  Version 8  *****************
 * User: Andy         Date: 10/08/02   Time: 0:16
 * Updated in $/Projects/AddIns/ResOrg/ResOrgNETAddIn
 * 1.  Added groups to the toolbar (to make it wider so the caption would
 * fit!)
 * 2.  Fixed a window parenting problem when the main window of ResOrg was
 * opened on an expired version
 * 
 * *****************  Version 7  *****************
 * User: Andy         Date: 9/08/02    Time: 17:02
 * Updated in $/Projects/AddIns/ResOrg/ResOrgNETAddIn
 * Added "Options" and "AboutBox" commands
 * 
 * *****************  Version 6  *****************
 * User: Andy         Date: 7/08/02    Time: 22:15
 * Updated in $/Projects/AddIns/ResOrg/ResOrgNETAddIn
 * Improved the way menu commands are added
 * 
 * *****************  Version 5  *****************
 * User: Andy         Date: 6/08/02    Time: 10:36
 * Updated in $/Projects/AddIns/ResOrg/ResOrgNETAddIn
 * Removed unused code
 * 
 * *****************  Version 4  *****************
 * User: Andy         Date: 5/08/02    Time: 13:49
 * Updated in $/Projects/AddIns/ResOrg/ResOrgNETAddIn
 * 1.  Moved menu entries to a submenu under the Tools menu
 * 2.  Tidied up the code a little
 * 
 * *****************  Version 3  *****************
 * User: Andy         Date: 1/08/02    Time: 16:44
 * Updated in $/Projects/AddIns/ResOrg/ResOrgNETAddIn
 * Further development of ResOrg.NET - particularly the tool window
 * 
 * *****************  Version 2  *****************
 * User: Andy         Date: 7/06/02    Time: 22:37
 * Updated in $/Projects/AddIns/ResOrg/ResOrgAddInVc7
 * Initial integration
 * 
 * *****************  Version 1  *****************
 * User: Andy         Date: 3/06/02    Time: 16:53
 * Created in $/Projects/AddIns/ResOrg/ResOrgAddInVc7
 *
 * $Nokeywords: $
 *
 ************************************************************************/

#pragma once

#include "ResOrgNETAddIn_Res.h"


#pragma warning( disable : 4278 )
//The following #import imports DTE based on it's LIBID
//#import "libid:80cc9f66-e7d8-4ddd-85b6-d9e6cd0e93e2" version("7.0") lcid("0") raw_interfaces_only named_guids
#pragma warning( default : 4278 )

// CConnect
class ATL_NO_VTABLE CConnect : 
			public CComObjectRootEx<CComSingleThreadModel>,
			public CComCoClass<CConnect, &CLSID_Connect>,
			public IDispatchImpl<EnvDTE::IDTCommandTarget, &EnvDTE::IID_IDTCommandTarget, &EnvDTE::LIBID_EnvDTE, 7, 0>,
			public IDispatchImpl<AddInDesignerObjects::_IDTExtensibility2, &AddInDesignerObjects::IID__IDTExtensibility2, &AddInDesignerObjects::LIBID_AddInDesignerObjects, 1, 0>
{
// Construction/destruction
public:
			CConnect(void);

			~CConnect(void);

			
// ATL/COM stuff
DECLARE_REGISTRY_RESOURCEID(IDR_ADDIN)
DECLARE_NOT_AGGREGATABLE(CConnect)

BEGIN_COM_MAP(CConnect)
	COM_INTERFACE_ENTRY(AddInDesignerObjects::IDTExtensibility2)
	COM_INTERFACE_ENTRY(EnvDTE::IDTCommandTarget)
	COM_INTERFACE_ENTRY2(IDispatch, AddInDesignerObjects::IDTExtensibility2)
END_COM_MAP()


// Attributes
protected:
			CComPtr<EnvDTE::_DTE>	m_pDTE;
			CComPtr<EnvDTE::AddIn>	m_pAddInInstance;
			CComPtr<EnvDTE::Window> m_pwndMain;
			CComPtr<IDispatch>		m_pwndMainCtrl;
			HWND					m_hwndResOrg;
			

// Operations
public:
			DECLARE_PROTECT_FINAL_CONSTRUCT()

			HRESULT					FinalConstruct(void);
			void					FinalRelease(void);

// Interfaces
public:
			// IDTExtensibility2 implementation:
			STDMETHOD(OnConnection)		(IDispatch* pApplication,
										 AddInDesignerObjects::ext_ConnectMode eConnectMode,
										 IDispatch* pAddInInst,
										 SAFEARRAY** ppCustom);

			STDMETHOD(OnDisconnection)	(AddInDesignerObjects::ext_DisconnectMode eRemoveMode,
										 SAFEARRAY** custom );

			STDMETHOD(OnAddInsUpdate)	(SAFEARRAY** custom );

			STDMETHOD(OnStartupComplete)(SAFEARRAY** custom );

			STDMETHOD(OnBeginShutdown)	(SAFEARRAY** custom );

			
			// IDTCommandTarget implementation:
			STDMETHOD(QueryStatus)		(BSTR CmdName,
										 EnvDTE::vsCommandStatusTextWanted eNeededText,
										 EnvDTE::vsCommandStatus* pStatusOption,
										 VARIANT* pCommandText);

			STDMETHOD(Exec)				(BSTR CmdName,
										 EnvDTE::vsCommandExecOption eExecuteOption,
										 VARIANT* pVariantIn,
										 VARIANT* pVariantOut,
										 VARIANT_BOOL* pbHandled);

	// Implementation
protected:
			HRESULT					ConfigureEvents(void);
			HRESULT					UnadviseEvents(void);

			HRESULT					ConfigureCommands(void);

			bool					LoadCommandSpec(UINT uResourceID,
													CString& rsCmd,
													CString& rsButtonText,
													CString& rsToolTip,
													CString& rsKeyBinding,
													BOOL& rbHasBitmap) const;

			HRESULT					AddCommand(		CComPtrBase<EnvDTE::Commands>& pCommands, 
													CComPtr<EnvDTE::Command>& rpCommand,
													UINT uCmdSpecID,
													bool bEnabled);

			HRESULT					RemoveCommands(void);

			HRESULT					AddCommandToCommandBar(	CComPtrBase<Office::CommandBar>& pCommandBar,
															CComPtr<EnvDTE::Command> pCommand,
															LONG lPos,
															bool bBeginGroupBefore = false);

			HRESULT					CreateMainToolWindow(IDispatch* pApplication);

			HRESULT					RefreshMainToolWindow(void);

			void					ConnectApp(void);

			void					DisconnectApp(void);

			HWND					FindVisualStudioMainWnd(void) const;

			HRESULT					ToggleProjectViewCmd(void);

			HRESULT					OpenResOrgMainWindow(void);

			HRESULT					DoOptionsCmd(void);

			HRESULT					DoAboutBoxCmd(void);

			void					QueryStatusToggleViewToolWinCmd(EnvDTE::vsCommandStatusTextWanted eNeededText,
																	EnvDTE::vsCommandStatus* pStatusOption,
																	VARIANT* pvarCommandText);

	// I found this code in the MS VCEvents sample. All I can say is YUCK!
	class SolutionEventsSink : public IDispEventImpl<	1,
														SolutionEventsSink,
														&__uuidof(EnvDTE::_dispSolutionEvents),
														&EnvDTE::LIBID_EnvDTE,
														7,
														0>
	{
	protected:
			CComPtr<IDispatch>		m_pwndMainCtrl;


	public:
		BEGIN_SINK_MAP(SolutionEventsSink)
			SINK_ENTRY_EX(1, __uuidof(EnvDTE::_dispSolutionEvents), 1, Opened)
			SINK_ENTRY_EX(1, __uuidof(EnvDTE::_dispSolutionEvents), 2, BeforeClosing)
			SINK_ENTRY_EX(1, __uuidof(EnvDTE::_dispSolutionEvents), 3, AfterClosing)
			SINK_ENTRY_EX(1, __uuidof(EnvDTE::_dispSolutionEvents), 4, QueryCloseSolution)
			SINK_ENTRY_EX(1, __uuidof(EnvDTE::_dispSolutionEvents), 5, Renamed)
			SINK_ENTRY_EX(1, __uuidof(EnvDTE::_dispSolutionEvents), 6, ProjectAdded)
			SINK_ENTRY_EX(1, __uuidof(EnvDTE::_dispSolutionEvents), 7, ProjectRemoved)
			SINK_ENTRY_EX(1, __uuidof(EnvDTE::_dispSolutionEvents), 8, ProjectRenamed)
		END_SINK_MAP()

		bool					Initialise(IDispatch* pToolWindowCtrl)
									{ m_pwndMainCtrl = pToolWindowCtrl; return true; }

		HRESULT					RefreshMainToolWindow(void);

		void __stdcall Opened(void);
		void __stdcall BeforeClosing(void);
		void __stdcall AfterClosing(void);
		void __stdcall QueryCloseSolution(VARIANT_BOOL* fCancel);
		void __stdcall Renamed(BSTR bsOldName);
		void __stdcall ProjectAdded(EnvDTE::Project* pProject);
		void __stdcall ProjectRemoved(EnvDTE::Project* pProject);
		void __stdcall ProjectRenamed(EnvDTE::Project* pProject, BSTR bsOldName);

};
		SolutionEventsSink		m_SolutionEventsSink;
};


OBJECT_ENTRY_AUTO(__uuidof(Connect), CConnect)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Founder Riverblade Limited
United Kingdom United Kingdom
I haven't always written software for a living. When I graduated from Surrey University in 1989, it was with an Electronic Engineering degree, but unfortunately that never really gave me the opportunity to do anything particularly interesting (with the possible exception of designing Darth Vader's Codpiece * for the UK Army in 1990).
    * Also known as the Standard Army Bootswitch. But that's another story...
Since the opportunity arose to lead a software team developing C++ software for Avionic Test Systems in 1996, I've not looked back. More recently I've been involved in the development of subsea acoustic navigation systems, digital TV broadcast systems, port security/tracking systems, and most recently software development tools with my own company, Riverblade Ltd.

One of my personal specialities is IDE plug-in development. ResOrg was my first attempt at a plug-in, but my day to day work is with Visual Lint, an interactive code analysis tool environment with works within the Visual Studio and Eclipse IDEs or on build servers.

I love lots of things, but particularly music, photography and anything connected with history or engineering. I despise ignorant, intolerant and obstructive people - and it shows...I can be a bolshy cow if you wind me up the wrong way...Laugh | :laugh:

I'm currently based 15 minutes walk from the beach in Bournemouth on the south coast of England. Since I moved here I've grown to love the place - even if it is full of grockles in Summer!

Comments and Discussions