using System; using System.IO; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text; namespace Vestris.ResourceLib { /// /// A collection of menu items. /// public class MenuTemplateItemCollection : List { /// /// A collection of menu items. /// public MenuTemplateItemCollection() { } /// /// Read the menu item collection. /// /// Address in memory. /// End of the menu item structure. internal IntPtr Read(IntPtr lpRes) { while(true) { User32.MENUITEMTEMPLATE childItem = (User32.MENUITEMTEMPLATE)Marshal.PtrToStructure( lpRes, typeof(User32.MENUITEMTEMPLATE)); MenuTemplateItem childMenu = null; if ((childItem.mtOption & (uint)User32.MenuFlags.MF_POPUP) > 0) childMenu = new MenuTemplateItemPopup(); else childMenu = new MenuTemplateItemCommand(); lpRes = childMenu.Read(lpRes); Add(childMenu); if ((childItem.mtOption & (uint)User32.MenuFlags.MF_END) != 0) break; } return lpRes; } /// /// Write the menu collection to a binary stream. /// /// Binary stream. internal void Write(BinaryWriter w) { foreach (MenuTemplateItem menuItem in this) { menuItem.Write(w); } } /// /// String representation in the MENU format. /// /// String representation. public override string ToString() { return ToString(0); } /// /// String representation in the MENU format. /// /// Indent. /// String representation. public string ToString(int indent) { StringBuilder sb = new StringBuilder(); if (Count > 0) { sb.AppendLine(string.Format("{0}BEGIN", new String(' ', indent))); foreach (MenuTemplateItem child in this) { sb.Append(child.ToString(indent + 1)); } sb.AppendLine(string.Format("{0}END", new String(' ', indent))); } return sb.ToString(); } } }