Click here to Skip to main content
15,881,139 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 529.9K   12.1K   201  
An application/add-in to organise and renumber resource symbol IDs
// ResOrgProjectsListCtrlVc7.cpp : implementation file
//

#include "stdafx.h"
#include "ResOrgNETAddInToolWindows.h"
#include "ResOrgNETProjectsListCtrl.h"


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


/////////////////////////////////////////////////////////////////////////////
// CResOrgProjectsListCtrlVc7

IMPLEMENT_DYNAMIC(CResOrgProjectsListCtrlVc7, CResOrgProjectsListCtrlVc7_BASE)


/////////////////////////////////////////////////////////////////////////////
// CResOrgProjectsListCtrlVc7 construction/destruction

CResOrgProjectsListCtrlVc7::CResOrgProjectsListCtrlVc7(void)
{
	m_bInitialised		= FALSE;
	m_nSortColumn		= 0;
	m_bSortAscending	= true;
}


CResOrgProjectsListCtrlVc7::~CResOrgProjectsListCtrlVc7(void)
{
	Clear();

	m_AutomationHelper.SetDTE(NULL);
}


/******************************************************************************
 *	Message Map implementation
 *
 ******************************************************************************/

BEGIN_MESSAGE_MAP(CResOrgProjectsListCtrlVc7, CResOrgProjectsListCtrlVc7_BASE)

	ON_WM_SIZE()

END_MESSAGE_MAP()



/////////////////////////////////////////////////////////////////////////////
// CResOrgProjectsListCtrlVc7 overrides

/******************************************************************************
 *	This method is called by the framework before the creation of the
 *	window attached to this CWnd object.
 *
 *	This override is used to modify the window styles here to set the List
 *	control style to report view.
 *
 *	This is achieved by masking out the view style using LVS_TYPEMASK
 *	and setting the LVS_REPORT style. LVS_SINGLESEL is also set to allow
 *	only single selections.
 *
 *	Note that we DON'T want the LVS_SORTASCENDING style as this sorts items
 *	by item text and in this case we cannot have a comparison function.
 *
 ******************************************************************************/

BOOL CResOrgProjectsListCtrlVc7::PreCreateWindow(CREATESTRUCT& cs)
{
	cs.style = (cs.style & ~LVS_TYPEMASK) | LVS_REPORT /*| LVS_SINGLESEL*/ | LVS_SHOWSELALWAYS;

	return CResOrgProjectsListCtrlVc7_BASE::PreCreateWindow(cs);
}


bool CResOrgProjectsListCtrlVc7::SortList(int nColumn, bool bAscending)
{
	m_nSortColumn		= nColumn;
	m_bSortAscending	= bAscending;

	// Resort contents if sorted before
	if (m_nSortColumn >= 0)
	{
		CCJSortClass sorter(this, m_nSortColumn);
		sorter.Sort(m_bSortAscending, DT_STRING);

		return true;
	}
	return false;
}


/////////////////////////////////////////////////////////////////////////////
// CResOrgProjectsListCtrlVc7 operations

bool CResOrgProjectsListCtrlVc7::Initialise(CComPtr<EnvDTE::_DTE> pDTE)
{
	// Change style to have:
	//
	//	1.	Flat header (requires CJListCtrl)
	//	2.	Full row selection (requires ComCtl32.dll v4.71)
	//
	if (!m_bInitialised)
	{
		m_AutomationHelper.SetDTE(pDTE);

		CCJThemeHelper theme;
		if (!theme.IsAppThemed() )
		{
			SubclassHeader();
		}
		SetExtendedStyle(GetExtendedStyle() | LVS_EX_FULLROWSELECT);

		CRect rect;
		GetClientRect(rect);

		InsertColumn(	0,
						_T("Project"),
						LVCFMT_LEFT,
						rect.Width(),
						-1);

		m_bInitialised = true;

		return true;
	}
	return false;
}


void CResOrgProjectsListCtrlVc7::Clear(void)
{
	if (::IsWindow(m_hWnd) )
	{
		DeleteAllItems();
	}
	for (int n = 0; n < m_arrayProjects.GetSize(); n++)
	{
		EnvDTE::Project* pProject = m_arrayProjects[n];
		if (NULL != pProject)
		{
			pProject->Release();
		}
	}
	m_arrayProjects.RemoveAll();
}


/////////////////////////////////////////////////////////////////////////////
// CResOrgProjectsListCtrlVc7 implementation

void CResOrgProjectsListCtrlVc7::FillListCtrl(void)
{
	SetRedraw(FALSE);

	Clear();

	m_AutomationHelper.GetProjects(m_arrayProjects);

	int nItem = -1;

	for (int n = 0; n < m_arrayProjects.GetSize(); n++)
	{
		EnvDTE::Project* pProject = m_arrayProjects[n];
		if (NULL != pProject)
		{
			CString sProject = m_AutomationHelper.GetName(pProject);

			VERIFY(-1 != InsertItem(++nItem, sProject) );

			SetItemData(nItem, (DWORD_PTR)pProject);
		}
	}
	SortList(m_nSortColumn, m_bSortAscending);

	SetRedraw(TRUE);
}


/////////////////////////////////////////////////////////////////////////////
// CResOrgProjectsListCtrlVc7 message handlers

void CResOrgProjectsListCtrlVc7::OnSize(UINT nType, int cx, int cy) 
{
	CResOrgProjectsListCtrlVc7_BASE::OnSize(nType, cx, cy);
	
	if (m_bInitialised)
	{
		AutoSizeColumn();
	}
}



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