bool CResMenu::Load(CTextFile &file) { int level = 0; CString buffer;//next line CString line; CAtlArray<CString> Words; while(!file.Eof()) { CString word; if (buffer.IsEmpty()) { file.ReadLine(line); } else { line = buffer; buffer.Empty(); } CutString(line, Words); if (Words[0] == _T("BEGIN")) { continue; } if (Words[0] == _T("END")) { return true; } if (Words[0] == _T("POPUP")) { CResMenu SubMenu; SubMenu.m_String = Words[1]; if (!SubMenu.Load(file)) return false; m_SubMenus.Add(SubMenu); } if (Words[0] == _T("MENUITEM")) { file.ReadLine(buffer); buffer.TrimLeft(); buffer.TrimRight(); while (_tcsncmp(buffer, _T("MENUITEM"), 8) && _tcsncmp(buffer, _T("POPUP"), 5) && _tcsncmp(buffer, _T("BEGIN"), 5) && _tcsncmp(buffer, _T("END"), 3)) { // line += _T(" ") + buffer; CutString(line, Words); file.ReadLine(buffer); buffer.TrimLeft(); buffer.TrimRight(); } ResMenuItem newitem; if (Words.GetCount() > 1) { newitem.m_String = Words[1]; if (newitem.m_String == _T("SEPARATOR") && Words.GetCount() == 2) { } else { newitem.m_String.Replace(_T("\"\""), _T("\"")); newitem.m_ID = Words[2]; if (Words.GetCount() > 3) { newitem.m_Style = Words[3]; } } } m_vItems.Add(newitem); } } return false; }
bool CResources::Load(LPCTSTR filename, bool bAppend /* = false */) { CTextFile file; if (!bAppend) { m_Dialogs.RemoveAll(); m_Menus.RemoveAll(); m_Toolbars.RemoveAll(); m_Accels.RemoveAll(); m_Icons.RemoveAll(); m_Bitmaps.RemoveAll(); m_Cursors.RemoveAll(); } if(!file.Open(filename)) { return false; } while(!file.Eof()) { CString line; file.ReadLine(line); if (line.IsEmpty()) continue; line.TrimLeft(); if (line.GetLength() >= 2 && line[0] == _T('/') && line[1] == _T('/')) continue; if (line[0] == _T('#')) continue; CAtlArray<CString> Words; CutString(line, Words); { CString word; if (Words.GetCount() > 1) { word = Words[1]; } else { word.Empty(); } if (word == _T("DESIGNINFO")) { //skip disign info while(!file.Eof()) { file.ReadLine(line); line.Trim(); if (line == _T("BEGIN")) break; } if (file.Eof()) return false; int Level = 1; while(!file.Eof() && Level) { file.ReadLine(line); line.Trim(); if (line == _T("BEGIN")) Level++; if (line == _T("END")) Level--; } if (Level) return false; else continue; } if(word == _T("MENU")) { CResMenu newmenu; newmenu.m_ID = Words[0]; newmenu.Load(file); m_Menus.Add(newmenu); } else if( word == _T("TOOLBAR") ) { CResToolbar newtoolbar; newtoolbar.m_ID = Words[0]; newtoolbar.Load(file); m_Toolbars.Add(newtoolbar); } else if( (word == _T("DIALOG")) || word == _T("DIALOGEX") ) { CResDialog newdialog; newdialog.m_ID = Words[0]; newdialog.m_Type = word; newdialog.Load(file); m_Dialogs.Add(newdialog); } else if( word == _T("BITMAP") || word == _T("ICON") || word == _T("CURSOR") ) { ResBinary m_simple; m_simple.m_ID = Words[0]; if(word == _T("BITMAP")) m_Bitmaps.Add(m_simple); else if(word == _T("ICON")) m_Icons.Add(m_simple); else m_Cursors.Add(m_simple); } else if(word == _T("ACCELERATORS")) { CResAccelerators accels; accels.m_ID = Words[0]; accels.Load(file); m_Accels.Add(accels); } else { if(Words.GetCount() > 0 && (Words[0] == _T("STRINGTABLE"))) { LoadString(file); } } } } return true; }