예제 #1
0
BOOL CComboBoxEx2::SelectItemDataStringA(LPCSTR pszText)
{
	CComboBox* pctrlCB = GetComboBoxCtrl();
	if (pctrlCB != NULL)
	{
		int iCount = pctrlCB->GetCount();
		for (int i = 0; i < iCount; i++)
		{
			void* pvItemData = GetItemDataPtr(i);
			if (pvItemData && strcmp((LPCSTR)pvItemData, pszText) == 0)
			{
				SetCurSel(i);
				GetParent()->SendMessage(WM_COMMAND, MAKELONG((WORD)GetWindowLong(m_hWnd, GWL_ID), CBN_SELCHANGE), (LPARAM)m_hWnd);
				return TRUE;
			}
		}
	}
	return FALSE;
}
예제 #2
0
BOOL CComboBoxEx2::SelectString(LPCTSTR pszText)
{
	// CComboBox::SelectString seems also not to work
	CComboBox* pctrlCB = GetComboBoxCtrl();
	if (pctrlCB != NULL)
	{
		int iCount = pctrlCB->GetCount();
		for (int i = 0; i < iCount; i++)
		{
			CString strItem;
			pctrlCB->GetLBText(i, strItem);
			if (strItem == pszText)
			{
				SetCurSel(i);
				GetParent()->SendMessage(WM_COMMAND, MAKELONG((WORD)GetWindowLong(m_hWnd, GWL_ID), CBN_SELCHANGE), (LPARAM)m_hWnd);
				return TRUE;
			}
		}
	}
	return FALSE;
}
예제 #3
0
BOOL CComboBoxEx2::PreTranslateMessage(MSG* pMsg)
{
	// there seems to be no way that we get the WM_CHARTOITEM for this control
	ASSERT( pMsg->message != WM_CHARTOITEM );

	if (pMsg->message == WM_KEYDOWN)
	{
		UINT uChar = MapVirtualKey(pMsg->wParam, 2);
		if (uChar != 0)
		{
			// CComboBox::SelectString seems also not to work
			CComboBox* pctrlCB = GetComboBoxCtrl();
			if (pctrlCB != NULL)
			{
				int iCount = pctrlCB->GetCount();
				for (int i = 0; i < iCount; i++)
				{
					CString strItem;
					pctrlCB->GetLBText(i, strItem);
					if (strItem.IsEmpty())
						continue;

					//those casts are indeed all(!) needed to get that thing (at least!) running correctly for ANSI code pages,
					//if that will also work for MBCS code pages has to be tested..
					UINT uFirstChar      = (UINT)(_TUCHAR)strItem[0];
					UINT uFirstCharLower = (UINT)(_TUCHAR)_totlower(uFirstChar);
					UINT uTheChar        = (UINT)(_TUCHAR)_totlower((UINT)uChar);
					if (uFirstCharLower == uTheChar){
						SetCurSel(i);
						GetParent()->SendMessage(WM_COMMAND, MAKELONG((WORD)GetWindowLong(m_hWnd, GWL_ID), CBN_SELCHANGE), (LPARAM)m_hWnd);
						return TRUE;
					}
				}
			}
		}
	}
	return CComboBoxEx::PreTranslateMessage(pMsg);
}