Click here to Skip to main content
11,494,407 members (73,297 online)
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 351K 10K 199
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
/////////////////////////////////////////////////////////////////////////////
//
// MRUCombo.cpp: Implementation file for the CNGRecentItemComboBox class.
//
// Written by Michael Dunn <mdunn at inreach dot com>
//
// Modified by Anna-Jayne Metcalfe to use CNGRecentItemList instead of CRecentFileList
//
/////////////////////////////////////////////////////////////////////////////
//
// Revision history:
//
//  9/9/1998: First release.
//
/////////////////////////////////////////////////////////////////////////////

#include "StdAfx.h"
#include "NGRecentItemComboBox.h"


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

#define MRUC_DEFAULT_MRU_SIZE   10


/////////////////////////////////////////////////////////////////////////////
// CNGRecentItemComboBox constructor & destructor


//////////////////////////////////////////////////////////////////////////
//
// Function:    CNGRecentItemComboBox()
//
// Description:
//  Class constructor.
//
// Notes:
//  Calls base class constructor and initializes member variables.
//
//////////////////////////////////////////////////////////////////////////

CNGRecentItemComboBox::CNGRecentItemComboBox() : CComboBox(),
    m_bRefreshAfterAdd   ( FALSE ),
    m_bSaveAfterAdd      ( FALSE ),
    m_bSaveOnDestroy     ( TRUE ),
    m_nMaxMRUSize        ( MRUC_DEFAULT_MRU_SIZE ),
    m_pMRU               ( NULL ),
    m_bParamsChanged     ( FALSE )
{
}


//////////////////////////////////////////////////////////////////////////
//
// Function:    CNGRecentItemComboBox()
//
// Description:
//  Class destructor.
//
//////////////////////////////////////////////////////////////////////////

CNGRecentItemComboBox::~CNGRecentItemComboBox(void)
{                                        // Save the MRU if we need to.
    if ( m_bSaveOnDestroy )
	{
        if ( !SaveMRU() )
		{
            TRACE( _T("CNGRecentItemComboBox -- Warning - SaveMRU() in destructor failed. MRU was not saved.\n") );
		}
	}

                                        // Free up the CRecentFileList object.
    if ( NULL != m_pMRU )
	{
        delete m_pMRU;
	}
}


BEGIN_MESSAGE_MAP(CNGRecentItemComboBox, CComboBox)
	//{{AFX_MSG_MAP(CNGRecentItemComboBox)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CNGRecentItemComboBox MRU operations


//////////////////////////////////////////////////////////////////////////
//
// Function:    AddToMRU()
//
// Description:
//  Adds a string to the MRU list.
//
// Input:
//  szNewItem: [in] The string to add.
//
// Returns:
//  TRUE if successful, FALSE if not.
//
//////////////////////////////////////////////////////////////////////////

BOOL CNGRecentItemComboBox::AddToMRU ( LPCTSTR szNewItem )
{
                                        // String can't be a null pointer!
    ASSERT ( NULL != szNewItem );

                                        // Allocate a new CRecentFileList 
                                        // if necessary.
    if ( NULL == m_pMRU )
	{
		if ( !AllocNewMRU() )
		{
			TRACE( _T("CNGRecentItemComboBox -- AllocNewMRU() failed in AddToMRU().\n") );
            return FALSE;
		}
	}

	m_pMRU->Add ( szNewItem );			// Add it to the MRU list.
    
                                        // Automagically refresh the combobox?
    if ( m_bRefreshAfterAdd )
	{
		RefreshCtrl();
	}

                                        // Automagically save the MRU?
    if ( m_bSaveAfterAdd )
	{
		SaveMRU();
	}


    return TRUE;
}


BOOL CNGRecentItemComboBox::RemoveFromMRU(int nItem)
{
	if ( (NULL != m_pMRU) && (nItem >= 0) && (nItem < GetCount() ) )
	{
		DeleteString(nItem);

		ASSERT( (*m_pMRU)[nItem].GetLength() > 0 );

		m_pMRU->Remove(nItem);

		AllocNewMRU();

		if (m_bSaveAfterAdd)
		{
	        SaveMRU();
		}
		RefreshCtrl();

		return TRUE;
	}
	return FALSE;
}


//////////////////////////////////////////////////////////////////////////
//
// Function:    EmptyMRU()
//
// Description:
//  Removes all strings from the MRU list.
//
// Input:
//  Nothing.
//
// Returns:
//  Nothing.
//
//////////////////////////////////////////////////////////////////////////

void CNGRecentItemComboBox::EmptyMRU()
{
	int i = 0;

    if ( NULL != m_pMRU )
	{
                                        // Remove all strings from the MRU list.
                                        // Go in reverse order to keep the
                                        // strings from changing positions 
                                        // while we're doing our dirty work.
        for ( i = m_pMRU->GetSize() - 1; i >= 0; i-- )
		{
            m_pMRU->Remove(i);
		}
	}
}


//////////////////////////////////////////////////////////////////////////
//
// Function:    LoadMRU()
//
// Description:
//  Loads an MRU from the registry or the app's INI file.
//
// Input:
//  Nothing.
//
// Returns:
//  TRUE if successful, FALSE if not.
//
//////////////////////////////////////////////////////////////////////////

BOOL CNGRecentItemComboBox::LoadMRU()
{
                                        // We always allocate a new
                                        // CRecentFileList object when loading.
    if ( !AllocNewMRU() )
	{
        TRACE( _T("CNGRecentItemComboBox -- AllocNewMRU() failed in LoadMRU().\n") );
        return FALSE;
	}

    m_pMRU->ReadList();

    return TRUE;
}


//////////////////////////////////////////////////////////////////////////
//
// Function:    SaveMRU()
//
// Description:
//  Writes the MRU to the registry or app's INI file.
//
// Input:
//  Nothing.
//
// Returns:
//  TRUE if successful, FALSE if not.
//
//////////////////////////////////////////////////////////////////////////

BOOL CNGRecentItemComboBox::SaveMRU()
{
                                        // If we haven't created a 
                                        // CRecentFileList yet, then there's
                                        // nothing to save.
    if ( NULL == m_pMRU )
	{
        TRACE( _T("CNGRecentItemComboBox -- SaveMRU failed - no CRecentFileList created.\n") );
        return FALSE;
	}

                                        // Check that the CRecentFileList 
                                        // parameters are kosher.
    if ( !VerifyMRUParams() )
	{
        TRACE( _T("CNGRecentItemComboBox -- SaveMRU() failed - params not set.\n") );
        return FALSE;
	}

                                        // If the registry key/value strings
                                        // have been changed, we need to make
                                        // a new CRecentFileList.
    if ( m_bParamsChanged )
	{
        if ( !AllocNewMRU() )
		{
            TRACE( _T("CNGRecentItemComboBox -- SaveMRU failed - couldn't reallocate CRecentFileList with new MRU params.\n") );
            return FALSE;
		}
	}

    m_pMRU->WriteList();

    return TRUE;
}


/////////////////////////////////////////////////////////////////////////////
// CNGRecentItemComboBox combobox control operations


//////////////////////////////////////////////////////////////////////////
//
// Function:    RefreshCtrl()
//
// Description:
//  Sets the contents of the combobox according to the MRU list.
//
// Input:
//  Nothing.
//
// Returns:
//  Nothing.
//
//////////////////////////////////////////////////////////////////////////

void CNGRecentItemComboBox::RefreshCtrl()
{
	CString cstrComboText;
                                        // Save the contents of the edit
                                        // portion of the combobox.
    GetWindowText ( cstrComboText );

    ResetContent();

    for ( int i = 0; i < m_pMRU->GetSize(); i++ )
	{
                                        // Don't add empty strings to the combobox.
        if ( (*m_pMRU)[i].GetLength() > 0 )
		{
            if ( AddString ( (*m_pMRU)[i] ) < 0 )
			{
                TRACE( _T("CNGRecentItemComboBox -- Warning - RefreshCtrl() couldn't add MRU item %d to combobox.\n"),
                       i );
			}
		}
	}

	// Restore the editbox text.
	int nItem = (int)SendMessage(CB_FINDSTRINGEXACT,
								 (WPARAM)-1,
								 (LPARAM)(LPCTSTR)cstrComboText);
	if (nItem >= 0)
	{
		// select it
		SetCurSel(nItem);
	}
	else
	{
		// just set the edit text (this will be ignored if this is a drop list)
		SetWindowText(cstrComboText);
	}
}


/////////////////////////////////////////////////////////////////////////////
// CNGRecentItemComboBox data accessor functions


//////////////////////////////////////////////////////////////////////////
//
// Function:    SetMRURegKey()
//
// Description:
//  Sets the registry key (or INI file section) in which the MRU will be
//  saved.
//
// Input:
//  szRegKey: [in] The key/section name.
//
// Returns:
//  Nothing.
//
//////////////////////////////////////////////////////////////////////////

void CNGRecentItemComboBox::SetMRURegKey ( LPCTSTR szRegKey )
{
                                        // The key name can't be a null string.
    ASSERT ( NULL != szRegKey );

    try
	{
                                        // Store the reg key name & set the
                                        // changed flag.
        m_cstrRegKey = szRegKey;

        m_bParamsChanged = TRUE;
	}
    catch (CMemoryException* e)
	{
        TRACE( _T("CNGRecentItemComboBox -- Memory exception in CNGRecentItemComboBox::SetMRURegKey()!\n") );
		e->Delete();
        throw;
	}
}


//////////////////////////////////////////////////////////////////////////
//
// Function:    GetMRURegKey
//
// Description:
//  Returns the current registry key or INI file section in which the MRU
//  will be saved.
//
// Input:
//  Nothing.
//
// Returns:
//  The key name.
//
//////////////////////////////////////////////////////////////////////////

const CString& CNGRecentItemComboBox::GetMRURegKey() const
{
    return m_cstrRegKey;
}


//////////////////////////////////////////////////////////////////////////
//
// Function:    SetMRUValueFormat()
//
// Description:
//  Sets the format to be used for writing MRU items to the registry or
//  the app's INI file.
//
// Input:
//  szValueFormat: [in] The format to use.
//
// Returns:
//  TRUE if the format is acceptable (i.e., contains "%d"), FALSE if not.
//
//////////////////////////////////////////////////////////////////////////

BOOL CNGRecentItemComboBox::SetMRUValueFormat ( LPCTSTR szValueFormat )
{
BOOL bRetVal = FALSE;

                                        // The key name can't be a null string.
    ASSERT ( NULL != szValueFormat );


                                        // Check that the format strings 
                                        // contains "%d"
    if ( NULL == _tcsstr ( szValueFormat, _T("%d") ) )
	{
        TRACE( _T("CNGRecentItemComboBox -- SetMRUValueFormat() returning FALSE - argument didn't contain \"%d\"\n") );
        return FALSE;
	}
    else
	{
        try
		{
                                        // Save the format string and set the
                                        // changed flag.
            m_cstrRegValueFormat = szValueFormat;
            m_bParamsChanged = TRUE;
            bRetVal = TRUE;
		}
        catch (CMemoryException* e)
		{
            TRACE( _T("CNGRecentItemComboBox -- Memory exception in CNGRecentItemComboBox::SetMRUValueFormat()!\n") );
			e->Delete();
            throw;
		}
	}

    return bRetVal;
}


//////////////////////////////////////////////////////////////////////////
//
// Function:    GetMRUValueFormat
//
// Description:
//  Returns the current registry value format string.
//
// Input:
//  Nothing.
//
// Returns:
//  The format string.
//
//////////////////////////////////////////////////////////////////////////

const CString& CNGRecentItemComboBox::GetMRUValueFormat() const
{
    return m_cstrRegValueFormat;
}


//////////////////////////////////////////////////////////////////////////
//
// Function:    SetMaxMRUSize()
//
// Description:
//  Sets the max number of entries that the MRU can hold.
//
// Input:
//  nMaxSize: [in] The new MRU size.
//
// Returns:
//  The previous MRU size, or 0 if there was no previous MRU allocated, or
//  -1 on error.
//
// Notes:
//  This function always reallocates a CRecentFileList so that the size
//  change (and registry string changes, if any) takes place immediately.
//
//////////////////////////////////////////////////////////////////////////

int CNGRecentItemComboBox::SetMaxMRUSize ( int nMaxSize )
{
int nRetVal = m_nMaxMRUSize;

                                        // New size needs to be a positive
                                        // number.
    ASSERT ( nMaxSize >= 1 );

    if ( nMaxSize <= 0 )
        return -1;


    m_nMaxMRUSize = nMaxSize;

    if ( NULL == m_pMRU )
	{
        nRetVal = 0;                    // no previous size
	}

    if ( !AllocNewMRU() )
	{
        nRetVal = -1;                   // error!!
        TRACE( _T("CNGRecentItemComboBox -- SetMaxMRUSize() failed - couldn't allocate new CRecentFileList.\n") );
	}

    return nRetVal;
}


//////////////////////////////////////////////////////////////////////////
//
// Function:    GetMaxMRUSize
//
// Description:
//  Returns the current max MRU size.
//
// Input:
//  Nothing.
//
// Returns:
//  The current max size.
//
//////////////////////////////////////////////////////////////////////////

int CNGRecentItemComboBox::GetMaxMRUSize() const
{
    return m_nMaxMRUSize;
}


//////////////////////////////////////////////////////////////////////////
//
// Function:    SetAutoSaveOnDestroy()
//
// Description:
//  Sets whether the CNGRecentItemComboBox will automatically save the MRU when
//  the object is destroyed.
//
// Input:
//  bAutoSave: [in] Flag: enable auto-saving?
//
// Returns:
//  The previous value of this setting.
//
//////////////////////////////////////////////////////////////////////////

BOOL CNGRecentItemComboBox::SetAutoSaveOnDestroy ( BOOL bAutoSave )
{
	BOOL bRetVal = m_bSaveOnDestroy;

    m_bSaveOnDestroy = bAutoSave;

    return bRetVal;
}


//////////////////////////////////////////////////////////////////////////
//
// Function:    SetAutoSaveAfterAdd()
//
// Description:
//  Sets whether the CNGRecentItemComboBox will automatically save the MRU after
//  an item is added successfully.
//
// Input:
//  bAutoSave: [in] Flag: enable auto-saving?
//
// Returns:
//  The previous value of this setting.
//
//////////////////////////////////////////////////////////////////////////

BOOL CNGRecentItemComboBox::SetAutoSaveAfterAdd ( BOOL bAutoSave )
{
	BOOL bRetVal = m_bSaveAfterAdd;

    m_bSaveAfterAdd = bAutoSave;

    return bRetVal;
}


//////////////////////////////////////////////////////////////////////////
//
// Function:    SetAutoRefreshAfterAdd()
//
// Description:
//  Sets whether the CNGRecentItemComboBox will automatically refresh the combobox
//  control after an item is added successfully.
//
// Input:
//  bAutoSave: [in] Flag: enable auto-refresh?
//
// Returns:
//  The previous value of this setting.
//
//////////////////////////////////////////////////////////////////////////

BOOL CNGRecentItemComboBox::SetAutoRefreshAfterAdd ( BOOL bAutoSave )
{
	BOOL bRetVal = m_bRefreshAfterAdd;

    m_bRefreshAfterAdd = bAutoSave;

    return bRetVal;
}


/////////////////////////////////////////////////////////////////////////////
// CNGRecentItemComboBox misc. functions


//////////////////////////////////////////////////////////////////////////
//
// Function:    VerifyMRUParams()
//
// Description:
//  Checks the registry and size parameters and makes sure they're valid
//  for CRecentFileList.
//
// Input:
//  Nothing. (uses member variables)
//
// Returns:
//  TRUE if the params are OK, FALSE if not.
//
//////////////////////////////////////////////////////////////////////////

BOOL CNGRecentItemComboBox::VerifyMRUParams() const
{
BOOL bRetVal = TRUE;

                                        // 1. The registry key string must be
                                        //    non-empty.
    if ( m_cstrRegKey.IsEmpty() || 0 == m_cstrRegKey.GetLength() )
	{
        TRACE( _T("CNGRecentItemComboBox -- VerifyMRUParams() - registry key name not set.\n") );
        bRetVal = FALSE;
	}

                                        // 2. The reg value must be non-empty
                                        //    and contain "%d"
    if ( m_cstrRegValueFormat.IsEmpty() || 
         0 == m_cstrRegValueFormat.GetLength() )
	{
        TRACE( _T("CNGRecentItemComboBox -- VerifyMRUParams() - registry value format not set.\n") );
        bRetVal = FALSE;
	}
    else if ( -1 == m_cstrRegValueFormat.Find ( _T("%d") ) )
	{
        TRACE( _T("CNGRecentItemComboBox -- VerifyMRUParams() - registry value format doesn't contain \"%d\"\n") );
        bRetVal = FALSE;
	}

                                        // 3. The Max MRU size must be > 0.
    if ( m_nMaxMRUSize <= 0 )
	{
        TRACE( _T("CNGRecentItemComboBox -- VerifyMRUParams() - max MRU size is set to <= 0\n") );
        bRetVal = FALSE;
	}

    return bRetVal;
}


//////////////////////////////////////////////////////////////////////////
//
// Function:    AllocNewMRU()
//
// Description:
//  Allocates a new CRecentFileList, and copies the contents of the previous
//  MRU (if any) to the new one.
//
// Input:
//  Nothing.
//
// Returns:
//  TRUE if successful, FALSE if not.
//
//////////////////////////////////////////////////////////////////////////

BOOL CNGRecentItemComboBox::AllocNewMRU()
{
	CString* acstrOldList = NULL;
	int      nItemsToCopy;
	int      i;
                                        // Make sure the MRU params are OK.
    if ( !VerifyMRUParams() )
	{
        TRACE( _T("CNGRecentItemComboBox -- AllocNewMRU() returning FALSE - MRU list params invalid or not set.\n") );
        return FALSE;
	}


    try
	{
                                        // Figuring out how many strings to
                                        // copy: The lesser of the new MRU 
                                        // size and the previous MRU's size.
                                        // Of course, if there was no previous
                                        // MRU, then nothing will be copied.
        nItemsToCopy = m_nMaxMRUSize;

        if ( NULL != m_pMRU )
		{
            nItemsToCopy = __min ( m_nMaxMRUSize, m_pMRU->GetSize() );

                                        // Save the contents of the old MRU list.
            acstrOldList = new CString [ nItemsToCopy ];

            for ( i = 0; i < nItemsToCopy; i++ )
			{
                acstrOldList[i] = (*m_pMRU)[i];
			}
                                        // Nuke the old CRecentItemList object...
            delete m_pMRU;
		}

                                        // and make a new one!
        m_pMRU = new CNGRecentItemList( 1,
										m_cstrRegKey,
										m_cstrRegValueFormat,
										m_nMaxMRUSize );


        // Copy the MRU strings if there was a previous MRU.  We add
        // the strings in reverse numerical order so they end up in the same
        // order as they were in the old MRU.

        if ( NULL != acstrOldList )
        {
            for ( i = nItemsToCopy - 1; i >= 0; i-- )
            {
				if (!acstrOldList[i].IsEmpty() )
				{
					m_pMRU->Add ( acstrOldList[i] );
				}
            }

            delete [] acstrOldList;
        }
    }
    catch (CMemoryException* e)
    {
        TRACE( _T("CNGRecentItemComboBox -- Memory exception in AllocNewMRU()!\n") );
		e->Delete();
        
        if ( NULL != m_pMRU )
        {
            delete m_pMRU;
			m_pMRU = NULL;
        }

        throw;
	}

                                        // Reset the changed flag.
    m_bParamsChanged = FALSE;

    return TRUE;
}


/////////////////////////////////////////////////////////////////////////////
// CNGRecentFileComboBox

CNGRecentFileComboBox::CNGRecentFileComboBox(void)
{
}


CNGRecentFileComboBox::~CNGRecentFileComboBox(void)
{
}




BEGIN_MESSAGE_MAP(CNGRecentFileComboBox, CNGRecentItemComboBox)
	//{{AFX_MSG_MAP(CNGRecentFileComboBox)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNGRecentFileComboBox message handlers

void CNGRecentFileComboBox::PreSubclassWindow(void) 
{
	ASSERT( (GetStyle() & (CBS_OWNERDRAWFIXED | CBS_HASSTRINGS)) == (CBS_OWNERDRAWFIXED | CBS_HASSTRINGS) );

	CNGRecentItemComboBox::PreSubclassWindow();
}


void CNGRecentFileComboBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
	CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);

	if (((LONG)(lpDrawItemStruct->itemID) >= 0) &&
		(lpDrawItemStruct->itemAction & (ODA_DRAWENTIRE | ODA_SELECT)))
	{
		BOOL bDisabled = !IsWindowEnabled ();

		COLORREF newTextColor = bDisabled ?
			RGB(0x80, 0x80, 0x80) : GetSysColor (COLOR_WINDOWTEXT);  // light gray

		COLORREF oldTextColor = pDC->SetTextColor (newTextColor);

		COLORREF newBkColor = GetSysColor (COLOR_WINDOW);
		COLORREF oldBkColor = pDC->SetBkColor (newBkColor);

		if (newTextColor == newBkColor)
			newTextColor = RGB(0xC0, 0xC0, 0xC0);   // dark gray

		if (!bDisabled && ((lpDrawItemStruct->itemState & ODS_SELECTED) != 0))
		{
			pDC->SetTextColor (GetSysColor (COLOR_HIGHLIGHTTEXT));
			pDC->SetBkColor (GetSysColor (COLOR_HIGHLIGHT));
		}

		CString sText;
		GetLBText(lpDrawItemStruct->itemID, sText);

		const RECT &rc=lpDrawItemStruct->rcItem;

		CString	sCompactedPath = sText;
		LPTSTR pszCompactedPath = sCompactedPath.GetBuffer(_MAX_PATH);

		::PathCompactPath(	pDC->GetSafeHdc(),
							pszCompactedPath,
							rc.right - rc.left);

		sCompactedPath.ReleaseBuffer();

		pDC->ExtTextOut(rc.left + 2,
				  rc.top + 2,// + max(0, (cyItem - m_cyText) / 2),
				  ETO_OPAQUE, &rc,
				  sCompactedPath, sCompactedPath.GetLength (), NULL);

		pDC->SetTextColor (oldTextColor);
		pDC->SetBkColor (oldBkColor);
	}
	else if ((LONG)(lpDrawItemStruct->itemID)<0)	// drawing edit text
	{
		COLORREF newTextColor = GetSysColor (COLOR_WINDOWTEXT);  // light gray
		COLORREF oldTextColor = pDC->SetTextColor (newTextColor);

		COLORREF newBkColor = IsWindowEnabled() ? ::GetSysColor(COLOR_WINDOW) : ::GetSysColor(COLOR_3DFACE);

		COLORREF oldBkColor = pDC->SetBkColor (newBkColor);

		if ((lpDrawItemStruct->itemState & ODS_SELECTED) != 0)
		{
			pDC->SetTextColor (GetSysColor (COLOR_HIGHLIGHTTEXT));
			pDC->SetBkColor (GetSysColor (COLOR_HIGHLIGHT));
		}

		CString sText;
		GetWindowText(sText);

		if (!sText.IsEmpty() )
		{
			const RECT& rc = lpDrawItemStruct->rcItem;

			CString	sCompactedPath = sText;
			LPTSTR pszCompactedPath = sCompactedPath.GetBuffer(_MAX_PATH);

			::PathCompactPath(	pDC->GetSafeHdc(),
								pszCompactedPath,
								rc.right - rc.left);

			sCompactedPath.ReleaseBuffer();

			pDC->ExtTextOut(rc.left + 2,
					  rc.top + 2,// + max(0, (cyItem - m_cyText) / 2),
					  ETO_OPAQUE, &rc,
					  sCompactedPath, sCompactedPath.GetLength (), NULL);

			pDC->SetTextColor (oldTextColor);
			pDC->SetBkColor (oldBkColor);
		}
	}

	if ((lpDrawItemStruct->itemAction & ODA_FOCUS) != 0)
	{
		pDC->DrawFocusRect(&lpDrawItemStruct->rcItem);
	}
}


void CNGRecentFileComboBox::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) 
{
	// TODO: Add your code to determine the size of specified item
	UNREFERENCED_PARAMETER(lpMeasureItemStruct);
}

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
Web04 | 2.8.150520.1 | Last Updated 10 Jan 2005
Article Copyright 2001 by Anna-Jayne Metcalfe
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid