Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

File Resource Management Library (.NET)

, 16 Sep 2009
A .NET implementation of a file resource management, with complete support for VS_VERSIONINFO version resources.
vestris.resourcelib.1.2.zip
Vestris.ResourceLib
1.2
ResourceLib.chm
Article
Bin
Release
Vestris.ResourceLib.dll
Source
ResourceLib.proj
Version.proj
Common
ResourceLib
Properties
ResourceLibUnitTests
Properties
Vestris.ResourceLib.zip
1.0
Article
Bin
nunit.framework.dll
Vestris.ResourceLib.dll
Vestris.ResourceLibUnitTests.dll
Source
Common
ResourceLib.proj
ResourceLib
Properties
ResourceLibUnitTests
Properties
using System;
using System.IO;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace Vestris.ResourceLib
{
    /// <summary>
    /// A command menu item.
    /// </summary>
    public class MenuTemplateItemCommand : MenuTemplateItem
    {
        private UInt16 _menuId = 0;

        /// <summary>
        /// Command menu id.
        /// </summary>
        public UInt16 MenuId
        {
            get
            {
                return _menuId;
            }
            set
            {
                _menuId = value;
            }
        }

        /// <summary>
        /// A command menu item.
        /// </summary>
        public MenuTemplateItemCommand()
        {

        }

        /// <summary>
        /// Read a command menu item.
        /// </summary>
        /// <param name="lpRes">Address in memory.</param>
        /// <returns>End of the menu item structure.</returns>
        internal override IntPtr Read(IntPtr lpRes)
        {
            _header = (User32.MENUITEMTEMPLATE)Marshal.PtrToStructure(
                lpRes, typeof(User32.MENUITEMTEMPLATE));

            lpRes = new IntPtr(lpRes.ToInt32() + Marshal.SizeOf(_header));

            _menuId = (UInt16) Marshal.ReadInt16(lpRes);
            lpRes = new IntPtr(lpRes.ToInt32() + 2);
            
            lpRes = base.Read(lpRes);

            return lpRes;
        }

        /// <summary>
        /// Write menu item to a binary stream.
        /// </summary>
        /// <param name="w">Binary stream.</param>
        internal override void Write(BinaryWriter w)
        {
            w.Write(_header.mtOption);
            w.Write(_menuId);
            base.Write(w);
        }

        /// <summary>
        /// Returns true if the item is a separator.
        /// </summary>
        public bool IsSeparator
        {
            get
            {
                return ((_header.mtOption & (uint)User32.MenuFlags.MF_SEPARATOR) > 0) ||
                    (_header.mtOption == 0 && _menuString == null && _menuId == 0);
            }
        }

        /// <summary>
        /// String representation in the MENU format.
        /// </summary>
        /// <param name="indent">Indent.</param>
        /// <returns>String representation.</returns>
        public override string ToString(int indent)
        {
            StringBuilder sb = new StringBuilder();
            if (IsSeparator)
            {
                sb.AppendLine(string.Format("{0}MENUITEM SEPARATOR", 
                    new String(' ', indent)));
            }
            else
            {
                sb.AppendLine(string.Format("{0}MENUITEM \"{1}\", {2}",
                    new String(' ', indent),
                    _menuString == null ? string.Empty : _menuString.Replace("\t", @"\t"), _menuId));
            }
            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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

dB.
Team Leader Application Security Inc., www.appsecinc.com
United States United States
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.

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 16 Sep 2009
Article Copyright 2008 by dB.
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid