(C #) Windows Shell shell programming Series 6-execution

Source: Internet
Author: User

(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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.