/// <summary>Gets popup menu items from padding</summary> /// <param name="reader">Menu bytes</param> /// <param name="padding">Starting popup menu padding</param> /// <exception cref="T:InvalidOperationException">Can't find end of menu marker</exception> /// <returns>Readed popup menu items</returns> private MenuPopupItem[] GetPopupMenu(PinnedBufferReader reader, ref UInt32 padding) { List <MenuPopupItem> result = new List <MenuPopupItem>(); while (padding < reader.Length) { padding = NativeMethods.AlignToInt(padding); WinUser.MENUITEMEX item = reader.BytesToStructure <WinUser.MENUITEMEX>(ref padding); MenuPopupItem menu = new MenuPopupItem() { ItemEx = item, }; result.Add(menu); menu.Title = reader.BytesToStringUni(ref padding); if (item.IsPopUp) { menu.dwHelpId = reader.BytesToStructure <UInt32>(ref padding); menu.SubItems = this.GetPopupMenu(reader, ref padding); } if (item.IsFinal) { return(result.ToArray()); } } throw new InvalidOperationException(); }
/// <summary>Gets menu items from padding</summary> /// <param name="padding">Starting menu padding</param> /// <exception cref="T:InvalidOperationException">Can't find end of menu marker</exception> /// <returns>Menu items</returns> private IEnumerable <MenuItem> GetMenu(UInt32 padding) { //List<MenuItem> result = new List<MenuItem>(); using (PinnedBufferReader reader = base.CreateDataReader()) while (padding < reader.Length) { padding = NativeMethods.AlignToInt(padding); WinUser.MENUITEMEX item = reader.BytesToStructure <WinUser.MENUITEMEX>(ref padding); MenuItem menu = new MenuItem() { ItemEx = item, }; //result.Add(menu); menu.Title = reader.BytesToStringUni(ref padding); //TODO: bResInfo в 16 битных приложениях занимает не WORD, а BYTE. Если найдётся реальный пример, придётся полностью делать динамичесую структуру. if (item.IsPopUp) { menu.dwHelpId = reader.BytesToStructure <UInt32>(ref padding); menu.SubItems = this.GetPopupMenu(reader, ref padding); } yield return(menu); if (item.IsFinal) { yield break; } //return result.ToArray(); } throw new InvalidOperationException(); }