示例#1
0
int CCJListCtrl::GetRegColumnWidth(int iColumn)
{
	ASSERT( m_strSection.GetLength() );
	ASSERT( m_strControl.GetLength() );
	
	CString strEntry( m_strControl );
	CString strValue, strSubString;

	strValue = AfxGetApp()->GetProfileString( m_strSection, strEntry, "" );
	AfxExtractSubString(strSubString, strValue, iColumn, ',');
	return atoi((char*)(LPCTSTR)strSubString);
}
/*
Utility function to look up a columns width in the registry.
If it returns -1 then it means that it was not found in the registry
*/
const int CMultiColumnSortListCtrl::GetRegColumnWidth( int iColumn ) const
{
	int nRes = -1;
	ASSERT( m_strUniqueName.GetLength() );	//You must set a unique name for every listctrl
	
	CString strEntry( m_strUniqueName );
	CString strValue, strSubString;
	CString strSection( m_strColumnWidthSection );
	strValue = AfxGetApp()->GetProfileString( strSection, strEntry, "" );
	AfxExtractSubString(strSubString, strValue, iColumn, ',');
	if( !strSubString.IsEmpty() )
	{
		nRes = atoi( (LPCTSTR)strSubString );
	}

	return nRes;
}
/*
This function loads the columns sort
To apply the changes you have to call SortCombinedColumns()
*/
int CMultiColumnSortListCtrl::LoadColumnSort()
{
	ASSERT( m_strUniqueName.GetLength() );	//You must set a unique name for every listctrl

	//set the colum order
	CString strEntry( m_strUniqueName );
	CString strValue, strSubString;
	CString strSection( m_strColumnSortSection );

	strValue = AfxGetApp()->GetProfileString( strSection, strEntry, "" );

	if( !strValue.IsEmpty() )
	{
		m_ctlHeaderCtrl.RemoveAllSortImages();
    	EmptyArray(m_aCombinedSortedColumns, -1);
	    m_lColumnSortStates = 0;

		int nIndex = 0;
		while( AfxExtractSubString(strSubString, strValue, nIndex, ',') )
		{
			//get the m_lColumnSortStates first
			if( !nIndex )
			{
				m_lColumnSortStates = atol( (LPCTSTR)strSubString );
				nIndex++;
				continue;
			}
			
			//get the other columns
			if( !strSubString.IsEmpty() )
			{
				m_aCombinedSortedColumns[nIndex-1] = atoi( (LPCTSTR)strSubString );
			}
			else
			{
				break;
			}
			
			//next please
			nIndex++;
		}
	}

	return 1;
}
/*
This function loads the columns order as the columns can be re-arranged with drag & drop
You should call it BEFORE you fill in the contents or it might not redraw properly
*/
int CMultiColumnSortListCtrl::LoadColumnOrder()
{
	ASSERT( m_strUniqueName.GetLength() );	//You must set a unique name for every listctrl

	int iNumColumns = GetColumnCount();

	//set the colum order
	CString strEntry( m_strUniqueName );
	CString strValue, strSubString;
	CString strSection( m_strColumnOrderSection );

	strValue = AfxGetApp()->GetProfileString( strSection, strEntry, "" );

	if( !strValue.IsEmpty() )
	{
		LPINT pnOrder = (LPINT)malloc(iNumColumns*sizeof(int));
		ASSERT(pnOrder != NULL);

		if( pnOrder )
		{
			for( int nIndex = 0; nIndex < iNumColumns; nIndex++ )
			{
				
				AfxExtractSubString(strSubString, strValue, nIndex, ',');
				if( !strSubString.IsEmpty() )
				{
					pnOrder[nIndex] = atoi( (LPCTSTR)strSubString );
				}
			}

			SetColumnOrderArray( iNumColumns, pnOrder );

			free(pnOrder);
		}
	}

	return 1;
}
void CSearchDialog::SaveEntry(int comboBoxId, boost::circular_buffer<std::wstring> &buffer)
{
	TCHAR entry[MAX_PATH];
	GetDlgItemText(m_hDlg, comboBoxId, entry, SIZEOF_ARRAY(entry));

	std::wstring strEntry(entry);
	auto itr = std::find_if(buffer.begin(), buffer.end(),
		[strEntry] (const std::wstring Pattern)
	{
		return Pattern.compare(strEntry) == 0;
	});

	HWND hComboBox = GetDlgItem(m_hDlg, comboBoxId);
	ComboBox_SetCurSel(hComboBox, -1);

	if(itr != buffer.end())
	{
		/* Remove the current element from both the list and the
		combo box. It will be reinserted at the front of both below. */
		auto index = std::distance(buffer.begin(), itr);
		SendMessage(hComboBox, CB_DELETESTRING, index, 0);

		buffer.erase(itr);
	}

	buffer.push_front(entry);

	SendMessage(hComboBox, CB_INSERTSTRING, 0, reinterpret_cast<LPARAM>(entry));
	ComboBox_SetCurSel(hComboBox, 0);
	ComboBox_SetEditSel(hComboBox, -1, -1);

	if(ComboBox_GetCount(hComboBox) > buffer.capacity())
	{
		SendMessage(hComboBox, CB_DELETESTRING, ComboBox_GetCount(hComboBox) - 1, 0);
	}
}
示例#6
0
#include "statscript.h"
#include "Strings.h"
#include "debug.h"

#define strEntry(var)  {#var,strSetStringCB,&MessageStrings[##var]}

udword strCurLanguage=0;
udword strCurKeyboardLanguage=0;
bool8  strInitialized=FALSE;
char  *MessageStrings[NumStrings];

char   crapMessage[]="*NO_STRING*";

scriptEntry LanguageStrings[] =
{
    strEntry(strAdvanceSupportFrigate),
    strEntry(strAttackBomber),
    strEntry(strCarrier),
    strEntry(strCloakedFighter),
    strEntry(strCloakGenerator),
    strEntry(strDDDFrigate),
    strEntry(strDefenseFighter),
    strEntry(strDFGFrigate),
    strEntry(strGravWellGenerator),
    strEntry(strHeavyCorvette),
    strEntry(strHeavyCruiser),
    strEntry(strHeavyDefender),
    strEntry(strHeavyInterceptor),
    strEntry(strIonCannonFrigate),
    strEntry(strLightCorvette),
    strEntry(strLightDefender),
/*
This function saves the columns widths of the listctrl to the registry.
This is called in two places, OnDestroy, and OnEndTrack in the headerCtrl class.
*/
void CMultiColumnSortListCtrl::SaveColumnSettings()
{
	//You must set a unique name for every listctrl
	ASSERT( m_strUniqueName.GetLength() );

	int nIndex;	//for the loops

	/*
	Save the widths
	*/
	CString strEntry( m_strUniqueName );
	CString strValue;

	int iNumColumns = GetColumnCount();
	for( nIndex = 0; nIndex < iNumColumns; nIndex++ )
	{
		CString strTemp;
		strTemp.Format( "%d,", GetColumnWidth(nIndex) );
		strValue += strTemp;
	}

	//write to the registry
	AfxGetApp()->WriteProfileString( m_strColumnWidthSection, strEntry, strValue );

	/*
	Save the column's order
	*/
	LPINT pnOrder = (LPINT)malloc(iNumColumns*sizeof(int));
	ASSERT(pnOrder != NULL);

	if( pnOrder )
	{
		GetColumnOrderArray(pnOrder, iNumColumns);
		
		CString strColumnOrder;
		
		for( nIndex = 0; nIndex < iNumColumns; nIndex++ )
		{
			CString strTemp;
			strTemp.Format( "%d,", pnOrder[nIndex] );
			strColumnOrder += strTemp;
		}
		
		//write to the registry
		AfxGetApp()->WriteProfileString( m_strColumnOrderSection, strEntry, strColumnOrder );

		free(pnOrder);
	}

	/*
	Save the sort order
	It saves the column numbers, it's negative if ASCENDING
	*/
	CString strColumnSort;
	int iNumCombinedSortedCols = GetNumCombinedSortedColumns();

	//store the m_lColumnSortStates first
	{
		CString strTemp;
		strTemp.Format( "%d,", m_lColumnSortStates );
		strColumnSort += strTemp;
	}

	//iterate the columns
	for( nIndex = 0; nIndex < iNumCombinedSortedCols; nIndex++ )
	{
		SORT_STATE ssEachItem = GetItemSortState( m_aCombinedSortedColumns[nIndex] );
		
		CString strTemp;
		strTemp.Format( "%d,", m_aCombinedSortedColumns[nIndex] );
		strColumnSort += strTemp;
	}

	//write to the registry
	AfxGetApp()->WriteProfileString( m_strColumnSortSection, strEntry, strColumnSort );
}
示例#8
0
void CPlayerView::AddToPlayList( const CString& strFileName ) 
{
	CString strExt( strFileName );
	CString strDir( strFileName );
	CString strCurrentDir;

	int nPos;

	nPos = strExt.ReverseFind( '.' );

	if ( nPos > 0 ) 
	{
		strExt = strExt.Mid( nPos + 1 );
	}


	nPos = strDir.ReverseFind( _T( '\\' ) );

	if ( nPos > 0 ) 
	{
		strDir = strDir.Left( nPos );
	}
	

	char lpszCurDir[ MAX_PATH + 1 ] = {'\0',};
	
	// Get current directory
	_getcwd( lpszCurDir, sizeof( lpszCurDir ) );

	if ( 0 == strExt.CompareNoCase( _T( "M3U" ) ) )
	{
		// go to the directory
		if ( 0 == _tchdir( strDir ) )
		{
			// open the playlist
			FILE* pFile = CDexOpenFile( CUString( strFileName ), _W( "rt" ) );

			if ( NULL != pFile )
			{
				char lpszLine[ 8192 ] = {'\0',};

				// read the lines in the playlist file
				while ( NULL != fgets( lpszLine, sizeof( lpszLine ), pFile ) )
				{
					if ( '\n' == lpszLine[ strlen( lpszLine ) -1 ] )
					{
						lpszLine[ strlen( lpszLine ) -1 ] = '\0';
					}

					// skip extended info
					if ( '#' != lpszLine[0] )
					{
						CString strEntry( lpszLine );

						int nPos = 0;

						if ( strDir.Find( _T( ":\\" ) ) < 0 ) 
						{
							if ( 0 == ( nPos = strEntry.Find( _T( ".\\" ) ) ) )
							{
								strEntry = strDir + strEntry.Mid( 1 );
							}
							else
							{
								strEntry = strDir + _T( "\\" ) + strEntry;
							}
						}

						AddStringToPlayList( strEntry );
					}
				}

				// close the playlist file
				fclose( pFile );
			}
		}

	}
	else if ( 0 == strExt.CompareNoCase( _T( "PLS" ) ) )
	{
		CIni	plsIni;
		int		nNumEntries = 0;
		CString	strEntry;
		CString	strNumber;
		int		i = 0;
		

		// go to the directory
		if ( 0 == _tchdir( strDir ) )
		{

			plsIni.SetIniFileName( CUString( strFileName ) );

			nNumEntries = plsIni.GetValue(	_T( "playlist" ),
											_T( "NumberOfEntries" ), 
											nNumEntries );

			for ( i = 1; i <= nNumEntries; i++ )
			{
				strNumber.Format( _T( "File%d"), i );

				strEntry = plsIni.GetValue( CUString( _W( "playlist" ) ),
											CUString( strNumber ),
											_W( "" ) );


				if ( !strEntry.IsEmpty() )
				{

					int nPos = 0;

					if ( strDir.Find( _T( ":\\" ) ) < 0 ) 
					{
						if ( 0 == ( nPos = strEntry.Find( _T( ".\\" ) ) ) )
						{
							strEntry = strDir + strEntry.Mid( 1 );
						}
						else
						{
							strEntry = strDir + _T( "\\" ) + strEntry;
						}
					}
					AddStringToPlayList( strEntry );
				}
			}
		}
	}
	else
	{
		AddStringToPlayList( strFileName );
	}

	// switch back to the current directory
	chdir( lpszCurDir );

}