Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

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

, 10 Jan 2005 CPOL
An application/add-in to organise and renumber resource symbol IDs
resorg103.zip
ResOrg103.exe
resorg104.zip
ResOrg104.exe
resorgaddinsetup.zip
ResOrgAddInSetup.exe
resorgaddin_executables.zip
ResOrg.exe
BXFileDialog.dll
CJ609Lib.dll
NGLib103.dll
ResOrgAddIn.dll
ResOrgCore.dll
ResOrg.cnt
resorg.fts
ResOrg.hlp
resorgnetaddinsetup.zip
ResOrgNETAddInSetup.msi
resorgnetaddin_executables.zip
ResOrgNETAddInToolWindows.ocx
ResOrgNET.exe
CJ609LibVc7.dll
NGLib103Vc7.dll
ResOrgNETAddIn.dll
ResOrgNETCore.dll
ResOrg.cnt
resorg.fts
ResOrg.hlp
ReadMe.rtf
Licence.rtf
resorgnet_executables.zip
ResOrgNET_executables
CJ609LibVc7.dll
NGLib103Vc7.dll
QHTMLight.dll
ResOrg.cnt
resorg.fts
ResOrg.hlp
ResOrgNETAddIn.dll
ResOrgNETAddInToolWindows.ocx
ResOrgNETCore.dll
resorg_demo.zip
ResOrg103.exe
resorg_executables.zip
ResOrgAddIn.dll
BXFileDialog.dll
CJ609Lib.dll
ResOrg.exe
ResOrg.cnt
resorg.fts
ResOrg.hlp
ResOrgCore.dll
NGLib103.dll
resorg_src.zip
BXFileDialog
BXFileDialog.dsp
Lib
Release
Res
bitmap2.bmp
FileOpen.bmp
filesave.bmp
CJLibrary
CJLibrary
CJLibrary.def
CJLibrary.dsp
CJLibrary.dsw
CJLibrarydep.jpg
CJLibraryStatic.dsp
Debug_Unicode
Release
Release_Unicode
res
Include
res
btn_arro.bmp
btn_explorer.bmp
button_images.bmp
cj_logo.bmp
dragging.cur
handcur.cur
headerba.bmp
hsplitba.cur
icr_hand.cur
nodraggi.cur
PushPin.bmp
Toolbar.bmp
vsplitba.cur
Lib
default.doxygen
NGLibrary
Bin
NGLibrary.def
NGLibrary.dsp
NGLibrary.dsw
Release
Res
Drives.bmp
Release
ResOrg.dsw
ResOrgAddIn
Release
Res
HtmlDoc.ico
ResOrg.ico
ResOrgDoc.ico
TBarLrge.bmp
TBarMedm.bmp
Toolbar.bmp
WorkspaceTabs.bmp
ResOrgAddIn.def
ResOrgAddIn.dsp
ResOrgAddIn.odl
ResOrgAddIn_Res.hm
ResOrgApp
Lint
Release
Res
HtmlDoc.ico
MAINFRAM.BMP
ResOrg.ico
ResOrgDoc.ico
TBarLrge.bmp
TBarMedm.bmp
Toolbar.bmp
workspace.ico
WorkspaceTabs.bmp
ResOrgApp.dsp
ResOrgApp_Res.hm
ResOrgApp_Res.resorg
ResOrgCore
Lint
Release
Res
Anna.bmp
BuildOptions.ico
ComCtl Version Prompt.rtf
File Reload Warning Ex.rtf
File Reload Warning.rtf
Global Next Symbol Value Warning Prompt.rtf
information.ico
Invalid Symbol Name.rtf
Mailing List Prompt.rtf
Next Symbol Value Warning Prompt.rtf
project context menu.bmp
project.ico
RenumWiz Completion.rtf
Report.ico
ResOrg Logo.bmp
ResOrg Updated.rtf
ResOrg.ico
resource file.ico
riverblade_logo.bmp
solution.ico
Symbol Delete Warning.rtf
Symbol Name Warning.rtf
Symbol Rename Warning.rtf
SymbolFile.ico
Symbols Delete Warning.rtf
sym_binary.ico
sym_bitmap.ico
sym_command.ico
sym_control.ico
sym_dialog.ico
sym_icon.ico
sym_menu.ico
sym_prompt.ico
sym_resource.ico
sym_string.ico
Toolbar.bmp
VcAddIn.ico
VersionCheck.ico
warning.ico
WizardHeader256.bmp
WizardWatermark256.bmp
ResOrgCore.def
ResOrgCore.dsp
ResOrgCore_Res.hm
ResOrgCore_Res.resorg
Xml
ProblemSymbolReportHtml.xsl
SymbolsReportHtml.xsl
ResOrgNETAddIn
AddIn.def
Release
Res
AddIn.rgs
HtmlDoc.ico
ResOrg.ico
ResOrgDoc.ico
Toolbar.bmp
WorkspaceTabs.bmp
ResOrgNETAddInSetup
Banner.jpg
Intro screen.jpg
Licence.rtf
ReadMe.rtf
Release
ResOrg.ico
ResOrgNETAddInSetup.vdproj
ResOrgNETAddInToolWindows
Release
Res
Edit.ico
Properties.ico
Renumber.ico
ResOrgNETAddInToolWindows.ico
ResOrgNETAddInToolWindowsCtrl.bmp
ResOrgNETAddInToolWindows.def
SatelliteDll
Release
res
AboutBoxCmd.bmp
OpenResOrgCmd.bmp
OptionsCmd.bmp
ViewMainToolWinCmd.bmp
/************************************************************************
 *
 *            Resource ID Organiser Add-In for Visual C++.NET
 *
 * (c) Copyright 2000-2004 by Anna-Jayne Metcalfe (resorg@annasplace.me.uk)
 *                         All rights reserved.
 *
 ************************************************************************
 *                                                                       
 *  Filename    : ResOrgNETAddInToolWinFormView.cpp
 *
 *  Description : CResOrgNETAddInToolWinFormView - ResOrg.NET Tool Window
 *                form view class
 *
 *  Compiler    : Microsoft Visual C++ .NET 2003
 *                                                                       
 *  Target                                                               
 *  Environment : Windows 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/ResOrgNETAddInToolWindows/ResOrgNETAddInToolWinFormView.cpp $
 *   $Revision: 16 $
 *       $Date: 30/08/04 0:44 $
 *     $Author: Anna $
 *
 *    $History: ResOrgNETAddInToolWinFormView.cpp $
 * 
 * *****************  Version 16  *****************
 * User: Anna         Date: 30/08/04   Time: 0:44
 * Updated in $/Projects/AddIns/ResOrg/ResOrgNETAddInToolWindows
 * 1.  CResOrgNETAddInToolWinFormView::Save() now checks that the file
 * exists before attempting to check whether it is read only
 * 2.  Moved CResOrgNETAddInToolWinFormView::DoOverwritePrompt() to
 * ResOrgCore_Globals.cpp/h
 * 
 * *****************  Version 15  *****************
 * User: Anna         Date: 24/08/04   Time: 0:14
 * Updated in $/Projects/AddIns/ResOrg/ResOrgNETAddInToolWindows
 * Added support for out of range symbols
 * 
 * *****************  Version 14  *****************
 * User: Anna         Date: 1/07/03    Time: 23:30
 * Updated in $/Projects/AddIns/ResOrg/ResOrgNETAddInToolWindows
 * Be a little more careful about dealing with relative pathnames. Also
 * guarded some methods against empty workspace/symbol file pathnames just
 * in case
 * 
 * *****************  Version 13  *****************
 * User: Anna         Date: 7/03/03    Time: 15:37
 * Updated in $/Projects/AddIns/ResOrg/ResOrgNETAddInToolWindows
 * Modified CResOrgNETAddInToolWinFormView::UpdateSymbolPropertiesCtrls()
 * to work better with CNGHtmlStaticCtrl
 * 
 * *****************  Version 12  *****************
 * User: Anna         Date: 15/02/03   Time: 21:05
 * Updated in $/Projects/AddIns/ResOrg/ResOrgNETAddInToolWindows
 * Knock on change from CResourceSymbolFilePropertySheet
 * 
 * *****************  Version 11  *****************
 * User: Anna         Date: 2/01/03    Time: 0:31
 * Updated in $/Projects/AddIns/ResOrg/ResOrgNETAddInToolWindows
 * Replaced CQhtmWnd controls with CNGHtmlStaticCtrl (QHTM is
 * overspecified for what I need here)
 * 
 * *****************  Version 10  *****************
 * User: Anna         Date: 25/11/02   Time: 16:50
 * Updated in $/Projects/AddIns/ResOrg/ResOrgNETAddInToolWindows
 * Changed website address in banner
 * 
 * *****************  Version 9  *****************
 * User: Anna         Date: 22/10/02   Time: 14:45
 * Updated in $/Projects/AddIns/ResOrg/ResOrgNETAddInToolWindows
 * Changed name/email address (at last!)
 * 
 * *****************  Version 8  *****************
 * User: Andy         Date: 10/08/02   Time: 0:17
 * Updated in $/Projects/AddIns/ResOrg/ResOrgNETAddInToolWindows
 * Added a warning if the Next Symbol values are in use
 * 
 * *****************  Version 7  *****************
 * User: Andy         Date: 9/08/02    Time: 17:01
 * Updated in $/Projects/AddIns/ResOrg/ResOrgNETAddInToolWindows
 * Added expiry date checks in the handlers for the "Properties", "Edit"
 * and "Renumber" buttons)
 * 
 * *****************  Version 6  *****************
 * User: Andy         Date: 8/08/02    Time: 20:42
 * Updated in $/Projects/AddIns/ResOrg/ResOrgNETAddInToolWindows
 * 1.  Added CResOrgNETAddInToolWinFormView::PreTranslateMessage() in a
 * vain attempt to get the tooltips on the buttons working (this is
 * driving me nuts, but it's probably something really dumb)
 * 2.  If no projects are loaded the expiry date warning is now shown (if
 * a dev build) and the combobox is disabled
 * 
 * *****************  Version 5  *****************
 * User: Andy         Date: 6/08/02    Time: 12:32
 * Updated in $/Projects/AddIns/ResOrg/ResOrgNETAddInToolWindows
 * The warning message is now also used to display expiry date information
 * 
 * *****************  Version 4  *****************
 * User: Andy         Date: 6/08/02    Time: 10:35
 * Updated in $/Projects/AddIns/ResOrg/ResOrgNETAddInToolWindows
 * Corrected a syntax error (forgot to compile before checking in!
 * 
 * *****************  Version 3  *****************
 * User: Andy         Date: 5/08/02    Time: 13:48
 * Updated in $/Projects/AddIns/ResOrg/ResOrgNETAddInToolWindows
 * 1.Converted literal strings to string table entries
 * 
 * *****************  Version 2  *****************
 * User: Andy         Date: 2/08/02    Time: 17:04
 * Updated in $/Projects/AddIns/ResOrg/ResOrgNETAddInToolWindows
 * 1.  Added file banners
 * 2.  Tidied up the code a little - removing unused capabilities
 * 
 * $Nokeywords: $
 *
 ************************************************************************/

#include "StdAfx.h"

#include "ResOrgNETAddInToolWindows.h"

#include "ResOrgNETAddInToolWinFormView.h"


/////////////////////////////////////////////////////////////////////////////
// CResOrgNETAddInToolWinFormView

IMPLEMENT_DYNCREATE(CResOrgNETAddInToolWinFormView, CResOrgNETAddInToolWinFormView_BASE)

CResOrgNETAddInToolWinFormView::CResOrgNETAddInToolWinFormView(void)
	: CResOrgNETAddInToolWinFormView_BASE(CResOrgNETAddInToolWinFormView::IDD)
{
	m_hWndResOrg			= NULL;
	m_pSymbols				= NULL;

	m_sResourceSymbolFile	= _T("");
	m_sResourceRange		= _T("");
	m_sCommandRange			= _T("");

	m_nOutOfRangeSymbols	= 0;
	m_sOutOfRangeSymbols	= _T("");

	m_nConflicts			= 0;
	m_sConflicts			= _T("");

	m_sOutOfRangeSymbolsCaption.LoadString(IDC_TOOLWIN_SYM_OUT_OF_RANGE_CAPTION);
	m_sConflictsCaption.LoadString(IDC_TOOLWIN_SYM_CONFLICTS_CAPTION);

	m_pSymbols = new CResourceSymbolManager;
	ASSERT(NULL != m_pSymbols);
}


CResOrgNETAddInToolWinFormView::~CResOrgNETAddInToolWinFormView(void)
{
	if (NULL != m_pSymbols)
	{
		delete m_pSymbols;
	}
}


/////////////////////////////////////////////////////////////////////////////
// CResOrgNETAddInToolWinFormView virtual overrides

void CResOrgNETAddInToolWinFormView::DoDataExchange(CDataExchange* pDX)
{
	CResOrgNETAddInToolWinFormView_BASE::DoDataExchange(pDX);

	DDX_Control(pDX,		IDC_TOOLWIN_SYM_FILE,					m_ctrlProjects);
	DDX_Control(pDX,		IDC_TOOLWIN_PROPERTIES,					m_ctrlProperties);
	DDX_Control(pDX,		IDC_TOOLWIN_EDIT,						m_ctrlEdit);
	DDX_Control(pDX,		IDC_TOOLWIN_RENUMBER,					m_ctrlRenumber);

	DDX_Control(pDX,		IDC_TOOLWIN_SYM_LOW_RANGE_CAPTION,		m_ctrlResourceRangeCaption);
	DDX_Control(pDX,		IDC_TOOLWIN_SYM_HIGH_RANGE_CAPTION,		m_ctrlCommandRangeCaption);

	DDX_Control(pDX,		IDC_TOOLWIN_SYM_LOW_RANGE,				m_ctrlResourceRange);
	DDX_Control(pDX,		IDC_TOOLWIN_SYM_HIGH_RANGE,				m_ctrlCommandRange);

	DDX_Control(pDX,		IDC_TOOLWIN_SYM_OUT_OF_RANGE_CAPTION,	m_ctrlOutOfRangeSymbolsCaption);
	DDX_Control(pDX,		IDC_TOOLWIN_SYM_OUT_OF_RANGE,			m_ctrlOutOfRangeSymbols);

	DDX_Control(pDX,		IDC_TOOLWIN_SYM_CONFLICTS_CAPTION,		m_ctrlConflictsCaption);
	DDX_Control(pDX,		IDC_TOOLWIN_SYM_CONFLICTS,				m_ctrlConflicts);

	DDX_Control(pDX,		IDC_TOOLWIN_WARNING_ICON,				m_ctrlWarningIcon);
	DDX_Control(pDX,		IDC_TOOLWIN_WARNING_MSG,				m_ctrlWarningText);
	
	DDX_CBStringExact(pDX,	IDC_TOOLWIN_SYM_FILE,					m_sResourceSymbolFile);

	DDX_Text(pDX,			IDC_TOOLWIN_SYM_LOW_RANGE,				m_sResourceRange);
	DDX_Text(pDX,			IDC_TOOLWIN_SYM_HIGH_RANGE,				m_sCommandRange);
	
	DDX_Text(pDX,			IDC_TOOLWIN_SYM_OUT_OF_RANGE_CAPTION,	m_sOutOfRangeSymbolsCaption);
	DDX_Text(pDX,			IDC_TOOLWIN_SYM_OUT_OF_RANGE,			m_sOutOfRangeSymbols);
	
	DDX_Text(pDX,			IDC_TOOLWIN_SYM_CONFLICTS_CAPTION,		m_sConflictsCaption);
	DDX_Text(pDX,			IDC_TOOLWIN_SYM_CONFLICTS,				m_sConflicts);

	DDX_Text(pDX,			IDC_TOOLWIN_WARNING_MSG,				m_sWarningText);
}


#define WM_USER_RESID_FILE_CHANGED WM_USER + 69

BEGIN_MESSAGE_MAP(CResOrgNETAddInToolWinFormView, CResOrgNETAddInToolWinFormView_BASE)

	ON_WM_CTLCOLOR()
	ON_CBN_SELCHANGE(		IDC_TOOLWIN_SYM_FILE,			OnCbnSelchangeResourceSymbolFile)
	ON_BN_CLICKED(			IDC_TOOLWIN_REFRESH,			OnBnClickedToolwinRefresh)
	ON_BN_CLICKED(			IDC_TOOLWIN_PROPERTIES,			OnBnClickedToolwinProperties)
	ON_BN_CLICKED(			IDC_TOOLWIN_EDIT,				OnBnClickedToolwinEdit)
	ON_BN_CLICKED(			IDC_TOOLWIN_RENUMBER,			OnBnClickedToolwinRenumber)
	ON_MESSAGE(				WM_USER_RESID_FILE_CHANGED,		OnMsgResourceSymbolFileChanged)

END_MESSAGE_MAP()


BOOL CResOrgNETAddInToolWinFormView::Create(LPCTSTR lpszClassName,
											LPCTSTR lpszWindowName,
											DWORD dwStyle,
											const RECT& rect,
											CWnd* pParentWnd,
											UINT nID,
											CCreateContext* pContext/* = NULL*/)
{
	int nResult = CResOrgNETAddInToolWinFormView_BASE::Create(	lpszClassName,
																lpszWindowName,
																dwStyle,
																rect,
																pParentWnd,
																nID,
																pContext);

	if (nResult > 0)
	{
		UpdateData(FALSE);

		m_Resizer.Create(this);

		m_Resizer.Add(IDC_TOOLWIN_SYM_FILE,		0, 0, 50, 0);
		m_Resizer.Add(IDC_TOOLWIN_PROPERTIES,	50, 0, 0, 0);
		m_Resizer.Add(IDC_TOOLWIN_EDIT,			50, 0, 0, 0);
		m_Resizer.Add(IDC_TOOLWIN_RENUMBER,		50, 0, 0, 0);

		m_Resizer.Add(IDC_TOOLWIN_DIVIDER,		0, 0, 100, 0);
		m_Resizer.Add(IDC_TOOLWIN_WARNING_MSG,	0, 0, 50, 0);

		m_ctrlProperties.SetIcon(IDI_TOOLWIN_PROPERTIES);
		m_ctrlProperties.SetTooltipText(IDS_TOOLWIN_PROPERTIES, TRUE);

		m_ctrlEdit.SetIcon(IDI_TOOLWIN_EDIT);
		m_ctrlEdit.SetTooltipText(IDS_TOOLWIN_EDIT, TRUE);

		m_ctrlRenumber.SetIcon(IDI_TOOLWIN_RENUMBER);
		m_ctrlRenumber.SetTooltipText(IDS_TOOLWIN_RENUMBER, TRUE);

		ASSERT( ::IsWindow(m_ctrlWarningIcon.m_hWnd) );

		m_ctrlResourceRangeCaption.SetWindowText( _T("Resource / Control IDs:") );
		m_ctrlCommandRangeCaption.SetWindowText( _T("Command IDs:") );

		m_ctrlResourceRange.SetWindowText( _T("") );
		m_ctrlCommandRange.SetWindowText( _T("") );
		m_ctrlOutOfRangeSymbols.SetWindowText( _T("") );
		m_ctrlConflicts.SetWindowText( _T("") );

		#ifdef _DEBUG
			// The Refresh button really shouldn't be needed - it's really just
			// there for testing
			CWnd* pWnd = GetDlgItem(IDC_TOOLWIN_REFRESH);
			if (NULL != pWnd) pWnd->ShowWindow(TRUE);
		#endif
	}
	return nResult;
}


BOOL CResOrgNETAddInToolWinFormView::PreTranslateMessage(MSG* pMsg)
{
/*	AJM 8.8.2002 this doesn't work..WM_MOUSEMOVE (the one we really want)
	never gets here
	CToolTipCtrl* pToolTip = NULL;

	switch (pMsg->message)
	{
		case WM_MOUSEMOVE:
		case WM_LBUTTONDOWN:
		case WM_LBUTTONUP:
		case WM_MBUTTONDOWN:
		case WM_MBUTTONUP:
		case WM_RBUTTONDOWN:
		case WM_RBUTTONUP:
				pToolTip = m_ctrlProperties.GetToolTips();
				if (NULL != pToolTip)
				{
					pToolTip->Activate(TRUE);
					pToolTip->RelayEvent(pMsg);
				}
				break;

		default:
			break;
	}
*/
	return CFormView::PreTranslateMessage(pMsg);
}


// This override is necessary since this view is created on the stack rather
// than the heap...and CView::PostNcDestroy() does a "delete this"!
//
// It's also a convenient place to unconfigure the automation helper
// before it's destroyed (it will ASSERT otherwise, since not
// clearing it down in normal use would be very, very bad)
void CResOrgNETAddInToolWinFormView::PostNcDestroy(void)
{
	m_AutomationHelper.SetDTE(NULL);
}


/////////////////////////////////////////////////////////////////////////////
// CResOrgNETAddInToolWinFormView operations

bool CResOrgNETAddInToolWinFormView::Initialise(CComPtr<EnvDTE::_DTE> pDTE, HWND hWndResOrg)
{
	m_AutomationHelper.SetDTE(pDTE);

	m_hWndResOrg = hWndResOrg;

	return true;
}


void CResOrgNETAddInToolWinFormView::Refresh(void)
{
	if (m_FileChangeMonitor.IsMonitoring() )
	{
		m_FileChangeMonitor.Stop();
	}
	if (UpdateSymbolFilesCtrl() && !m_sWorkspacePathName.IsEmpty() && !m_sResourceSymbolFile.IsEmpty() )
	{
		CNGSplitPath split(m_sWorkspacePathName);
		CString sWorkspaceFolder = split.GetDrive() + split.GetDirectory();

		CString sPathName = ::CombinePath(sWorkspaceFolder, m_sResourceSymbolFile);

		// If the file has changed, parse it and update statistics
		if ( ConfigureSymbolManager(m_pSymbols, sPathName) )
		{
			UpdateSymbolPropertiesCtrls();

			m_FileChangeMonitor.Start(	sPathName,
										this,
										WM_USER_RESID_FILE_CHANGED);
		}
	}
	SetAvailableControls();
}


/////////////////////////////////////////////////////////////////////////////
// CResOrgNETAddInToolWinFormView implementation

bool CResOrgNETAddInToolWinFormView::UpdateSymbolFilesCtrl(void)
{
	m_sWorkspacePathName = m_AutomationHelper.GetSolutionPathName();

	CStringArray arrayProjects;
	m_AutomationHelper.GetProjectNames(arrayProjects);

	CStringArray arraySymbolFilePathNames;

	for (int n = 0; n < arrayProjects.GetSize(); n++)
	{
		CString sProject = arrayProjects[n];
		if (!sProject.IsEmpty() )
		{
			CString sResourceFile = m_AutomationHelper.GetResourceFileName(sProject);
			if (!sResourceFile.IsEmpty() )
			{
				CString sSymbolFile = ::GetSymbolFileName(sResourceFile);
				if (!sSymbolFile.IsEmpty())
				{
					arraySymbolFilePathNames.Add(sSymbolFile);
				}
			}
		}
	}

	CStringArray arraySymbolFiles;

	for (int n = 0; n < arraySymbolFilePathNames.GetSize(); n++)
	{
		CString sSymbolFile = arraySymbolFilePathNames[n];
		if (!sSymbolFile.IsEmpty() )
		{
			CString sRelativeFileName;
			LPTSTR pszRelativeFileName = sRelativeFileName.GetBuffer(_MAX_PATH);

			::PathRelativePathTo(	pszRelativeFileName,
									m_sWorkspacePathName,
									FILE_ATTRIBUTE_NORMAL,
									sSymbolFile,
									FILE_ATTRIBUTE_NORMAL);

			sRelativeFileName.ReleaseBuffer();
			if (!sRelativeFileName.IsEmpty() )
			{
				arraySymbolFiles.Add(sRelativeFileName);
			}
		}
	}
	::FillComboBox(&m_ctrlProjects, arraySymbolFiles, m_sResourceSymbolFile);

	// Only enable the combobox if there's something in it
	m_ctrlProjects.EnableWindow(arraySymbolFiles.GetSize() > 0);

	if (CB_ERR == m_ctrlProjects.FindStringExact(0, m_sResourceSymbolFile) )
	{
		m_ctrlProjects.SetCurSel(0);

		UpdateData(TRUE);		// Update m_sResourceSymbolFile

		// Force the dependent controls to update
		OnCbnSelchangeResourceSymbolFile();

		return true;			// A true return indicates that the selection has changed
		
	}
	return false;				// The selection is unchanged
}


bool CResOrgNETAddInToolWinFormView::ConfigureSymbolManager(CResourceSymbolManager* pSymbols,
															const CString& sPathName) const
{
	CStdioFile f;
	CFileException e;

	if (f.Open(	sPathName,
				CFile::modeRead |
				CFile::shareDenyWrite,
				&e) )
	{
		// File opened OK
		//
		// Now create an archive, and an empty text buffer
		CArchive ar(&f, CArchive::load);

		pSymbols->Serialize(ar);

		try
		{
			ar.Flush();
			ar.Close();
			f.Flush();
			f.Close();
		}
		catch (CException* e)
		{
			TCHAR szCause[255];
			e->GetErrorMessage(szCause, 255);

			CString sMsg;
			sMsg.Format(IDS_TOOLWIN_ERR_CLOSING_FILE, szCause);

			TRACE1("%s\n", sMsg);
			::AfxMessageBox(sMsg, MB_OK | MB_ICONSTOP);

			e->Delete();

			return false;
		}
		return true;
	}
	return false;
}


bool CResOrgNETAddInToolWinFormView::UpdateSymbolPropertiesCtrls(void)
{
	bool bResult = false;

	if ( (NULL != m_pSymbols) && !m_sResourceSymbolFile.IsEmpty() )
	{
		CResourceSymbolCounts Info;
		m_pSymbols->GetSymbolCount(Info);

		m_sResourceRange.LoadString(IDS_TOOLWIN_SYM_RANGE_NONE);
		m_sCommandRange.LoadString(IDS_TOOLWIN_SYM_RANGE_NONE);

		if (Info.m_uMaxResource > 0)
		{
			m_sResourceRange.Format(_T("%d - %d"),
									Info.m_uMinResource,
									Info.m_uMaxResource);
		}
		if (Info.m_uMaxCommand > 0)
		{
			m_sCommandRange.Format(	_T("%d - %d"), 
									Info.m_uMinCommand,
									Info.m_uMaxCommand);
		}

		m_nOutOfRangeSymbols	= m_pSymbols->GetProblemSymbolCount() - m_pSymbols->GetConflictCount();
		m_nConflicts			= m_pSymbols->GetConflictCount();

		CString	sOpenTags	= _T("<b><font color=\"red\">");
		CString sCloseTags	= _T("</font></b>");

		UINT uWarningMsgID = 0;

		if (m_nOutOfRangeSymbols > 0)
		{
			m_sOutOfRangeSymbolsCaption = sOpenTags + CString( (LPCSTR)IDS_TOOLWIN_SYM_OUT_OF_RANGE_CAPTION) + sCloseTags;
			m_sOutOfRangeSymbols		= sOpenTags + ::IntToStr(m_nOutOfRangeSymbols) + sCloseTags;

			uWarningMsgID = IDS_TOOLWIN_WARN_VALUE_OUT_OF_RANGE;
		}
		else
		{
			m_sOutOfRangeSymbolsCaption = CString( (LPCSTR)IDS_TOOLWIN_SYM_OUT_OF_RANGE_CAPTION);
			m_sOutOfRangeSymbols		= ::IntToStr(m_nOutOfRangeSymbols);
		}

		if (m_nConflicts > 0)
		{
			m_sConflictsCaption			= sOpenTags + CString( (LPCSTR)IDS_TOOLWIN_SYM_CONFLICTS_CAPTION) + sCloseTags;
			m_sConflicts				= sOpenTags + ::IntToStr(m_nConflicts) + sCloseTags;

			uWarningMsgID = IDS_TOOLWIN_WARN_VALUE_CONFLICT;
		}
		else
		{
			m_sConflictsCaption			= CString( (LPCSTR)IDS_TOOLWIN_SYM_CONFLICTS_CAPTION);
			m_sConflicts				= ::IntToStr(m_nConflicts);
		}

		if (uWarningMsgID > 0)
		{
			m_ctrlWarningIcon.SetIcon( ::AfxGetApp()->LoadStandardIcon(IDI_EXCLAMATION) );

			m_ctrlWarningIcon.ShowWindow(TRUE);
			m_ctrlWarningText.ShowWindow(TRUE);

			m_sWarningText.LoadString(uWarningMsgID);
		}
		else
		{
			if (m_pSymbols->AreNextSymbolValuesInUse() )
			{
				m_ctrlWarningIcon.SetIcon( ::AfxGetApp()->LoadStandardIcon(IDI_EXCLAMATION) );

				m_ctrlWarningIcon.ShowWindow(TRUE);
				m_ctrlWarningText.ShowWindow(TRUE);

				m_sWarningText.LoadString(IDP_TOOLWIN_WARN_NEXT_SYM_VALUES);
			}
			else
			{
				#ifdef _RESORG_EXPIRY_DATE
					ShowExpiryWarning();
				#else
					m_ctrlWarningIcon.ShowWindow(FALSE);
					m_ctrlWarningText.ShowWindow(FALSE);

					m_sWarningText =	_T("");
				#endif
			}
		}
		bResult = true;
	}
	else
	{
		m_sResourceRange		= _T("N/A");
		m_sCommandRange			= _T("N/A");

		m_sOutOfRangeSymbolsCaption.LoadString(IDS_TOOLWIN_SYM_OUT_OF_RANGE_CAPTION);
		m_sOutOfRangeSymbols	= _T("N/A");

		m_sConflictsCaption.LoadString(IDS_TOOLWIN_SYM_CONFLICTS_CAPTION);
		m_sConflicts			= _T("N/A");

		#ifdef _RESORG_EXPIRY_DATE
			ShowExpiryWarning();
		#else
			m_ctrlWarningIcon.ShowWindow(FALSE);
			m_ctrlWarningText.ShowWindow(FALSE);
		#endif
	}
	UpdateData(FALSE);

	Invalidate();			// Force the HTML controls to repaint

	return bResult;
}


#ifdef _RESORG_EXPIRY_DATE
void CResOrgNETAddInToolWinFormView::ShowExpiryWarning(void)
{
	if (::IsVersionExpired() )
	{
		m_ctrlWarningIcon.SetIcon( ::AfxGetApp()->LoadStandardIcon(IDI_EXCLAMATION) );

		m_sWarningText.LoadString(IDP_RESORG_EXPIRED);

		m_sWarningText	= _T("<b><font color=\"red\">") + m_sWarningText + _T("</font></b>");
	}
	else
	{
		m_ctrlWarningIcon.SetIcon( ::AfxGetApp()->LoadStandardIcon(IDI_INFORMATION) );

		CTime timeExpires = GetVersionExpiryDate();

		CString sExpiryTime = timeExpires.Format( _T("%A, %d %B, %Y") );

		m_sWarningText.Format(IDP_RESORG_EXPIRY, sExpiryTime);

		m_sWarningText	= _T("<font color=\"blue\">") + m_sWarningText + _T("</font>");
	}
	m_ctrlWarningIcon.ShowWindow(TRUE);
	m_ctrlWarningText.ShowWindow(TRUE);
}
#endif


void CResOrgNETAddInToolWinFormView::SetAvailableControls(void)
{
	BOOL bAvailable = ( (NULL != m_pSymbols) && !m_sResourceSymbolFile.IsEmpty() );

	m_ctrlProperties.EnableWindow(bAvailable);
	m_ctrlEdit.EnableWindow(bAvailable);
	m_ctrlRenumber.EnableWindow(bAvailable);
}


CString CResOrgNETAddInToolWinFormView::GetFullPath(const CString& sRelativePath) const
{
	ASSERT(!m_sWorkspacePathName.IsEmpty() );

	CString sPathName;

	LPTSTR pszPathName = sPathName.GetBuffer(_MAX_PATH);

	::PathCombine(	pszPathName,
					m_sWorkspacePathName,
					sRelativePath);

	sPathName.ReleaseBuffer();

	return sPathName;
}


bool CResOrgNETAddInToolWinFormView::Save(CResourceSymbolManager* pSymbols)
{
	bool bResult = false;

	CString sPathName = pSymbols->GetPathName();
	if (!sPathName.IsEmpty() )
	{
		DWORD dwAttrib = ::GetFileAttributes(sPathName);
		if (::FileExists(sPathName) && (dwAttrib & FILE_ATTRIBUTE_READONLY) )
		{
			UINT eResult = ::DoOverwritePrompt(sPathName);
			switch (eResult)
			{
			case IDYES:
				if (!::SetFileAttributes(sPathName, dwAttrib & ~FILE_ATTRIBUTE_READONLY) )
				{
					::AfxMessageBox(IDP_TOOLWIN_ERR_FILE_ATTRIBUTES, MB_OK | MB_ICONSTOP);

					return false;
				}
				break;

			case IDNO:
				{
					CFileDialog dlg(FALSE,									// Save As
									CString( (LPCTSTR)IDS_FILE_FILTER_RESOURCE_SYMBOL_FILES_EXT),
																			// Default extension
									NULL,									// Default filename
									OFN_PATHMUSTEXIST | OFN_ENABLESIZING,	// Flags
									CString( (LPCTSTR)IDS_FILE_FILTER_RESOURCE_SYMBOL_FILES),
																			// File filter
									::AfxGetMainWnd() );					// Parent window

					if (IDOK != dlg.DoModal())
					{
						return false;
					}
					sPathName = dlg.GetPathName();
				}
				break;

			case IDCANCEL:
				return false;

			default:
				ASSERT(FALSE);
				break;
			}
		}

		try
		{
			// Save the file to disk
			CStdioFile f(	sPathName,
							CFile::modeWrite | CFile::modeCreate | CFile::shareDenyWrite);

			// File opened OK
			//
			// Now create an archive, and an empty text buffer
			CArchive ar(&f, CArchive::store);

			pSymbols->Serialize(ar);

			ar.Flush();
			ar.Close();
			f.Flush();
			f.Close();

			bResult = true;
		}
		catch (CException* e)
		{
			TCHAR szCause[_MAX_PATH];
			e->GetErrorMessage(szCause, _MAX_PATH);
			CString sMsg;

			sMsg.Format(IDP_TOOLWIN_ERR_SAVE_FILE, szCause);

			TRACE1("%s\n", sMsg);
			::AfxMessageBox(sMsg, MB_OK | MB_ICONSTOP);

			e->Delete();
		}
	}
	return bResult;
}


/////////////////////////////////////////////////////////////////////////////
// CResOrgNETAddInToolWinFormView diagnostics

#ifdef _DEBUG
void CResOrgNETAddInToolWinFormView::AssertValid(void) const
{
	CResOrgNETAddInToolWinFormView_BASE::AssertValid();
}


void CResOrgNETAddInToolWinFormView::Dump(CDumpContext& dc) const
{
	CResOrgNETAddInToolWinFormView_BASE::Dump(dc);
}
#endif //_DEBUG



/////////////////////////////////////////////////////////////////////////////
// CResOrgNETAddInToolWinFormView message handlers

HBRUSH CResOrgNETAddInToolWinFormView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
#if 1
	return CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
#else
	// Stubbed since I can't get the HTML control to be transparent.
	// Although I could get around this by setting its background colour
	// there are more pressing things to do right now!
	CFormView::OnCtlColor(pDC, pWnd, nCtlColor);

	// TO DO: Make this the background colour for toolwindows, or failing that use COLOR_WINDOW
	HBRUSH hbr = (HBRUSH)::GetStockObject(WHITE_BRUSH);

	switch (nCtlColor)
	{
		case CTLCOLOR_BTN:
		case CTLCOLOR_EDIT:
		case CTLCOLOR_STATIC:
			pDC->SetBkMode(TRANSPARENT);
			break;

		default:
			// Is this the warning message?
			if (pWnd->GetDlgCtrlID() == IDC_TOOLWIN_WARNING_MSG)
			{
				pDC->SetBkMode(TRANSPARENT);
			}
			break;
	}
	return hbr;
#endif
}


void CResOrgNETAddInToolWinFormView::OnCbnSelchangeResourceSymbolFile(void)
{
	if (m_FileChangeMonitor.IsMonitoring() )
	{
		m_FileChangeMonitor.Stop();
	}

	UpdateData(TRUE);

	if (!m_sWorkspacePathName.IsEmpty() && !m_sResourceSymbolFile.IsEmpty() )
	{
		CNGSplitPath split(m_sWorkspacePathName);
		CString sWorkspaceFolder = split.GetDrive() + split.GetDirectory();

		CString sPathName = ::CombinePath(sWorkspaceFolder, m_sResourceSymbolFile);

		// If the file has changed, parse it and update statistics
		if ( ConfigureSymbolManager(m_pSymbols, sPathName) )
		{
			m_FileChangeMonitor.Start(	sPathName,
										this,
										WM_USER_RESID_FILE_CHANGED);
		}
		UpdateSymbolPropertiesCtrls();
	}
}


void CResOrgNETAddInToolWinFormView::OnBnClickedToolwinRefresh(void)
{
	Refresh();
}


const UINT WM_RESORG_OPEN = ::RegisterWindowMessage( _T("ResOrgShowMainWnd") );

void CResOrgNETAddInToolWinFormView::OnBnClickedToolwinEdit(void)
{
	if (::IsWindow(m_hWndResOrg) )
	{
		#ifdef _RESORG_EXPIRY_DATE
			::DoVersionExpiryCheck();
		#endif

		CNGSplitPath split(m_sWorkspacePathName);
		CString sWorkspaceFolder = split.GetDrive() + split.GetDirectory();

		CString sPathName = ::CombinePath(sWorkspaceFolder, m_sResourceSymbolFile);

		::SendMessage(m_hWndResOrg, WM_RESORG_OPEN,	0, (LPARAM)(LPCTSTR)sPathName);
	}
}


void CResOrgNETAddInToolWinFormView::OnBnClickedToolwinRenumber(void)
{
	#ifdef _RESORG_EXPIRY_DATE
		::DoVersionExpiryCheck();
	#endif

	// To renumber all the symbols in a given file we need to pick starting
	// values for each of the four symbol catgories identified by the _APS_NEXT...
	// symbols in each resource file.
	//
	// The Symbol Renumbering Wizard works this out by looking at the values
	// of existing symbols in the resource symbol file.
	//
	CRenumWizard Wizard;
	Wizard.Initialise(m_pSymbols);

	if (ID_WIZFINISH == Wizard.DoModal() )
	{
		if (m_pSymbols->IsModified() )
		{
			if (Save(m_pSymbols) )
			{
				UpdateSymbolPropertiesCtrls();			
			}
			else
			{
				// Restore previous values
				OnCbnSelchangeResourceSymbolFile();
			}
		}
	}
}


void CResOrgNETAddInToolWinFormView::OnBnClickedToolwinProperties(void)
{
	#ifdef _RESORG_EXPIRY_DATE
		::DoVersionExpiryCheck();
	#endif

	CResourceSymbolFilePropertySheet dlg(	IDP_SYM_FILE_PROPERTIES_CAPTION,
											::AfxGetMainWnd() );

	dlg.Initialise(m_pSymbols, NULL);

	if (IDOK == dlg.DoModal())
	{
		if (m_pSymbols->IsModified() )
		{
			if (Save(m_pSymbols) )
			{
				UpdateSymbolPropertiesCtrls();			
			}
			else
			{
				// Restore previous values
				OnCbnSelchangeResourceSymbolFile();
			}
		}
	}
}


LRESULT CResOrgNETAddInToolWinFormView::OnMsgResourceSymbolFileChanged(WPARAM wParam, LPARAM lParam)
{
	UNREFERENCED_PARAMETER(wParam);
	UNREFERENCED_PARAMETER(lParam);

	// Refresh the displayed properties and restart the monitor
	OnCbnSelchangeResourceSymbolFile();

	return 0L;
}

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)

Share

About the Author

Anna-Jayne Metcalfe
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!
Follow on   Twitter

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141216.1 | Last Updated 10 Jan 2005
Article Copyright 2001 by Anna-Jayne Metcalfe
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid