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

📄 configmgr.cpp

📁 Blood 2全套源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:

	AddConfig(fd.name);

	BOOL bContinue = TRUE;

	while (bContinue)
	{
		if (_findnext(hFile, &fd) != 0)
		{
			bContinue = FALSE;
		}
		else
		{
			AddConfig(fd.name);
		}
	}


	// Restore the directory...

	chdir ("..");


	// All done...

	return(TRUE);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CConfigMgr::FillListBox
//
//	PURPOSE:	Fills the given list box
//
// ----------------------------------------------------------------------- //

CConfig* CConfigMgr::AddConfig(char* sFilename)
{
	// Sanity checks...

	if (!sFilename) return(FALSE);
	if (sFilename[0] == '\0') return(FALSE);
	if (m_cConfigs >= CM_MAX_CONFIGS) return(NULL);


	// Init the next available config object...

	CConfig* pConfig = &m_aConfigs[m_cConfigs];

	if (!pConfig->Init(sFilename))
	{
		return(NULL);
	}


	// Increment the number of configs...

	m_cConfigs++;


	// All done...

	return(pConfig);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CConfigMgr::FillListBox
//
//	PURPOSE:	Fills the given list box
//
// ----------------------------------------------------------------------- //

BOOL CConfigMgr::FillListBox(HWND hList, char* sCurSel, char* sDefSel)
{
	// Sanity checks...

	if (!hList) return(FALSE);


	// Reset the contents of the list box...

	SendMessage(hList, LB_RESETCONTENT, 0, 0);


	// Add each config...

	for (int i = 0; i < m_cConfigs; i++)
	{
		CConfig* pConfig = GetConfig(i);
		if (pConfig)
		{
			SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)(LPCSTR)pConfig->GetDisplayName());
		}
	}


	// Set the current selection if requested...

	BOOL bSel = FALSE;

	if (sCurSel && sCurSel[0] != '\0')
	{
		char sCmp[128];
		_mbscpy((unsigned char*)sCmp, (const unsigned char*)sCurSel);
		int nLen = _mbstrlen(sCmp);
		if (nLen > 4) sCmp[nLen-4] = '\0';

		int count = SendMessage(hList, LB_GETCOUNT, 0, 0);
		if (count == LB_ERR) return(TRUE);

		for (int i = 0; i < count; i++)
		{
			char sText[128] = { "" };

			int nRet = SendMessage(hList, LB_GETTEXT, i, (LPARAM)sText);
			if (nRet != LB_ERR)
			{
				if (_mbsicmp((const unsigned char*)sText, (const unsigned char*)sCmp) == 0)
				{
					nRet = SendMessage(hList, LB_SETCURSEL, i, 0);
					if (nRet != LB_ERR) bSel = TRUE;
				}
			}
		}
	}

	if (!bSel && sDefSel && sDefSel[0] != '\0')
	{
		char sCmp[128];
		_mbscpy((unsigned char*)sCmp, (const unsigned char*)sDefSel);
		int nLen = _mbstrlen(sCmp);
		if (nLen > 4) sCmp[nLen-4] = '\0';

		int count = SendMessage(hList, LB_GETCOUNT, 0, 0);
		if (count == LB_ERR) return(TRUE);

		for (int i = 0; i < count; i++)
		{
			char sText[128] = { "" };

			int nRet = SendMessage(hList, LB_GETTEXT, i, (LPARAM)sText);
			if (nRet != LB_ERR)
			{
				if (_mbsicmp((const unsigned char*)sText, (const unsigned char*)sCmp) == 0)
				{
					nRet = SendMessage(hList, LB_SETCURSEL, i, 0);
				}
			}
		}
	}


	// All done...

	return(TRUE);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CConfigMgr::GetListBoxSelection
//
//	PURPOSE:	Gets the current selection from the given list box
//
// ----------------------------------------------------------------------- //

CConfig* CConfigMgr::GetListBoxSelection(HWND hList)
{
	// Sanity checks...

	if (!hList) return(NULL);


	// Get the currently select list-box item...

	int nIndex = SendMessage(hList, LB_GETCURSEL, 0, 0);
	if (nIndex == LB_ERR) return(NULL);


	// Get the text for this item...

	char sText[128] = { "" };

	int nRet = SendMessage(hList, LB_GETTEXT, nIndex, (LPARAM)sText);
	if (nRet == LB_ERR) return(NULL);


	// Find this item...

	return(GetConfigFromDisplay(sText));
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CConfigMgr::FillComboBox
//
//	PURPOSE:	Fills the given combo box
//
// ----------------------------------------------------------------------- //

BOOL CConfigMgr::FillComboBox(HWND hCombo, char* sCurSel, char* sDefSel)
{
	// Sanity checks...

	if (!hCombo) return(FALSE);


	// Reset the contents of the list box...

	SendMessage(hCombo, CB_RESETCONTENT, 0, 0);


	// Add each config...

	for (int i = 0; i < m_cConfigs; i++)
	{
		CConfig* pConfig = GetConfig(i);
		if (pConfig)
		{
			SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)pConfig->GetDisplayName());
		}
	}


	// Set the current selection if requested...

	BOOL bSel = FALSE;

	if (sCurSel && sCurSel[0] != '\0')
	{
		char sCmp[128];
		_mbscpy((unsigned char*)sCmp, (const unsigned char*)sCurSel);
		int nLen = _mbstrlen(sCmp);
		if (nLen > 4) sCmp[nLen-4] = '\0';

		int count = SendMessage(hCombo, CB_GETCOUNT, 0, 0);
		if (count == CB_ERR) return(TRUE);

		for (int i = 0; i < count; i++)
		{
			char sText[128] = { "" };

			int nRet = SendMessage(hCombo, CB_GETLBTEXT, i, (LPARAM)sText);
			if (nRet != CB_ERR)
			{
				if (_mbsicmp((const unsigned char*)sText, (const unsigned char*)sCmp) == 0)
				{
					nRet = SendMessage(hCombo, CB_SETCURSEL, i, 0);
					if (nRet != CB_ERR) bSel = TRUE;
				}
			}
		}
	}

	if (!bSel && sDefSel && sDefSel[0] != '\0')
	{
		char sCmp[128];
		_mbscpy((unsigned char*)sCmp, (const unsigned char*)sDefSel);
		int nLen = _mbstrlen(sCmp);
		if (nLen > 4) sCmp[nLen-4] = '\0';

		int count = SendMessage(hCombo, CB_GETCOUNT, 0, 0);
		if (count == CB_ERR) return(TRUE);

		for (int i = 0; i < count; i++)
		{
			char sText[128] = { "" };

			int nRet = SendMessage(hCombo, CB_GETLBTEXT, i, (LPARAM)sText);
			if (nRet != CB_ERR)
			{
				if (_mbsicmp((const unsigned char*)sText, (const unsigned char*)sCmp) == 0)
				{
					nRet = SendMessage(hCombo, CB_SETCURSEL, i, 0);
				}
			}
		}
	}


	// All done...

	return(TRUE);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CConfigMgr::GetComboBoxSelection
//
//	PURPOSE:	Gets the current selection from the given combo box
//
// ----------------------------------------------------------------------- //

CConfig* CConfigMgr::GetComboBoxSelection(HWND hCombo)
{
	// Sanity checks...

	if (!hCombo) return(NULL);


	// Get the currently select list-box item...

	int nIndex = SendMessage(hCombo, CB_GETCURSEL, 0, 0);
	if (nIndex == CB_ERR) return(NULL);


	// Get the text for this item...

	char sText[128] = { "" };

	int nRet = SendMessage(hCombo, CB_GETLBTEXT, nIndex, (LPARAM)sText);
	if (nRet == CB_ERR) return(NULL);


	// Find this item...

	return(GetConfigFromDisplay(sText));
}

⌨️ 快捷键说明

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