(This seriesArticleOriginal by lemon (lc_mtt), reprinted please indicate the source, thank you ~)
Run
Many people know that ShellExecute is used to execute an external command. But for the ishellfoloder object, its execution commands are all in its contextmenu. I remember how to directly call the items in contextmenu in the previous sections. Therefore, executing an ishellfoloder is nothing more than the default items in its contextmenu:
// Stores the pidl Array
Intptr [] pidls = new intptr [1];
Pidls [0] = pidl;
// Obtain the icontextmenu Interface
Intptr icontextmenuptr = intptr. zero;
Icontextmenuptr = iparent. getuiobjectof (intptr. Zero, (uint) pidls. length,
Pidls, ref guids. iid_icontextmenu, out icontextmenuptr );
Icontextmenu = (icontextmenu) Marshal. getobjectforiunknown (icontextmenuptr );
// Provide a handle for the pop-up menu
Intptr contextmenu = API. createpopupmenu ();
Icontextmenu. querycontextmenu (contextmenu, 0,
Api. Sort _first, Api. Sort _last, CMF. Normal | CMF. Sort E );
// Obtain the default command item
Int defaultcommand = API. getmenudefaultitem (contextmenu, false, 0 );
Cminvokecommandinfoex invoke = new cminvokecommandinfoex ();
Invoke. cbsize = marshal. sizeof (typeof (cminvokecommandinfoex ));
Invoke. lpverb = (intptr) (defaultcommand-API. pai_first );
Invoke. lpdirectory = string. empty;
Invoke. fmask = 0;
Invoke. ptinvoke = new point (mouseposition. X, mouseposition. y );
Invoke. nshow = 1;
Icontextmenu. invokecommand (ref invoke );
Prototype of getmenudefaultitem:
[Dllimport ("USER32", setlasterror = true, charset = charset. Auto)]
Public static extern int getmenudefaultitem (intptr hmenu, bool fbypos, uint gmdiflags );
The default menu of an ishellfolder is generally "open", but some are not. Therefore, lpverb should not directly use "open ".
Resource Manager
After modifying the examples in the previous sections, we can get a prototype of the resource manager, but there are still many problems:
1. Resources will not be released
2. Icon icons such as shortcuts and sharing cannot be displayed.
3. contextmenu is not processed in some places, for example, sent...
4. Drag is not implemented
5. No real-time monitoring changes
Therefore, it is very troublesome to create a complete resource manager. You can refer to C # filebrowser, which is already very good.
Source code:/files/lemony/winshell5.rar
In the future, we will introduce some content for implementing shell operations in the resource manager. I hope you will support javas_^ more.