⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resorgappprojectsview.cpp

📁 一个vc中管理资源文件ID的插件
💻 CPP
字号:
/************************************************************************
 *
 *                   Resource ID Organiser Add-In
 *
 *       (c) Copyright 2000-2001 by Andy Metcalfe (andy.metcalfe@lineone.net)
 *                         All rights reserved.
 *
 ************************************************************************
 *                                                                       
 *  Filename    : ResOrgAppProjectsView.cpp
 *
 *  Description : CResOrgAppProjectsView - project workspace list view class
 *
 *  Compiler    : Microsoft Visual C++ 6.0, Service Pack 3 or 4
 *                                                                       
 *  Target                                                               
 *  Environment : Windows 98/NT
 *
 *  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 Andy 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.resorg.co.uk 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/ResOrgApp/ResOrgAppProjectsView.cpp $
 *   $Revision: 6 $
 *       $Date: 8/07/01 8:40 $
 *     $Author: Andy $
 *
 *    $History: ResOrgAppProjectsView.cpp $
 * 
 * *****************  Version 6  *****************
 * User: Andy         Date: 8/07/01    Time: 8:40
 * Updated in $/Projects/AddIns/ResOrg/ResOrgApp
 * The Projects Display now autosizes the list control when it is resized
 * 
 * *****************  Version 5  *****************
 * User: Andy         Date: 5/05/01    Time: 20:49
 * Updated in $/Projects/AddIns/ResOrg/ResOrgApp
 * Trap attempts to Renumber symbols in empty resource symbol files from
 * the Workspace Display
 * 
 * *****************  Version 4  *****************
 * User: Andy         Date: 26/04/01   Time: 19:47
 * Updated in $/Projects/AddIns/ResOrg/ResOrgApp
 * Renamed Resource.h to ResOrgAddIn_Res.h
 * 
 * *****************  Version 3  *****************
 * User: Andy         Date: 23/04/01   Time: 21:25
 * Updated in $/Projects/AddIns/ResOrg/ResOrgApp
 * Added icons to context menu
 * 
 * *****************  Version 2  *****************
 * User: Andy         Date: 5/03/01    Time: 19:12
 * Updated in $/Projects/AddIns/ResOrg/ResOrgApp
 * 1.  CResOrgAppProjectsView::OnCmdOpenProject() now displays a message
 * box if a resource symbol file cannot be located in a project instead of
 * ASSERTing
 * 2.  The Workspace Display is now disabled if no workspace is loaded
 * 3.  CResOrgAppProjectsView::SortList() now calls the base class
 * implementation to set the correct sort image in the header control
 * 4.  Items inserted into the list control now have their item data set
 * to allow sorting
 * 5.  CResOrgAppProjectsView::OnCmdOpenProject() now displays a message
 * box instead of ASSERTing if no resource symbol file can be identified
 * within a project
 * 
 * *****************  Version 1  *****************
 * User: Andy         Date: 2/03/01    Time: 17:20
 * Created in $/Projects/AddIns/ResOrg/ResOrgApp
 * 
 * *****************  Version 4  *****************
 * User: Andy         Date: 17/02/01   Time: 7:08
 * Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
 * Context menu ID changed
 * 
 * *****************  Version 3  *****************
 * User: Andy         Date: 29/11/00   Time: 18:37
 * Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
 * 1.  Moved Office2KDlg code to its own DLL
 * 2.  Added file banners
 *
 * $Nokeywords: $
 *
 ************************************************************************/

// ResOrgAppProjectsView.cpp : implementation of the CResOrgAppProjectsView class
//

#include "StdAfx.h"
#include "ResOrgApp_Res.h"

#include "ResOrgAppProjectsDoc.h"

#include "ResOrgAppProjectsView.h"


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


/////////////////////////////////////////////////////////////////////////////
// CResOrgAppProjectsView

IMPLEMENT_DYNCREATE(CResOrgAppProjectsView, CResOrgAppProjectsView_BASE)

BEGIN_MESSAGE_MAP(CResOrgAppProjectsView, CResOrgAppProjectsView_BASE)
	//{{AFX_MSG_MAP(CResOrgAppProjectsView)
	ON_WM_SIZE()
	ON_WM_CONTEXTMENU()
	ON_COMMAND(						ID_PROJ_OPEN,				OnCmdOpenProject)
	ON_COMMAND(						ID_PROJ_RENUMBER,			OnCmdRenumberProject)
	ON_UPDATE_COMMAND_UI(			ID_PROJ_RENUMBER,			OnUpdateRenumberProject)
	//}}AFX_MSG_MAP

	// The following are outside of ClassWizard's reach as it can't understand
	// them....
	ON_NOTIFY_REFLECT(	NM_DBLCLK,								OnDblClick)
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CResOrgAppProjectsView construction/destruction

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


CResOrgAppProjectsView::~CResOrgAppProjectsView(void)
{
	Clear();
}


/////////////////////////////////////////////////////////////////////////////
// CResOrgAppProjectsView 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 CResOrgAppProjectsView::PreCreateWindow(CREATESTRUCT& cs)
{
	cs.style = (cs.style & ~LVS_TYPEMASK) | LVS_REPORT /*| LVS_SINGLESEL*/ | LVS_SHOWSELALWAYS;

	return CResOrgAppProjectsView_BASE::PreCreateWindow(cs);
}


void CResOrgAppProjectsView::OnInitialUpdate(void)
{
	// Change style to have:
	//
	//	1.	Flat header (requires CJListCtrl)
	//	2.	Full row selection (requires ComCtl32.dll v4.71)
	//
	if (!m_bInitialised)
	{
		SubclassHeader();
		SetExtendedStyle(GetExtendedStyle() | LVS_EX_FULLROWSELECT);

		CRect rect;
		GetClientRect(rect);

		GetListCtrl().InsertColumn(0,
									_T("Project"),
									LVCFMT_LEFT,
									rect.Width(),
									-1);
		m_bInitialised = TRUE;
	}
	CResOrgAppProjectsView_BASE::OnInitialUpdate();
}


void CResOrgAppProjectsView::OnUpdate( CView* pSender, LPARAM lHint, CObject* pHint)
{
	UNREFERENCED_PARAMETER(pSender);
	UNREFERENCED_PARAMETER(pHint);

	switch (lHint)
	{
		case CLEAR_WORKSPACE:
			GetListCtrl().DeleteAllItems();
			GetListCtrl().EnableWindow(FALSE);
			Clear();
			break;

		case SHOW_WORKSPACE:
			GetListCtrl().DeleteAllItems();
			GetListCtrl().EnableWindow(TRUE);
			Clear();

			GetDocument()->GetProjects(m_arrayProjects);
			FillListCtrl();

			// If there's only one project, open its symbol
			// file automatically
			if (m_arrayProjects.GetSize() == 1)
			{
				CString sProject = m_arrayProjects[0];
				if (!sProject.IsEmpty())
				{
					OpenProject(sProject);
				}
			}
			break;


		default:
			Clear();

			GetDocument()->GetProjects(m_arrayProjects);
			GetListCtrl().EnableWindow( (m_arrayProjects.GetSize() > 0) );

			FillListCtrl();

			break;
	}
}	


void CResOrgAppProjectsView::OnDraw(CDC* /*pDC*/)
{
	CResOrgAppProjectsDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	// TODO: add draw code for native data here
}


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

	// Resort contents if sorted before
	if (m_nSortColumn >= 0)
	{
		CResOrgAppProjectsView_BASE::SortList(nColumn, bAscending);

		DWORD lParam = MAKELONG(m_nSortColumn, m_bSortAscending);

		GetListCtrl().SortItems(ListViewCompareProc, lParam);

		return true;
	}
	return false;
}


/////////////////////////////////////////////////////////////////////////////
// CResOrgAppProjectsView diagnostics

#ifdef _DEBUG
void CResOrgAppProjectsView::AssertValid(void) const
{
	CResOrgAppProjectsView_BASE::AssertValid();
}


void CResOrgAppProjectsView::Dump(CDumpContext& dc) const
{
	CResOrgAppProjectsView_BASE::Dump(dc);
}


CResOrgAppProjectsDoc* CResOrgAppProjectsView::GetDocument(void) // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CResOrgAppProjectsDoc)));

	return (CResOrgAppProjectsDoc*)m_pDocument;
}
#endif //_DEBUG


/////////////////////////////////////////////////////////////////////////////
// CResOrgAppProjectsView implementation

void CResOrgAppProjectsView::FillListCtrl(void)
{
	GetListCtrl().SetRedraw(FALSE);

	GetListCtrl().DeleteAllItems();

	CResOrgAppProjectsDoc* pDoc = GetDocument();

	if (NULL != pDoc)
	{
		int nItem = -1;

		for (int n = 0; n < m_arrayProjects.GetSize(); n++)
		{
			CString sProject = m_arrayProjects[n];

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

			GetListCtrl().SetItemData(nItem, (DWORD)&(m_arrayProjects[n]) );
		}
	}
	SortList(m_nSortColumn, m_bSortAscending);

	GetListCtrl().SetRedraw(TRUE);
}


void CResOrgAppProjectsView::Clear(void)
{
	m_arrayProjects.RemoveAll();
}


/******************************************************************************
 *	Static callback function for List Control sorting
 *
 *	The list control will then repeatedly call this to determine how to sort
 *	its data
 *
 ******************************************************************************/

int CALLBACK CResOrgAppProjectsView::ListViewCompareProc(	LPARAM lParam1,
															LPARAM lParam2,
															LPARAM lParamSort)
{
	CString* pItem1 = (CString*)lParam1;
	CString* pItem2 = (CString*)lParam2;

	int nResult = 0;		// Default => Equal

	if ( (NULL != pItem1) && (NULL != pItem2) )
	{
		int nColumn			= LOWORD(lParamSort);
		BOOL bSortAscending	= HIWORD(lParamSort);

		switch (nColumn)
		{
			case 0:
				{
					CString sItem1 = *pItem1;
					CString sItem2 = *pItem2;

					nResult = lstrcmpi(sItem1, sItem2);

					if ( (sItem1.IsEmpty()) || (sItem2.IsEmpty()) )
					{
						nResult = -nResult;			// Modify sort so a blank entry is HIGHER than one with something in it
					}
				}
				break;

			default:
				return 0;
	   	}
		if (!bSortAscending)
		{
			nResult = -nResult;			// Sneaky way to reverse sort order...
		}
	}
	return nResult;
}


CDocument* CResOrgAppProjectsView::OpenProject(const CString& sProject)
{
	CDocument* pDoc = NULL;

	// First, extract the rc file name by parsing the .dsp file
	CString sResourceFile = GetDocument()->GetResourceFileName(sProject);
	if (!sResourceFile.IsEmpty())
	{
		// Retrieve the name of the symbol file by parsing the rc file
		CString sSymbolFile = ::GetSymbolFileName(sResourceFile);
		if (!sSymbolFile.IsEmpty())
		{
			pDoc = GetDocument()->GetOpenDocument(sSymbolFile);
			if (NULL != pDoc)
			{
				// If the file is already open, just activate it
				GetDocument()->SetActiveDocument(pDoc);
			}
			else
			{
				// ...otherwise, we have to open it...
				//
				// To Do: convert to flash box
				//AfxMessageBox( "Displaying symbols for: " + sSymbolFile);

				pDoc = AfxGetApp()->OpenDocumentFile(sSymbolFile);

				ASSERT(NULL != pDoc);
			}
		}
		else
		{
			ASSERT(FALSE);		// Unable to identify symbol file
		}
	}
	return pDoc;
}


/////////////////////////////////////////////////////////////////////////////
// CResOrgAppProjectsView message handlers

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


//	Context Menu handler
void CResOrgAppProjectsView::OnContextMenu(CWnd* pWnd, CPoint point) 
{
	UNREFERENCED_PARAMETER(pWnd);

	// Make sure window is active
	GetParentFrame()->ActivateFrame();

	// Convert to client coordinates for hit testing
	// Note that TrackPopupMenu() expects its coordinates to be screen, not client!
	CPoint ptClient = point;
	ScreenToClient(&ptClient);

	UINT nFlags = 0;
	int nIndex = GetListCtrl().HitTest(ptClient, &nFlags);
	
	if (nIndex >= 0)
	{
		CCJMenu menu;
		if (menu.LoadMenu(IDM_PRJ_CONTEXT_MENU))
		{
			menu.LoadToolbar(IDM_PRJ_CONTEXT_MENU);

			CMenu* pPopup = menu.GetSubMenu(0);
			ASSERT(NULL != pPopup);

			pPopup->SetDefaultItem(ID_PROJ_OPEN);
			pPopup->TrackPopupMenu(TPM_RIGHTBUTTON | TPM_LEFTALIGN,
								   point.x,
								   point.y,
								   AfxGetMainWnd()); // route commands through main window
			return;
		}
	}
	Default();									// Default message handling if we didn't do anything
}


void CResOrgAppProjectsView::OnDblClick(NMHDR* /*pNMHDR*/, LRESULT* pResult) 
{
	*pResult = 0;

	OnCmdOpenProject();
}


void CResOrgAppProjectsView::OnCmdOpenProject(void)
{
	if (GetListCtrl().GetSelectedCount() > 0)
	{
		CResOrgAppProjectsDoc* pDoc = GetDocument();
		ASSERT_VALID(pDoc);

		if (NULL != pDoc)
		{
			POSITION pos = GetListCtrl().GetFirstSelectedItemPosition();
			while (pos != NULL)
			{
				int nItem = GetListCtrl().GetNextSelectedItem(pos);
				if (nItem >= 0)
				{
					CString sProject = GetListCtrl().GetItemText(nItem, 0);

					if (NULL == OpenProject(sProject) )
					{
						CString sMsg;
						sMsg.Format(IDP_PRJ_NO_SYM_FILE, sProject);

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


void CResOrgAppProjectsView::OnCmdRenumberProject(void)
{
	if (GetListCtrl().GetSelectedCount() > 0)
	{
		CResOrgAppProjectsDoc* pDoc = GetDocument();
		ASSERT_VALID(pDoc);

		if (NULL != pDoc)
		{
			POSITION pos = GetListCtrl().GetFirstSelectedItemPosition();
			while (pos != NULL)
			{
				int nItem = GetListCtrl().GetNextSelectedItem(pos);
				if (nItem >= 0)
				{
					CString sProject = GetListCtrl().GetItemText(nItem, 0);

					CResOrgSymbolsDoc* pDoc = dynamic_cast<CResOrgSymbolsDoc*>( OpenProject(sProject) );
					if (NULL != pDoc)
					{
						if (pDoc->GetSymbolBuffer()->GetSymbolCount() > 0)
						{
							AfxGetMainWnd()->PostMessage(WM_COMMAND, ID_TOOLS_RENUMBER);
						}
						else
						{
							AfxMessageBox(	_T("This file contains no symbols"),
											MB_OK | MB_ICONSTOP);
						}
					}
				}
			}
		}
	}
}


void CResOrgAppProjectsView::OnUpdateRenumberProject(CCmdUI* pCmdUI)
{
	pCmdUI->Enable( GetListCtrl().GetSelectedCount() == 1);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -