Sky Software Homepage LogicNP Software Knowledge Base And FAQ

 
Contact Product Support    SearchSearch      Subscribe to the RSS feed for this forum

HOWTO: Target a context menu extension for 'My Computer' or other special folders

 
Subscribe to the RSS feed for this forum  Forum Index -> EZShellExtensions.Net
View previous topic :: View next topic  
Author Message
Support



Joined: 18 Jul 2005
Posts: 731

Posted: Fri Nov 13, 2009 3:52 am    Post subject: HOWTO: Target a context menu extension for 'My Computer' or other special folders

To target a context menu extension for 'My Computer' or other special folders, use the following code:


Code:
[Guid("B084EEB5-C144-4006-A7C3-8DB4ED46C54B"), ComVisible(true)]
[TargetExtension(SpecialProgIDTargets.AllFolders, false)]
public class RegisterExtensionCtxExt : ContextMenuExtension
{
    public RegisterExtensionCtxExt()
    {
    }

    protected override bool OnInitializeEx(LogicNP.EZShellExtensions.Interop.IOleDataObject dataObject)
    {
        // Get PIDL of folder for which context menu is being shown
        IntPtr[] pidls = Utils.GetPIDLListFromDataObject(dataObject);

        // Get PIDL of 'My Computer'
        IntPtr myComp = Utils.GetSpecialFolderPIDL(SpecialFolders.DRIVES);

        // Only enable the extension for 'My Computer'
        if (Utils.PIDLCompare(pidls[0], myComp) == 0)
            return true;
        else
            return false;

    }

    protected override void OnGetMenuItems(LogicNP.EZShellExtensions.GetMenuitemsEventArgs e)
    {
        // Add our menu items
        e.Menu.AddItem("MyMenuItem", "MyMenuItem", "MyMenuItem");
    }

    protected override bool OnExecuteMenuItem(LogicNP.EZShellExtensions.ExecuteItemEventArgs e)
    {
        if (e.MenuItem.Verb == "MyMenuItem")
        {
            // Simply display the verb
            MessageBox.Show(e.MenuItem.Verb);
            return true;
        }
        // MUST return false if called for other verbs
        return false;
    }

    [ComRegisterFunction]
    public static void Register(System.Type t)
    {
        ContextMenuExtension.RegisterExtension(typeof(RegisterExtensionCtxExt));
    }

    [ComUnregisterFunction]
    public static void UnRegister(System.Type t)
    {
        ContextMenuExtension.UnRegisterExtension(typeof(RegisterExtensionCtxExt));
    }
}


Note

To target other special folders, use the appropriate SpecialFolders.XXXX enum in the OnInitializeEx method above.
Back to top
Display posts from previous:   
Forum Index -> EZShellExtensions.Net All times are GMT
Page 1 of 1

 
Jump to:  


Powered by phpBB © 2001, 2005 phpBB Group