6
6
using Vanara . InteropServices ;
7
7
using Vanara . PInvoke ;
8
8
using Vanara . Windows . Shell ;
9
+ using Windows . Win32 ;
10
+ using Windows . Win32 . UI . WindowsAndMessaging ;
9
11
10
12
namespace Files . App . Utils . Shell
11
13
{
@@ -43,7 +45,7 @@ private ContextMenu(Shell32.IContextMenu cMenu, User32.SafeHMENU hMenu, IEnumera
43
45
44
46
public async static Task < bool > InvokeVerb ( string verb , params string [ ] filePaths )
45
47
{
46
- using var cMenu = await GetContextMenuForFiles ( filePaths , Shell32 . CMF . CMF_DEFAULTONLY ) ;
48
+ using var cMenu = await GetContextMenuForFiles ( filePaths , PInvoke . CMF_DEFAULTONLY ) ;
47
49
48
50
return cMenu is not null && await cMenu . InvokeVerb ( verb ) ;
49
51
}
@@ -112,7 +114,7 @@ public async Task<bool> InvokeItem(int itemID)
112
114
return false ;
113
115
}
114
116
115
- public async static Task < ContextMenu ? > GetContextMenuForFiles ( string [ ] filePathList , Shell32 . CMF flags , Func < string , bool > ? itemFilter = null )
117
+ public async static Task < ContextMenu ? > GetContextMenuForFiles ( string [ ] filePathList , uint flags , Func < string , bool > ? itemFilter = null )
116
118
{
117
119
var owningThread = new ThreadWithMessageQueue ( ) ;
118
120
@@ -140,14 +142,14 @@ public async Task<bool> InvokeItem(int itemID)
140
142
} ) ;
141
143
}
142
144
143
- public async static Task < ContextMenu ? > GetContextMenuForFiles ( ShellItem [ ] shellItems , Shell32 . CMF flags , Func < string , bool > ? itemFilter = null )
145
+ public async static Task < ContextMenu ? > GetContextMenuForFiles ( ShellItem [ ] shellItems , uint flags , Func < string , bool > ? itemFilter = null )
144
146
{
145
147
var owningThread = new ThreadWithMessageQueue ( ) ;
146
148
147
149
return await owningThread . PostMethod < ContextMenu > ( ( ) => GetContextMenuForFiles ( shellItems , flags , owningThread , itemFilter ) ) ;
148
150
}
149
151
150
- private static ContextMenu ? GetContextMenuForFiles ( ShellItem [ ] shellItems , Shell32 . CMF flags , ThreadWithMessageQueue owningThread , Func < string , bool > ? itemFilter = null )
152
+ private static ContextMenu ? GetContextMenuForFiles ( ShellItem [ ] shellItems , uint flags , ThreadWithMessageQueue owningThread , Func < string , bool > ? itemFilter = null )
151
153
{
152
154
if ( ! shellItems . Any ( ) )
153
155
return null ;
@@ -159,7 +161,7 @@ public async Task<bool> InvokeItem(int itemID)
159
161
160
162
Shell32 . IContextMenu menu = sf . GetChildrenUIObjects < Shell32 . IContextMenu > ( default , shellItems ) ;
161
163
var hMenu = User32 . CreatePopupMenu ( ) ;
162
- menu . QueryContextMenu ( hMenu , 0 , 1 , 0x7FFF , flags ) ;
164
+ menu . QueryContextMenu ( hMenu , 0 , 1 , 0x7FFF , ( Shell32 . CMF ) flags ) ;
163
165
var contextMenu = new ContextMenu ( menu , hMenu , shellItems . Select ( x => x . ParsingName ) , owningThread , itemFilter ) ;
164
166
contextMenu . EnumMenuItems ( hMenu , contextMenu . Items ) ;
165
167
@@ -174,10 +176,10 @@ public async Task<bool> InvokeItem(int itemID)
174
176
175
177
public static async Task WarmUpQueryContextMenuAsync ( )
176
178
{
177
- using var cMenu = await GetContextMenuForFiles ( new string [ ] { $@ "{ Constants . UserEnvironmentPaths . SystemDrivePath } \" } , Shell32 . CMF . CMF_NORMAL ) ;
179
+ using var cMenu = await GetContextMenuForFiles ( new string [ ] { $@ "{ Constants . UserEnvironmentPaths . SystemDrivePath } \" } , PInvoke . CMF_NORMAL ) ;
178
180
}
179
181
180
- private void EnumMenuItems ( HMENU hMenu , List < Win32ContextMenuItem > menuItemsResult , bool loadSubenus = false )
182
+ private void EnumMenuItems ( Vanara . PInvoke . HMENU hMenu , List < Win32ContextMenuItem > menuItemsResult , bool loadSubenus = false )
181
183
{
182
184
var itemCount = User32 . GetMenuItemCount ( hMenu ) ;
183
185
@@ -211,12 +213,12 @@ private void EnumMenuItems(HMENU hMenu, List<Win32ContextMenuItem> menuItemsResu
211
213
continue ;
212
214
}
213
215
214
- menuItem . Type = ( MenuItemType ) menuItemInfo . fType ;
216
+ menuItem . Type = ( MENU_ITEM_TYPE ) menuItemInfo . fType ;
215
217
216
218
// wID - idCmdFirst
217
219
menuItem . ID = ( int ) ( menuItemInfo . wID - 1 ) ;
218
220
219
- if ( menuItem . Type == MenuItemType . MFT_STRING )
221
+ if ( menuItem . Type == MENU_ITEM_TYPE . MFT_STRING )
220
222
{
221
223
Debug . WriteLine ( "Item {0} ({1}): {2}" , index , menuItemInfo . wID , menuItemInfo . dwTypeData ) ;
222
224
@@ -244,7 +246,7 @@ private void EnumMenuItems(HMENU hMenu, List<Win32ContextMenuItem> menuItemsResu
244
246
}
245
247
}
246
248
247
- if ( menuItemInfo . hSubMenu != HMENU . NULL )
249
+ if ( menuItemInfo . hSubMenu != Vanara . PInvoke . HMENU . NULL )
248
250
{
249
251
Debug . WriteLine ( "Item {0}: has submenu" , index ) ;
250
252
var subItems = new List < Win32ContextMenuItem > ( ) ;
0 commit comments