Click here to Skip to main content
15,887,676 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 531.4K   12.1K   201  
An application/add-in to organise and renumber resource symbol IDs
/************************************************************************
 *
 *                 Resource ID Organiser Core Library
 *
 * (c) Copyright 2000-2003 by Anna-Jayne Metcalfe (resorg@annasplace.me.uk)
 *                         All rights reserved.
 *
 ************************************************************************
 *                                                                       
 *  Filename    : ResourceSymbolFilesPage.cpp
 *
 *  Description : CResourceSymbolFilesPage - "File" page for
 *                resource symbol file properties (used as the first
 *                page of the File Properties Dialog when multiple files
 *                are opened)
 *                
 *  Compiler    : Microsoft Visual C++ 6.0, Service Pack 3 or later
 *                Microsoft Visual C++ .NET 2002
 *                                                                       
 *  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/ResOrgCore/ResourceSymbolFilesPage.cpp $
 *   $Revision: 5 $
 *       $Date: 26/06/03 20:18 $
 *     $Author: Anna $
 *
 *    $History: ResourceSymbolFilesPage.cpp $
 * 
 * *****************  Version 5  *****************
 * User: Anna         Date: 26/06/03   Time: 20:18
 * Updated in $/Projects/AddIns/ResOrg/ResOrgCore
 * Added resizing support
 * 
 * *****************  Version 4  *****************
 * User: Anna         Date: 26/03/03   Time: 14:12
 * Updated in $/Projects/AddIns/ResOrg/ResOrgCore
 * CResourceSymbolFilesPage now disables the "Remove" button where
 * appropriate to prevent you from removing the last file (a very bad
 * idea, trust me)
 * 
 * *****************  Version 3  *****************
 * User: Anna         Date: 15/02/03   Time: 21:19
 * Updated in $/Projects/AddIns/ResOrg/ResOrgCore
 * Multiple selections can now be made on the "Files" page...when this is
 * so the other tabs disappear as they don't apply
 * 
 * *****************  Version 2  *****************
 * User: Anna         Date: 28/01/03   Time: 21:19
 * Updated in $/Projects/AddIns/ResOrg/ResOrgCore
 * Improved multi-file support by allowing files to be Added/Removed from
 * a multi-file display via the File Properties Dialog
 * 
 * *****************  Version 1  *****************
 * User: Anna         Date: 19/01/03   Time: 17:23
 * Created in $/Projects/AddIns/ResOrg/ResOrgCore
 * CResourceSymbolFilesPage - "File" page for resource symbol file
 * properties (used as the first page of the File Properties Dialog when
 * multiple files are opened)
 * 
 * $Nokeywords: $
 *
 ************************************************************************/


#include "StdAfx.h"
#include "ResOrgCore_Priv.h"

#include "ResourceSymbolManagerMultiFile.h"

#include "ResourceSymbolFilesPage.h"



#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


/////////////////////////////////////////////////////////////////////////////
// CResourceSymbolFilesPage property page

IMPLEMENT_DYNAMIC(CResourceSymbolFilesPage, CResourceSymbolFilesPage_BASE)


// Registered message definitions
const UINT WM_SEL_FILES_CHANGED	= ::RegisterWindowMessage( _T("SelectedFilesChanged") );



CResourceSymbolFilesPage::CResourceSymbolFilesPage(void)
	: CResourceSymbolFilesPage_BASE(CResourceSymbolFilesPage::IDD)
{
	m_pSymbols		= NULL;

	//{{AFX_DATA_INIT(CResourceSymbolFilesPage)
	//}}AFX_DATA_INIT
}


CResourceSymbolFilesPage::~CResourceSymbolFilesPage(void)
{
}


/////////////////////////////////////////////////////////////////////////////
// CResourceSymbolFilesPage virtual overrides

void CResourceSymbolFilesPage::DoDataExchange(CDataExchange* pDX)
{
	CResourceSymbolFilesPage_BASE::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CResourceSymbolFilesPage)
	DDX_Control(pDX,				IDC_SYM_FILES,					m_ctrlFiles);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CResourceSymbolFilesPage, CResourceSymbolFilesPage_BASE)
	//{{AFX_MSG_MAP(CResourceSymbolFilesPage)
	ON_NOTIFY(	LVN_ITEMCHANGED,	IDC_SYM_FILES,					OnItemChangedFilesCtrl)
	ON_BN_CLICKED(					IDC_SYM_FILE_ADD,				OnClickedAddFile)
	ON_BN_CLICKED(					IDC_SYM_FILE_REMOVE,			OnClickedRemoveFile)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


BOOL CResourceSymbolFilesPage::OnInitDialog(void)
{
	BOOL bResult = CResourceSymbolFilesPage_BASE::OnInitDialog();

	m_Resizer.Add( IDC_SYM_FILES,			0,   0,   100, 100);
	m_Resizer.Add( IDC_SYM_FILE_ADD,		0,   100, 0,   0);
	m_Resizer.Add( IDC_SYM_FILE_REMOVE,		0,   100, 0,   0);

	ASSERT(NULL != m_pSymbols);		// Must be set first

	if (NULL != m_pSymbols)
	{
		m_ctrlFiles.AddFiles( static_cast<CResourceSymbolManagerMultiFile*>(m_pSymbols) );

		ASSERT(m_ctrlFiles.GetItemCount() > 0);

		// Select the first item by default
		// This is safe since the list control should NEVER be empty
		m_ctrlFiles.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);

		SetAvailableControls();
	}
	return bResult;
}


BOOL CResourceSymbolFilesPage::OnSetActive(void)
{
	CSymbolManagerPtrArray arrayManagers;
	m_ctrlFiles.GetSelection(arrayManagers);

	if (1 == arrayManagers.GetSize() )
	{
		CResourceSymbolManager* pMngr = arrayManagers[0];
		ASSERT(NULL != pMngr);

		if (NULL != pMngr)
		{
			SetFile(pMngr);
		}
	}
	else
	{
		SetFile(NULL);
	}

	return CResourceSymbolFilesPage_BASE::OnSetActive();
}



/////////////////////////////////////////////////////////////////////////////
// CResourceSymbolFilesPage operations

void CResourceSymbolFilesPage::SetAvailableControls(void)
{
	if (NULL != m_pSymbols)
	{
		int nFiles = static_cast<CResourceSymbolManagerMultiFile*>(m_pSymbols)->GetSymbolFileCount();

		CSymbolManagerPtrArray arrayManagers;
		m_ctrlFiles.GetSelection(arrayManagers);

		int nSelFiles = arrayManagers.GetSize();

		// Removing the last file is a really BAD idea
		EnableDlgControl(IDC_SYM_FILE_REMOVE, (nFiles > 1) && (nSelFiles < nFiles) );
	}
}


/////////////////////////////////////////////////////////////////////////////
// CResourceSymbolFilesPage implementation

// Update the othe pages in the property sheet with the properties of
// the selected file
void CResourceSymbolFilesPage::SetFile(CResourceSymbolManager* pMngr)
{
	CPropertySheet* pParent = DYNAMIC_DOWNCAST(CPropertySheet, GetParent() );
	ASSERT(NULL != pParent);

	if (NULL != pParent)
	{
		for (int n = 0; n < pParent->GetPageCount(); n++)
		{
			CResourceSymbolFilePropertyPage* pPage = DYNAMIC_DOWNCAST(	CResourceSymbolFilePropertyPage,
																		pParent->GetPage(n) );
			ASSERT(NULL != pPage);

			if ( (NULL != pPage) && (pPage != this) )
			{
				pPage->SetSymbolManager(pMngr);
			}
		}
	}
}


/////////////////////////////////////////////////////////////////////////////
// CResourceSymbolFilesPage message handlers

void CResourceSymbolFilesPage::OnItemChangedFilesCtrl(NMHDR* pNMHDR, LRESULT* pResult) 
{
	*pResult = 0;

	LPNMLISTVIEW pLV = (LPNMLISTVIEW)pNMHDR;
	if (0 != (pLV->uChanged & LVIF_STATE) )
	{
		CSymbolManagerPtrArray arrayManagers;
		m_ctrlFiles.GetSelection(arrayManagers);

		CWnd* pParent = CNGWizardPage_BASE::GetParent();
		ASSERT(NULL != pParent);

		if (NULL != pParent)
		{
			pParent->SendMessage(WM_SEL_FILES_CHANGED, (WPARAM)arrayManagers.GetSize(), (LPARAM)&arrayManagers);
		}

		if (1 == arrayManagers.GetSize() )
		{
			CResourceSymbolManager* pMngr = arrayManagers[0];
			ASSERT(NULL != pMngr);

			if (NULL != pMngr)
			{
				SetFile(pMngr);
			}
		}
		else
		{
			SetFile(NULL);
		}
	}
	SetAvailableControls();
}



void CResourceSymbolFilesPage::OnClickedAddFile(void) 
{
	CResourceSymbolManagerMultiFile* pMngr = static_cast<CResourceSymbolManagerMultiFile*>(m_pSymbols);
	if (NULL != pMngr)
	{
		#if _MSC_VER < 1300		// BXFileDialog doesn't work with VC7 yet
			BXFileDialog dlg(	TRUE,												// Open
								FALSE,												// No preview
								TRUE,												// Resizeable
								CString( (LPCTSTR)IDS_FILE_FILTER_SYM_FILES_EXT),	// Default extension
								NULL,												// Default filename
								OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST,				// Flags
								CString( (LPCTSTR)IDS_FILE_FILTER_SYM_FILES),		// File filter
								::AfxGetMainWnd() );								// Parent window

			DWORD dwVersion		= LOWORD(::GetVersion() );

			DWORD dwMajor		= LOBYTE(dwVersion);
			DWORD dwMinor		= HIBYTE(dwVersion);
			DWORD dwUseableVer	= (dwMajor << 8) + dwMinor;

			if (dwUseableVer >= 0x501)
			{
				// Use the VS.NET visual style on WinXP and later
				dlg.SetAppearance(BXFileDialog::APPEARANCE_VSDOTNET);
			}
		#else
			CFileDialog dlg(	TRUE,												// Open
								CString( (LPCTSTR)IDS_FILE_FILTER_WORKSPACES_EXT),	// Default extension
								NULL,												// Default filename
								OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_ENABLESIZING,
																					// Flags
								CString( (LPCTSTR)IDS_FILE_FILTER_WORKSPACES),		// File filter
								::AfxGetMainWnd() );								// Parent window
		#endif

		if (IDOK == dlg.DoModal() )
		{
			// Open and parse it (via the document)
			CString sPathName = dlg.GetPathName();

			if (!pMngr->IsSymbolFileLoaded(sPathName) )
			{
				CResourceSymbolManager* pFile = pMngr->AddSymbolFile(sPathName);
				if (NULL != pFile)
				{
					m_ctrlFiles.AddFile(pFile);

					m_ctrlFiles.UpdateAllFiles();

					if (NULL != m_pDoc)
					{
						m_pDoc->UpdateAllViews(NULL, SYM_REFRESH, NULL);
					}
				}
			}
			else
			{
				CNGSplitPath split(sPathName);
				
				CString sMsg;
				sMsg.Format(IDP_SYM_FILE_ALREADY_LOADED,
							split.GetFileName() + split.GetExtension() );

				::AfxMessageBox(sMsg, MB_OK | MB_ICONEXCLAMATION);
			}
		}
	}
}


void CResourceSymbolFilesPage::OnClickedRemoveFile(void) 
{
	CResourceSymbolManagerMultiFile* pMngr = static_cast<CResourceSymbolManagerMultiFile*>(m_pSymbols);
	if (NULL != pMngr)
	{
		CSymbolManagerPtrArray arrayManagers;
		m_ctrlFiles.GetSelection(arrayManagers);

		for (int n = 0; n < arrayManagers.GetSize(); n++)
		{
			CResourceSymbolManager* pFile = arrayManagers[n];

			if (NULL != pFile)
			{
				m_ctrlFiles.RemoveFile(pFile);

				pMngr->RemoveSymbolFile(pFile->GetPathName() );

			}
		}

		m_ctrlFiles.UpdateAllFiles();

		if (NULL != m_pDoc)
		{
			m_pDoc->UpdateAllViews(NULL, SYM_REFRESH, NULL);
		}
	}
}

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