📄 maintoolwindowctrl.cpp
字号:
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);
DoDataExchange(true); // Update m_sResourceSymbolFile
// Force the dependent controls to update
OnCbnSelchangeResourceSymbolFile(0, 0, NULL);
return true; // A true return indicates that the selection has changed
}
return false; // The selection is unchanged
}
bool CMainToolWindowCtrl::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);
// Load the corresponding config file (if present) so that we have the right base values
if (Options.AutoSaveSymbolFileConfig() )
{
CString sConfigFilePathName = CResOrgXmlWriter::GetConfigFilePathName( pSymbols->GetPathName() );
CString sErrorMsg;
if (::FileExists(sConfigFilePathName) )
{
if (!CResOrgXmlWriter::LoadSymbolFileConfig(pSymbols,
sConfigFilePathName,
&sErrorMsg) )
{
#ifdef _DEBUG
CNGSplitPath split(sConfigFilePathName);
CString sMsg;
sMsg.Format(IDP_WARN_CONFIG_LOAD_FAILED,
split.GetFileName() + split.GetExtension(),
sErrorMsg);
::AfxMessageBox( sMsg, MB_OK | MB_ICONEXCLAMATION);
#endif
}
}
}
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 CMainToolWindowCtrl::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
}
DoDataExchange(false);
m_ctrlResourceRangeCaption.SetWindowText( _T("Resource / Control IDs:") );
m_ctrlCommandRangeCaption.SetWindowText( _T("Command IDs:") );
Invalidate(); // Force the HTML controls to repaint
return bResult;
}
#ifdef _RESORG_EXPIRY_DATE
void CMainToolWindowCtrl::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 CMainToolWindowCtrl::SetAvailableControls(void)
{
BOOL bAvailable = ( (NULL != m_pSymbols) && !m_sResourceSymbolFile.IsEmpty() );
m_ctrlProperties.EnableWindow(bAvailable);
m_ctrlEdit.EnableWindow(bAvailable);
m_ctrlRenumber.EnableWindow(bAvailable);
}
CString CMainToolWindowCtrl::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 CMainToolWindowCtrl::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;
}
BOOL CMainToolWindowCtrl::DDX_Text(UINT nID, CString& strText, int /*cbSize*/, BOOL bSave, BOOL bValidate /*= FALSE*/, int nLength /*= 0*/)
{
BOOL bSuccess = TRUE;
if(bSave)
{
HWND hWndCtrl = GetDlgItem(nID);
int nLen = ::GetWindowTextLength(hWndCtrl);
int nRetLen = -1;
LPTSTR lpstr = strText.GetBufferSetLength(nLen);
if(lpstr != NULL)
{
nRetLen = ::GetWindowText(hWndCtrl, lpstr, nLen + 1);
strText.ReleaseBuffer();
}
if(nRetLen < nLen)
bSuccess = FALSE;
}
else
{
bSuccess = SetDlgItemText(nID, strText);
}
if(!bSuccess)
{
OnDataExchangeError(nID, bSave);
}
else if(bSave && bValidate) // validation
{
ATLASSERT(nLength > 0);
if(strText.GetLength() > nLength)
{
_XData data = { ddxDataText };
data.textData.nLength = strText.GetLength();
data.textData.nMaxLength = nLength;
OnDataValidateError(nID, bSave, data);
bSuccess = FALSE;
}
}
return bSuccess;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -