Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > windows explorer context menu


Reply
 
Thread Tools Display Modes
  #1  
Old 09-04-2010, 05:41 AM
Goggy's Avatar
Goggy Goggy is offline
Contributor
 
Join Date: Sep 2005
Location: Enschede,The Netherlands
Posts: 612
Default windows explorer context menu


i used the code below to register a menu item in the Explorer context menu. Aldo this works just fine there is one problem with it. When i select multiple files and then press the button my application is fired up multiple times. Now what i would like is to it to be fired once and then pass on the multiple files that where selected...
any idea'?

Code:
''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Public Shared Sub RegisterMyApp()
            'full path to self, %L is placeholder for selected file
            Dim MenuCommand As String = String.Format("{0} {1}", Chr(34) & Application.ExecutablePath & Chr(34), Chr(34) & "%L" & Chr(34))
            Register(KeyName, MenuCaption, MenuCommand)
        End Sub
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <param name="ShellKeyName">Registry key name</param>
        ''' <param name="MenuCaption">Text that will appeare in context menu</param>
        ''' <param name="MenuCommand">Command</param>
        ''' <remarks></remarks>
        Public Shared Sub Register(ByVal ShellKeyName As String, ByVal MenuCaption As String, ByVal MenuCommand As String)
            If Not (String.IsNullOrEmpty(ShellKeyName) And _
                    String.IsNullOrEmpty(MenuCaption) And _
                    String.IsNullOrEmpty(MenuCaption)) Then
                ' create full path to registry location
                Dim regPath As String = String.Format("{0}\shell\{1}", "*", ShellKeyName)
                ' add context menu to the registry
                Using key As RegistryKey = Registry.ClassesRoot.CreateSubKey(regPath)
                    key.SetValue(Nothing, MenuCaption)
                End Using
                ' add command that is invoked to the registry
                Using key As RegistryKey = Registry.ClassesRoot.CreateSubKey(String.Format("{0}\command", regPath))
                    key.SetValue(Nothing, MenuCommand)
                End Using
            End If
        End Sub
        ''' <summary>
        ''' Unregister a simple shell context menu.
        ''' </summary>
        ''' <param name="shellKeyName">Name that was registered in the registry.</param>
        Public Shared Sub Unregister(ByVal ShellKeyName As String)
            If Not String.IsNullOrEmpty(ShellKeyName) Then
                ' full path to the registry location			
                Dim regPath As String = String.Format("{0}\shell\{1}", "*", ShellKeyName)
                ' remove context menu from the registry
                Registry.ClassesRoot.DeleteSubKeyTree(regPath)
            End If
        End Sub
thank you in advance
Goggy
__________________
As finishing touch, god created the Dutch!

utterly useless, but always trying to help
Reply With Quote
  #2  
Old 09-04-2010, 06:41 PM
AtmaWeapon's Avatar
AtmaWeapon AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

I don't think there's a way to do that via the registry/shell extensions. I'm pretty sure the correct way to do it is to write your application as a single-instance application, and have the StartupNextInstance event look for command-line arguments and open the document if they're there.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 09-05-2010, 01:36 AM
Goggy's Avatar
Goggy Goggy is offline
Contributor
 
Join Date: Sep 2005
Location: Enschede,The Netherlands
Posts: 612
Default

Thank you Ataweapon for the "missing link", ill take a look and see if i cant get it to work like i intended.

Got it to work like i wanted....
Your a Genius! thank you!
__________________
As finishing touch, god created the Dutch!

utterly useless, but always trying to help

Last edited by Goggy; 09-05-2010 at 06:20 AM.
Reply With Quote
  #4  
Old 09-06-2010, 12:29 AM
Goggy's Avatar
Goggy Goggy is offline
Contributor
 
Join Date: Sep 2005
Location: Enschede,The Netherlands
Posts: 612
Default 14 Files....

I do have one additional question do, under windows 7 i cant select more then 14 files, anything after that and my button disappears from the context menu. Under windows xp on the other hand i get a nice notification(something like selecting 18 files to... might result in system slowing up). Is there something i am missing in windows 7? i would like to be able to select more then just 14 files.
__________________
As finishing touch, god created the Dutch!

utterly useless, but always trying to help
Reply With Quote
  #5  
Old 09-07-2010, 10:21 AM
AtmaWeapon's Avatar
AtmaWeapon AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

I think I found the answer, but haven't experimented. I was surprised it only took me two web searches; I figured it'd take some esoteric combination of keywords that would take days to stumble upon.

This is kind of shaky but might actually end up working. Creating Shortcut Menu Handlers is a remarkably useful topic that I wish I'd found earlier. Look for the "Employing the Verb Selection Model" section near the end. It looks like the default verb is probably "Document", which is listed as having a limit of 15 items in both "legacy" and "COM" implementations of the shortcut menu handler. Switch the verb to "Player", and you get 100 or unlimited selections.

I'm not exactly sure how you use the COM implementation to get unlimited items, but 100 might be good enough for you. You might be able to use that document to get to something that's more help.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #6  
Old 09-07-2010, 10:49 AM
Goggy's Avatar
Goggy Goggy is offline
Contributor
 
Join Date: Sep 2005
Location: Enschede,The Netherlands
Posts: 612
Default

Quote:
Originally Posted by AtmaWeapon View Post
I think I found the answer, but haven't experimented. I was surprised it only took me two web searches; I figured it'd take some esoteric combination of keywords that would take days to stumble upon.
Again thank you for all you help, now lets see i can't get it to work for 100 items...

Code:
        Public Shared Sub Register(ByVal ShellKeyName As String, ByVal MenuCaption As String, ByVal MenuCommand As String)
            If Not (String.IsNullOrEmpty(ShellKeyName) And _
                    String.IsNullOrEmpty(MenuCaption) And _
                    String.IsNullOrEmpty(MenuCaption)) Then
                ' create full path to registry location
                Dim regPath As String = String.Format("{0}\shell\{1}", "*", ShellKeyName)
                ' add context menu to the registry
                Using key As RegistryKey = Registry.ClassesRoot.CreateSubKey(regPath)
                    key.SetValue(Nothing, MenuCaption, RegistryValueKind.String)
                End Using
                Using key As RegistryKey = Registry.ClassesRoot.CreateSubKey(regPath)
                    key.SetValue("MultiSelectModel", "Player", RegistryValueKind.String)
                End Using
                ' add command that is invoked to the registry
                Using key As RegistryKey = Registry.ClassesRoot.CreateSubKey(String.Format("{0}\command", regPath))
                    key.SetValue(Nothing, MenuCommand)
                End Using
            End If
        End Sub
Like Atma mentioned, the code piece in red was all that was needed to get the context menu to work for 100 entries
__________________
As finishing touch, god created the Dutch!

utterly useless, but always trying to help

Last edited by Goggy; 09-07-2010 at 11:35 AM. Reason: got it to work...
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->