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

📄 resorgnetaddintoolwinformview.cpp

📁 ResOrg 图形化管理Vc项目的资源ID的工具的源代码。 ResOrg - Manage and Renumber Resource Symbol IDs Introduction The
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		{
			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;
}

⌨️ 快捷键说明

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