Ejemplo n.º 1
0
extern "C" BOOL FAR PASCAL _export FillCountryComboBox(HWND hComboBox, WORD wSelectCountryId /*=0*/)
#endif
{
	BOOL fResult = FALSE;

	// Fill the specified combo box with the country names from the resource file.
	// The data for each item is set to the country ID number.

	CComboBox ComboBox;
	CString csCountry;

	TRY
	{
		ComboBox.Attach(hComboBox);

		ComboBox.SetRedraw(FALSE);

		if (wSelectCountryId == 0)
		{
			wSelectCountryId = ID_UnitedStatesOfAmerica;
		}

		int nSelectIndex = 0;

		int nCount = CCountryTableEntry::GetCountryTableEntryCount();
		for (int nCountry = 0; nCountry < nCount; nCountry++)
		{
			CCountryTableEntry* pCountry = CCountryTableEntry::GetCountryEntryByIndex(nCountry);
			if (pCountry != NULL)
			{
				csCountry.LoadString(pCountry->GetId());
				int nComboIndex = ComboBox.AddString(csCountry);
				if (nComboIndex != CB_ERR)
				{
					ComboBox.SetItemData(nComboIndex, (DWORD)(pCountry->GetId()));
					if (pCountry->GetId() == wSelectCountryId)
					{
						nSelectIndex = nComboIndex;
					}
				}
			}
		}

		if (nSelectIndex != 0)
		{
			ComboBox.SetCurSel(nSelectIndex);
		}

		ComboBox.SetRedraw(TRUE);
		ComboBox.Invalidate();

		ComboBox.Detach();

		fResult = TRUE;
	}
	CATCH_ALL(e)
	{
		if (ComboBox.m_hWnd != NULL)
		{
			ComboBox.SetRedraw(TRUE);
			ComboBox.Detach();
		}

		fResult = FALSE;
	}
	END_CATCH_ALL

	return fResult;
}