找到图上某个文字
C++开发|大少爷|2017-07-27 11:43
-
回答:
void CTestOcxForVc6Dlg::FindText(CString sText) { MxDrawXLib::IMxDrawSelectionSetPtr ssGet; ssGet.CreateInstance(__uuidof( MxDrawXLib::MxDrawSelectionSet )); if(ssGet == NULL) { return; } ssGet->Select(MxDrawXLib::mcSelectionSetAll); if(ssGet->GetCount() == 0) return; for(long i = 0; i < ssGet->GetCount();i++) { MxDrawXLib::IMxDrawEntityPtr spEnt = ssGet->Item(i); if(spEnt == NULL) continue; CComPtr<IMxDrawText> spText; spEnt->QueryInterface(&spText); CComPtr<IMxDrawMText> spMText; spEnt->QueryInterface(&spMText); if(spText != NULL) { // 是一个文字. CString sVal; _bstr_t sBstr= spText->GetTextString(); sVal= CString(LPCTSTR(sBstr) ); if(sVal.Find(sText) != -1) { // 找到要找的文字. m_ocx.TwinkeEnt(spEnt->ObjectID); return; } } else if(spMText != NULL) { // 是个多行文字. CString sVal; _bstr_t sBstr = spMText->GetContents(); sVal= CString(LPCTSTR(sBstr) ); if(sVal.Find(sText) != -1) { // 找到要找的文字. m_ocx.TwinkeEnt(spEnt->ObjectID); return; } } } }