|
using System;
using System.IO;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace Vestris.ResourceLib
{
/// <summary>
/// A collection of menu items.
/// </summary>
public class MenuTemplateItemCollection : List<MenuTemplateItem>
{
/// <summary>
/// A collection of menu items.
/// </summary>
public MenuTemplateItemCollection()
{
}
/// <summary>
/// Read the menu item collection.
/// </summary>
/// <param name="lpRes">Address in memory.</param>
/// <returns>End of the menu item structure.</returns>
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;
}
/// <summary>
/// Write the menu collection to a binary stream.
/// </summary>
/// <param name="w">Binary stream.</param>
internal void Write(BinaryWriter w)
{
foreach (MenuTemplateItem menuItem in this)
{
menuItem.Write(w);
}
}
/// <summary>
/// String representation in the MENU format.
/// </summary>
/// <returns>String representation.</returns>
public override string ToString()
{
return ToString(0);
}
/// <summary>
/// String representation in the MENU format.
/// </summary>
/// <param name="indent">Indent.</param>
/// <returns>String representation.</returns>
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();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Daniel Doubrovkine has been in software engineering for twelve years and is currently development manager at Application Security Inc. in New York City. He has been involved in many software ventures, including Xo3 and Vestris Inc, was a development lead at Microsoft Corp. in Redmond, and director of Engineering at Visible Path Corp. in New York City. Daniel also builds and runs a foodie website, http://www.foodcandy.com.