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

📄 ngdlgcontrols.cpp

📁 ResOrg 图形化管理Vc项目的资源ID的工具的源代码。 ResOrg - Manage and Renumber Resource Symbol IDs Introduction The
💻 CPP
字号:
// DlgControls.cpp : implementation file
//

#include "stdafx.h"

#include "NGUtils.h"
#include "NGDlgControls.h"


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


/////////////////////////////////////////////////////////////////////////////
// Combo Box functions
//

/*****************************************************************************
 *	Reload the contents (but not selection) of a combo box
 *
 *	NOTE: These are non-exported implementation functions
 *
 *****************************************************************************/

CComboBox* SetComboBoxChoices(CWnd* pWnd, LPCSTR pszChoices, LPCTSTR pszDelimiter)
{
    CComboBox* pCtrl = (CComboBox*)pWnd;
    if (NULL != pCtrl)
	{
		pCtrl->ResetContent();
		CString sChoices(pszChoices);
		CString sChoice;
		do
		{
			sChoice = Chomp(sChoices, pszDelimiter);// Consumes sChoices in the process
			if (!sChoice.IsEmpty())
				pCtrl->AddString(sChoice);			// Add current choice names

		} while (!sChoice.IsEmpty());
	}
	return pCtrl;
}


CComboBox* SetComboBoxChoices(CWnd* pWnd, const CStringList& listChoices)
{
    CComboBox* pCtrl = (CComboBox*)pWnd;
    if (NULL != pCtrl)
	{
		pCtrl->ResetContent();
		if (!listChoices.IsEmpty() )
		{
			for (int n = 0; n < listChoices.GetCount(); n++)
			{
				pCtrl->AddString( listChoices.GetAt(listChoices.FindIndex(n)) );
			}
		}
	}
	return pCtrl;
}


CComboBox* SetComboBoxChoices(CWnd* pWnd, const CStringArray& arrayChoices)
{
    CComboBox* pCtrl = (CComboBox*)pWnd;
    if (NULL != pCtrl)
	{
		pCtrl->ResetContent();

		for (int n = 0; n < arrayChoices.GetSize(); n++)
		{
			pCtrl->AddString( arrayChoices[n] );
		}
	}
	return pCtrl;
}


/*****************************************************************************
 *	Replace one string in a combo box with another
 *	If the deleted string was the current selection, its replacement
 *	remains selected.
 *
 *****************************************************************************/

NGLIB_EXT_API CComboBox* ReplaceComboBoxString(CWnd* pWnd, LPCTSTR pszTarget, LPCTSTR pszReplacement)
{
    CComboBox* pCtrl = (CComboBox*)pWnd;
    if (NULL != pCtrl)
	{
		int nIndex = pCtrl->FindString(0, pszTarget);
		if (CB_ERR != nIndex)					// Entry found...
		{
			int nCurSel = pCtrl->GetCurSel();
			pCtrl->DeleteString(nIndex);
			pCtrl->InsertString(nIndex, pszReplacement);
			if (CB_ERR != nCurSel)
				pCtrl->SetCurSel(nCurSel);		// Set selection if necessary
		}
	}
	return pCtrl;
}


/*****************************************************************************
 *	Reload the contents and selection of a combo box
 *
 *	NOTE:
 *		These functions which take an intenger selection should be used
 *		with UNSORTED combo boxes only!
 *
 *****************************************************************************/

NGLIB_EXT_API CComboBox* FillComboBox(	CWnd* pWnd,
										const CStringList& listChoices,
										LPCTSTR pszSelection)
{
	CComboBox* pCtrl = SetComboBoxChoices(pWnd, listChoices);

	if ((NULL != pCtrl) && (!listChoices.IsEmpty()) )
	{
		pCtrl->SelectString(-1, pszSelection);	// Try to restore the original selection
	}
	return pCtrl;
}


NGLIB_EXT_API CComboBox* FillComboBox(	CWnd* pWnd,
										const CStringList& listChoices,
										int nSelection)
{
	CComboBox* pCtrl = SetComboBoxChoices(pWnd, listChoices);
	if ( (NULL != pCtrl) && (!listChoices.IsEmpty()) )
	{
		pCtrl->SetCurSel(nSelection);			// Try to restore the original selection
	}
    return pCtrl;
}


NGLIB_EXT_API CComboBox* FillComboBox(	CWnd* pWnd,
										const CStringArray& arrayChoices,
										LPCTSTR pszSelection)
{
	CComboBox* pCtrl = SetComboBoxChoices(pWnd, arrayChoices);

	if ((NULL != pCtrl) && (arrayChoices.GetSize() > 0) )
	{
		pCtrl->SelectString(-1, pszSelection);	// Try to restore the original selection
	}
	return pCtrl;
}


NGLIB_EXT_API CComboBox* FillComboBox(	CWnd* pWnd,
										const CStringArray& arrayChoices,
										int nSelection)
{
	CComboBox* pCtrl = SetComboBoxChoices(pWnd, arrayChoices);
	if ( (NULL != pCtrl) && (arrayChoices.GetSize() > 0) )
	{
		pCtrl->SetCurSel(nSelection);			// Try to restore the original selection
	}
    return pCtrl;
}


NGLIB_EXT_API CComboBox* FillComboBox(	CWnd* pWnd,
										LPCTSTR pszChoices,
										LPCTSTR pszSelection,
										LPCTSTR pszDelimiter /*= "\t"*/)
{
	CComboBox* pCtrl = SetComboBoxChoices(pWnd, pszChoices, pszDelimiter);
	if (NULL != pCtrl)
		pCtrl->SelectString(-1, pszSelection);	// Try to restore the original selection

	return pCtrl;
}


NGLIB_EXT_API CComboBox* FillComboBox(	CWnd* pWnd,
										LPCTSTR pszChoices,
										int nSelection,
										LPCTSTR pszDelimiter /*= "\t"*/)
{
	CComboBox* pCtrl = SetComboBoxChoices(pWnd, pszChoices, pszDelimiter);
	if (NULL != pCtrl)
		pCtrl->SetCurSel(nSelection);			// Try to restore the original selection

	return pCtrl;
}


NGLIB_EXT_API CComboBox* FillComboBox(	CWnd* pWnd,
										int nChoiceID,
										LPCTSTR pszSelection,
										LPCTSTR pszDelimiter /* = "\t" */)
{
	if (NULL != pWnd)
	{		
		CString sChoices;
		sChoices.LoadString(nChoiceID);
		return FillComboBox(pWnd, sChoices, pszSelection, pszDelimiter);
	}
	return NULL;
}


NGLIB_EXT_API CComboBox* FillComboBox(	CWnd* pWnd,
										int nChoiceID,
										int nSelection,
										LPCTSTR pszDelimiter /*= "\t"*/)
{
	if (NULL != pWnd)
	{		
		CString sChoices;
		sChoices.LoadString(nChoiceID);
		return FillComboBox(pWnd, sChoices, nSelection, pszDelimiter);
	}
	return NULL;
}


/////////////////////////////////////////////////////////////////////////////
// List Box functions
//

/*****************************************************************************
 *	Reload the contents (but not selection) of a List box
 *
 *	NOTE: These are non-exported implementation functions
 *
 *****************************************************************************/

CListBox* SetListBoxChoices(CWnd* pWnd, LPCSTR pszChoices, LPCTSTR pszDelimiter)
{
    CListBox* pCtrl = (CListBox*)pWnd;
    if (NULL != pCtrl)
	{
		pCtrl->ResetContent();
		CString sChoices(pszChoices);
		CString sChoice;
		do
		{
			sChoice = Chomp(sChoices, pszDelimiter);// Consumes sChoices in the process
			if (!sChoice.IsEmpty())
				pCtrl->AddString(sChoice);			// Add current choice names

		} while (!sChoice.IsEmpty());
	}
	return pCtrl;
}


CListBox* SetListBoxChoices(CWnd* pWnd, const CStringList& listChoices)
{
    CListBox* pCtrl = (CListBox*)pWnd;
    if (NULL != pCtrl)
	{
		pCtrl->ResetContent();
		if (!listChoices.IsEmpty() )
		{
			for (int n = 0; n < listChoices.GetCount(); n++)
			{
				pCtrl->AddString( listChoices.GetAt(listChoices.FindIndex(n)) );
			}
		}
	}
	return pCtrl;
}


CListBox* SetListBoxChoices(CWnd* pWnd, const CStringArray& arrayChoices)
{
    CListBox* pCtrl = (CListBox*)pWnd;
    if (NULL != pCtrl)
	{
		pCtrl->ResetContent();

		for (int n = 0; n < arrayChoices.GetSize(); n++)
		{
			pCtrl->AddString( arrayChoices[n] );
		}
	}
	return pCtrl;
}


/*****************************************************************************
 *	Replace one string in a List box with another
 *	If the deleted string was the current selection, its replacement
 *	remains selected.
 *
 *****************************************************************************/

NGLIB_EXT_API CListBox* ReplaceListBoxString(CWnd* pWnd, LPCTSTR pszTarget, LPCTSTR pszReplacement)
{
    CListBox* pCtrl = (CListBox*)pWnd;
    if (NULL != pCtrl)
	{
		int nIndex = pCtrl->FindString(0, pszTarget);
		if (CB_ERR != nIndex)					// Entry found...
		{
			int nCurSel = pCtrl->GetCurSel();
			pCtrl->DeleteString(nIndex);
			pCtrl->InsertString(nIndex, pszReplacement);
			if (CB_ERR != nCurSel)
				pCtrl->SetCurSel(nCurSel);		// Set selection if necessary
		}
	}
	return pCtrl;
}


/*****************************************************************************
 *	Reload the contents and selection of a List box
 *
 *	NOTE:
 *		These functions which take an intenger selection should be used
 *		with UNSORTED List boxes only!
 *
 *****************************************************************************/

NGLIB_EXT_API CListBox* FillListBox(	CWnd* pWnd,
										const CStringList& listChoices,
										LPCTSTR pszSelection)
{
	CListBox* pCtrl = SetListBoxChoices(pWnd, listChoices);
	if ((NULL != pCtrl) && (!listChoices.IsEmpty()) )
		pCtrl->SelectString(-1, pszSelection);	// Try to restore the original selection

	return pCtrl;
}


NGLIB_EXT_API CListBox* FillListBox(	CWnd* pWnd,
										const CStringList& listChoices,
										int nSelection)
{
	CListBox* pCtrl = SetListBoxChoices(pWnd, listChoices);
	if ( (NULL != pCtrl) && (!listChoices.IsEmpty()) )
		pCtrl->SetCurSel(nSelection);			// Try to restore the original selection

    return pCtrl;
}

NGLIB_EXT_API CListBox* FillListBox(	CWnd* pWnd,
										const CStringArray& arrayChoices,
										LPCTSTR pszSelection)
{
	CListBox* pCtrl = SetListBoxChoices(pWnd, arrayChoices);
	if ((NULL != pCtrl) && (arrayChoices.GetSize() > 0) )
		pCtrl->SelectString(-1, pszSelection);	// Try to restore the original selection

	return pCtrl;
}


NGLIB_EXT_API CListBox* FillListBox(	CWnd* pWnd,
										const CStringArray& arrayChoices,
										int nSelection)
{
	CListBox* pCtrl = SetListBoxChoices(pWnd, arrayChoices);
	if ((NULL != pCtrl) && (arrayChoices.GetSize() > 0) )
		pCtrl->SetCurSel(nSelection);			// Try to restore the original selection

    return pCtrl;
}


NGLIB_EXT_API CListBox* FillListBox(	CWnd* pWnd,
										LPCTSTR pszChoices,
										LPCTSTR pszSelection,
										LPCTSTR pszDelimiter /*= "\t"*/)
{
	CListBox* pCtrl = SetListBoxChoices(pWnd, pszChoices, pszDelimiter);
	if (NULL != pCtrl)
		pCtrl->SelectString(-1, pszSelection);	// Try to restore the original selection

	return pCtrl;
}


NGLIB_EXT_API CListBox* FillListBox(	CWnd* pWnd,
										LPCTSTR pszChoices,
										int nSelection,
										LPCTSTR pszDelimiter /*= "\t"*/)
{
	CListBox* pCtrl = SetListBoxChoices(pWnd, pszChoices, pszDelimiter);
	if (NULL != pCtrl)
		pCtrl->SetCurSel(nSelection);			// Try to restore the original selection

	return pCtrl;
}


NGLIB_EXT_API CListBox* FillListBox(	CWnd* pWnd,
										int nChoiceID,
										LPCTSTR pszSelection,
										LPCTSTR pszDelimiter /* = "\t" */)
{
	if (NULL != pWnd)
	{		
		CString sChoices;
		sChoices.LoadString(nChoiceID);
		return FillListBox(pWnd, sChoices, pszSelection, pszDelimiter);
	}
	return NULL;
}


NGLIB_EXT_API CListBox* FillListBox(	CWnd* pWnd,
										int nChoiceID,
										int nSelection,
										LPCTSTR pszDelimiter /*= "\t"*/)
{
	if (NULL != pWnd)
	{		
		CString sChoices;
		sChoices.LoadString(nChoiceID);
		return FillListBox(pWnd, sChoices, nSelection, pszDelimiter);
	}
	return NULL;
}

⌨️ 快捷键说明

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