BOOL CEmoticons::LoadXML(LPCTSTR pszFile) { CString strPath, strValue; CXMLElement* pXML = CXMLElement::FromFile( pszFile, TRUE ); if ( pXML == NULL ) return FALSE; strPath = pszFile; int nSlash = strPath.ReverseFind( '\\' ); if ( nSlash >= 0 ) strPath = strPath.Left( nSlash + 1 ); CXMLElement* pBitmap = pXML->GetElementByName( _T("bitmap") ); if ( pBitmap == NULL ) { delete pXML; return FALSE; } strValue = pBitmap->GetAttributeValue( _T("file") ); nSlash = strValue.ReverseFind( '/' ); if ( nSlash >= 0 ) strValue = strValue.Mid( nSlash + 1 ); strValue = strPath + strValue; CImageFile pImage; if ( ! pImage.LoadFromFile( strValue ) || ! pImage.EnsureRGB( GetSysColor( COLOR_WINDOW ) ) || ! pImage.SwapRGB() ) { delete pXML; return FALSE; } COLORREF crBack = RGB( pImage.m_pImage[2], pImage.m_pImage[1], pImage.m_pImage[0] ); for ( POSITION pos = pXML->GetElementIterator() ; pos ; ) { CXMLElement* pEmoticon = pXML->GetNextElement( pos ); if ( ! pEmoticon->IsNamed( _T("emoticon") ) ) continue; CXMLElement* pSource = pEmoticon->GetElementByName( _T("source") ); CString strText = pEmoticon->GetAttributeValue( _T("text") ); CRect rc( 0, 0, 0, 0 ); strValue = pSource->GetAttributeValue( _T("left"), _T("0") ); _stscanf( strValue, _T("%i"), &rc.left ); strValue = pSource->GetAttributeValue( _T("top"), _T("0") ); _stscanf( strValue, _T("%i"), &rc.top ); strValue = pSource->GetAttributeValue( _T("right"), _T("0") ); _stscanf( strValue, _T("%i"), &rc.right ); strValue = pSource->GetAttributeValue( _T("bottom"), _T("0") ); _stscanf( strValue, _T("%i"), &rc.bottom ); BOOL bButton = pEmoticon->GetAttributeValue( _T("button") ).CompareNoCase( _T("yes") ) == 0; AddEmoticon( strText, &pImage, &rc, crBack, bButton ); } delete pXML; return TRUE; }