示例#1
0
//查找线程处理函数
DWORD WINAPI CDlgFormulaFind::FindComp(LPVOID pParameter)
{
	CDlgFormulaFind* pCompFind = (CDlgFormulaFind*)(pParameter);
	if( pCompFind == NULL)
		return 0;

	CWnd* pWnd = pCompFind->GetDlgItem(IDC_STARTBUTTON);
	if(pWnd != NULL)
	{
		pWnd->EnableWindow(false);
	}
	pWnd = pCompFind->GetDlgItem(IDC_STOPBUT);
	if(pWnd != NULL)
	{
		pWnd->EnableWindow(true);
	}

	pCompFind->m_wndAnimate.Play(0,-1,-1);
	CString strKey ;
	pCompFind->m_wndKeyCombo.GetWindowText(strKey);
	strKey.MakeUpper();
//	DWORD dwFindMask = pCompFind->GetFindMask();
	DWORD dwFindMask = pCompFind->m_nFindMask;
	if( dwFindMask == 0 ) 
		return 0;
	
	CListCtrl* pListCtrl = &(pCompFind->m_wndResultList);
	if( pListCtrl == NULL)
		return 0;

	pListCtrl->DeleteAllItems();
	CMapVariabile* pVarsMap = CDlgFormulaMan::m_pExternExpression;
	if(pVarsMap != NULL)
	{
		POSITION pos = pVarsMap->GetStartPosition();
		pWnd = pCompFind->GetDlgItem(IDC_RESULTSTATIC);

		CString sName;
		CValue *pVal;
		while (pos != NULL && pCompFind->m_bThreadRun)
		{			
			pVarsMap->GetNextAssoc (pos, sName, pVal);

			if(pVal != NULL)
			{
				if( pVal->IsStyle(HX_EXPRESSSENTENCE) )
				{
					CString strFindText = _T("正在查找 --");
					strFindText +=  ((CExpValue*)pVal)->GetWholeName();
					pWnd->SetWindowText( strFindText);
					CString strRet;
					if( ((CExpValue*)pVal)->Find(strKey,strRet,dwFindMask) )
					{

						int nCount = pListCtrl->GetItemCount();
						CString strText;
						strText.Format(TEXT("%d"), nCount+1);

						// Insert the item, select every other item.
						CExpression* pExpression = ((CExpValue*)pVal)->GetExp();
						if(pExpression )
						{
							DWORD dwMask = (DWORD)pExpression->GetExpressType();
							dwMask &= 0xf;
							if ((pCompFind->m_dwMask & dwMask) == 0)
							{
								continue;
							}

							pListCtrl->InsertItem(
								LVIF_TEXT|LVIF_STATE, nCount, strText, 
								(nCount%2)==0 ? LVIS_SELECTED : 0, LVIS_SELECTED,
								0, 0);
							pListCtrl->SetItemData(nCount,(DWORD)pExpression);

							int nNameIndex = strRet.Find(_T("公式全名"));
							int nDescrible = strRet.Find(_T("公式描述"));
							if( nDescrible - nNameIndex != 8)
							{
								CString strDescrible = strRet.Mid(
									nNameIndex+8,nDescrible-nNameIndex-8);
								pListCtrl->SetItemText(nCount, 2,  strDescrible);
							}

							CString strWholeName = strRet.Left(nNameIndex);
							pListCtrl->SetItemText(nCount, 1, strWholeName.Mid(1,nNameIndex));

							CString strGroup;
							switch( dwMask )
							{
							case Tech :
								{
									strGroup = CTreeCtrlFormula::g_strTech;
									break;
								}
							case Exchange :
								{

									strGroup = CTreeCtrlFormula::g_strExchange;
									break;
								}
							case Condition :
								{
									strGroup = CTreeCtrlFormula::g_strCondition;
									break;
								}
							case MoreKLine :
								{
									strGroup = CTreeCtrlFormula::g_strColorKLine;
									break;
								}
							case Strategy : //20090302 YJT 增加 Strategy
								{
									strGroup = CTreeCtrlFormula::g_strStrategy;
									break;
								}
							default :
								{
									return 0;
								}
							}

							pListCtrl->SetItemText(nCount, 3, strGroup);
						}
					}
				}		
			}
		}

		CString strFindText ;
		strFindText.Format(_T("找到 %d 个对象"),pListCtrl->GetItemCount());
		pWnd->SetWindowText( strFindText);
		pWnd = pCompFind->GetDlgItem(IDC_STARTBUTTON);

		if(pWnd != NULL)
		{
			pWnd->EnableWindow(true);
		}
		pWnd = pCompFind->GetDlgItem(IDC_STOPBUT);
		if(pWnd != NULL)
		{
			pWnd->EnableWindow(false);
		}
		pCompFind->m_wndAnimate.Stop();

	}
	return 0;
}