forked from yangzhongke/NetAutoGUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamicMainMenu.cs
More file actions
32 lines (30 loc) · 872 Bytes
/
Copy pathDynamicMainMenu.cs
File metadata and controls
32 lines (30 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using Vanara.PInvoke;
using static Vanara.PInvoke.User32;
namespace NetAutoGUI.Windows;
public class DynamicMainMenu : DynamicObject
{
private HWND hwnd;
public DynamicMainMenu(HWND hwnd)
{
this.hwnd = hwnd;
}
public override bool TryGetMember(GetMemberBinder binder, out object? result)
{
HMENU menu = GetMenu(hwnd);
DynamicMenuItem? menuItem = MenuHelpers.FindMenuItem(hwnd, menu, binder.Name);
if (menuItem != null)
{
result = menuItem;
return true;
}
return base.TryGetMember(binder, out result);
}
public override IEnumerable<string> GetDynamicMemberNames()
{
var menu = GetMenu(hwnd);
return MenuHelpers.GetSubMenuItems(menu).Select(e => e.Text);
}
}