Home All Groups Group Topic Archive Search About

How difficult is to add my menu to Windows Explorer?

Author
17 Feb 2009 12:47 AM
Kathy
Hello group,
         I need some pointers where to start.
I would like to add my own menu to Windows Explorer popup menu depending on
the object clicked on by the user.
How difficult is it?
Can I see some examples how to do that?
Thanks,
Kathy

Author
17 Feb 2009 1:26 AM
mayayana
You can add a basic Shell menu easily. Pick the
file type and add a few Registry keys. The following
adds Open with Notepad for all files:

HKEY_CLASSES_ROOT\*\shell\Open with Notepad\
default value: "Open with Notepad"

HKEY_CLASSES_ROOT\*\shell\Open with Notepad\Command\
default value: "notepad.exe %1"

  The default value of the "Open with Notepad" key (which can
be named anything) is what displays on the menu. In other
words, this:

HKEY_CLASSES_ROOT\*\shell\blah\
default value: "Open with Notepad"

will still display "Open with Notepad"

  You can also add the keys under the file type key. For
instance, you can add it under HKCR\.txt or HKCR\txtfile.
But if you use HKCR\txtfile and an editor is later installed
that takes over .txt then the HKCR\.txt key may lead to
the HKCR\AcmeTextFile key, disabling your menu.

  And you can have a menu for folders by doing the same
thing under the HKCR\folder or HKCR\directory key.

  By adding the line: yourEXEpath %1 your program gets
the selected file path in the command line at startup. So
you just have to check in Sub Main or Form load:

s = Command$

  Then check that at startup to see if you've got a file path.

   You can also add a menu item under the shellex key instead
of the shell key. Your menu item then shows lower down on
the context menu. But for that you need to write a context menu
handler shell extension. The advantages are questionable.The
main difference seems to be that you get to customize your
menu text for the specific file. If you're interested in that you
might want to look for the book V. B. Shell Programming by
J.P. Hamilton (O'Reilly). It covers all of the shell extensions
clearly. They're not hard to do from VB but I don't know of
any usable documentation about *how* to do it other than
that book.

Show quoteHide quote
> Hello group,
>          I need some pointers where to start.
> I would like to add my own menu to Windows Explorer popup menu depending
on
> the object clicked on by the user.
> How difficult is it?
> Can I see some examples how to do that?
> Thanks,
> Kathy
>
>
Author
17 Feb 2009 3:03 AM
Kathy
Thank you very much for your information.
I was not clear enough I'm afraid.
What I need is:
adding to shell menu my menu which will mimic Windows 'Copy' menu.
What I mean is: my menu should be always available when 'Copy' menu is
available.
Possible?
Thank you,
Kathy

Show quoteHide quote
"mayayana" <mayayaX***@rcXXn.com> wrote in message
news:%23f8Y97JkJHA.1252@TK2MSFTNGP03.phx.gbl...
>    You can add a basic Shell menu easily. Pick the
> file type and add a few Registry keys. The following
> adds Open with Notepad for all files:
>
> HKEY_CLASSES_ROOT\*\shell\Open with Notepad\
> default value: "Open with Notepad"
>
> HKEY_CLASSES_ROOT\*\shell\Open with Notepad\Command\
> default value: "notepad.exe %1"
>
>  The default value of the "Open with Notepad" key (which can
> be named anything) is what displays on the menu. In other
> words, this:
>
> HKEY_CLASSES_ROOT\*\shell\blah\
> default value: "Open with Notepad"
>
> will still display "Open with Notepad"
>
>  You can also add the keys under the file type key. For
> instance, you can add it under HKCR\.txt or HKCR\txtfile.
> But if you use HKCR\txtfile and an editor is later installed
> that takes over .txt then the HKCR\.txt key may lead to
> the HKCR\AcmeTextFile key, disabling your menu.
>
>  And you can have a menu for folders by doing the same
> thing under the HKCR\folder or HKCR\directory key.
>
>  By adding the line: yourEXEpath %1 your program gets
> the selected file path in the command line at startup. So
> you just have to check in Sub Main or Form load:
>
> s = Command$
>
>  Then check that at startup to see if you've got a file path.
>
>   You can also add a menu item under the shellex key instead
> of the shell key. Your menu item then shows lower down on
> the context menu. But for that you need to write a context menu
> handler shell extension. The advantages are questionable.The
> main difference seems to be that you get to customize your
> menu text for the specific file. If you're interested in that you
> might want to look for the book V. B. Shell Programming by
> J.P. Hamilton (O'Reilly). It covers all of the shell extensions
> clearly. They're not hard to do from VB but I don't know of
> any usable documentation about *how* to do it other than
> that book.
>
>> Hello group,
>>          I need some pointers where to start.
>> I would like to add my own menu to Windows Explorer popup menu depending
> on
>> the object clicked on by the user.
>> How difficult is it?
>> Can I see some examples how to do that?
>> Thanks,
>> Kathy
>>
>>
>
>
Author
17 Feb 2009 4:11 AM
mayayana
>  adding to shell menu my menu which will mimic Windows 'Copy' menu.
> What I mean is: my menu should be always available when 'Copy' menu is
> available.

   You'll need to test this to be certain, but I think
that if you add your menu under:

HKEY_CLASSES_ROOT\*\shell\
and
HKEY_CLASSES_ROOT\Directory\shell\

  then it should show up for all files and folders. It
won't show up for drives and specialty "namespaces",
but neither does Copy. So that should be what you want.

  The format is the same for both keys. Add a submenu
under shell, with menu text in the default value. Then
add a Command key under that, with a default value
that's your program EXE path + " %1". That works on all
systems up through XP. I assume it works on Vista, but
I haven't tried it.

   While your menu should show up wherever Copy shows
up, it won't be in the same grouping. It will be above the top
menu divider line. As far as I know the things below that
line are hard-coded and can't be changed.
Author
18 Feb 2009 1:31 AM
Kathy
Thank you for your help but I am unable to display any menu.
I am not sure if I should add my menu as a registry key or registry value.
What I tried:
In:
HKEY_CLASSES_ROOT\Directory\shell\
I added new key: mymenu
and
HKEY_CLASSES_ROOT\*\shell\
I added new key: mymenu

That did nothing to Windows.
Then I tried to add value mymenu to both keys mymenu.
That also did nothing to Windows.
Please tell me what I am doing wrong?
Thanks,
Kathy

Show quoteHide quote
"mayayana" <mayayaX***@rcXXn.com> wrote in message
news:OAdyNYLkJHA.4880@TK2MSFTNGP02.phx.gbl...
>>  adding to shell menu my menu which will mimic Windows 'Copy' menu.
>> What I mean is: my menu should be always available when 'Copy' menu is
>> available.
>
>   You'll need to test this to be certain, but I think
> that if you add your menu under:
>
> HKEY_CLASSES_ROOT\*\shell\
> and
> HKEY_CLASSES_ROOT\Directory\shell\
>
>  then it should show up for all files and folders. It
> won't show up for drives and specialty "namespaces",
> but neither does Copy. So that should be what you want.
>
>  The format is the same for both keys. Add a submenu
> under shell, with menu text in the default value. Then
> add a Command key under that, with a default value
> that's your program EXE path + " %1". That works on all
> systems up through XP. I assume it works on Vista, but
> I haven't tried it.
>
>   While your menu should show up wherever Copy shows
> up, it won't be in the same grouping. It will be above the top
> menu divider line. As far as I know the things below that
> line are hard-coded and can't be changed.
>
>
Author
18 Feb 2009 2:33 AM
mayayana
> What I tried:
> In:
> HKEY_CLASSES_ROOT\Directory\shell\
> I added new key: mymenu
> and
> HKEY_CLASSES_ROOT\*\shell\
> I added new key: mymenu
>

OK, so now you have
HKCR\*\shell\mymenu\

  Add the string "mymenu2" as the default value
in that key. Then add another key named Command,
under that key:

HKCR\*\shell\mymenu\Command\

  Add the string "notepad.exe %1" as the default
value in that key.

   (Some people say it should be "notepad.exe "%1""
I don't remember the reason for that, but it doesn't
seem to be necessary.)

  That should open the selected file in Notepad when
you click the "mymenu2" menu item. To test your own
program, in the Command key default value put the
path to your EXE:
  "C:\test\yourNewEXE.exe %1"

   When the mymenu2 menu item is clicked now, your
program should be opened and you should get the selected
file(s) path in the Command string:

Private Sub Form_Load()
   msgbox Command$
End Sub

   It should work the same way under the Directory key.
I've added "Open with Notepad" on 95/98/ME/XP in
the past. I've also added "Open in New Window" for
folders under the Directory key. (That's a very handy
menu item that Microsoft, for some reason, doesn't
bother adding.)

  Note on the menu text: I always put the menu text in
the default value of the key under shell, but it *seems*
to be the case that if you put no text then the key name
itself will be used.

   I don't know why your "mymenu" didn't show up.
I assume it's because you didn't have a Command key
with a valid command line, and therefore the mymenu
key served no purpose.

------------------------------------------
If I export with regedit I get this:

REGEDIT4

[HKEY_CLASSES_ROOT\*\shell\Open with Notepad\Command]
@="notepad.exe %1"

But I think it should really be this:

REGEDIT4

[HKEY_CLASSES_ROOT\*\shell\Open with Notepad]
@="Open with Notepad"

[HKEY_CLASSES_ROOT\*\shell\Open with Notepad\Command]
@="notepad.exe %1"

------------------------------

   Does that all make sense? Basically you're putting
a shell key under the relevant HKCR key. Then you're
putting your menu key under that, which can be anything
you like. Then you put the Command key under that.

    You should be able to see
the same basic thing under the HKCR\txtfile key.
Any shell menu like Open, Edit, etc. is reflected in the
Registry, either under the extension key (example: HKCR\.txt)
or under the file type key. (example: HKCR\txtfile)
Author
18 Feb 2009 6:39 AM
Kathy
Thank you for your patience being with me, mayayana.
I am able to add my menu to shell now.
I was missing "Command" key hence the lack of the display.
Now, I need some fine tuning.
I need my menu to appear not when the folders list are displayed, but only
when some text document is opened (edit mode).
For example:
when Notepad is opened there is: Undo, Cut, Copy, Paste, Delete, Select All
or Internet Explorer window, which also has:Cut,Copy,Copy, Shortcut, Paste
(some greyed out),
or MsWord, which has Cut, Copy, Paste
etc
Are those Shell menus or belonging to each application indepedently?

Maybe, I am asking too much?
Thank you very much,
Kathy

Show quoteHide quote
"mayayana" <mayayaX***@rcXXn.com> wrote in message
news:uQ0$RGXkJHA.1168@TK2MSFTNGP05.phx.gbl...
>> What I tried:
>> In:
>> HKEY_CLASSES_ROOT\Directory\shell\
>> I added new key: mymenu
>> and
>> HKEY_CLASSES_ROOT\*\shell\
>> I added new key: mymenu
>>
>
> OK, so now you have
> HKCR\*\shell\mymenu\
>
>  Add the string "mymenu2" as the default value
> in that key. Then add another key named Command,
> under that key:
>
> HKCR\*\shell\mymenu\Command\
>
>  Add the string "notepad.exe %1" as the default
> value in that key.
>
>   (Some people say it should be "notepad.exe "%1""
> I don't remember the reason for that, but it doesn't
> seem to be necessary.)
>
>  That should open the selected file in Notepad when
> you click the "mymenu2" menu item. To test your own
> program, in the Command key default value put the
> path to your EXE:
>  "C:\test\yourNewEXE.exe %1"
>
>   When the mymenu2 menu item is clicked now, your
> program should be opened and you should get the selected
> file(s) path in the Command string:
>
> Private Sub Form_Load()
>   msgbox Command$
> End Sub
>
>   It should work the same way under the Directory key.
> I've added "Open with Notepad" on 95/98/ME/XP in
> the past. I've also added "Open in New Window" for
> folders under the Directory key. (That's a very handy
> menu item that Microsoft, for some reason, doesn't
> bother adding.)
>
>  Note on the menu text: I always put the menu text in
> the default value of the key under shell, but it *seems*
> to be the case that if you put no text then the key name
> itself will be used.
>
>   I don't know why your "mymenu" didn't show up.
> I assume it's because you didn't have a Command key
> with a valid command line, and therefore the mymenu
> key served no purpose.
>
> ------------------------------------------
> If I export with regedit I get this:
>
> REGEDIT4
>
> [HKEY_CLASSES_ROOT\*\shell\Open with Notepad\Command]
> @="notepad.exe %1"
>
> But I think it should really be this:
>
> REGEDIT4
>
> [HKEY_CLASSES_ROOT\*\shell\Open with Notepad]
> @="Open with Notepad"
>
> [HKEY_CLASSES_ROOT\*\shell\Open with Notepad\Command]
> @="notepad.exe %1"
>
> ------------------------------
>
>   Does that all make sense? Basically you're putting
> a shell key under the relevant HKCR key. Then you're
> putting your menu key under that, which can be anything
> you like. Then you put the Command key under that.
>
>    You should be able to see
> the same basic thing under the HKCR\txtfile key.
> Any shell menu like Open, Edit, etc. is reflected in the
> Registry, either under the extension key (example: HKCR\.txt)
> or under the file type key. (example: HKCR\txtfile)
>
>
>
Author
1 Mar 2009 9:35 PM
GS
If your looking to provide 'custom' functionality to the MS Office apps, you
can do so via Add-ins. These will need to be application specific as each
component of the MS Office suite has there own form for this feature. For
example, Excel uses '.XLA' files for its addins.

The addin would contain VBA code in a VBA project module similar to a VB6
project. This code could change the behavior of Excel's built-in menus to run
your procedures instead of its own default procedure when a menuitem is
clicked. The term used for this sort of thing is called "control hooking",
whereby the commandbar controls are re-routed through your code. This is
commonly used as a conditional measure to get the normal action to use your
function/procedure instead of the built-in function/procedure within a
certain context, or use the built-in function/procedure in the normal fashion.

Since VBA is a subset of VB6 your code will run with little or no changes.
You will need to have an understanding of each application's object model to
impliment things, and this is a subject for another forum.

Alternatively, you could write a VB6 COM addin for the specific MS Office
app you want to provide the custom function/procedure to.

HTH
Kind regards,
Garry
--

Show quoteHide quote
"Kathy" wrote:

> Thank you for your patience being with me, mayayana.
> I am able to add my menu to shell now.
> I was missing "Command" key hence the lack of the display.
> Now, I need some fine tuning.
> I need my menu to appear not when the folders list are displayed, but only
> when some text document is opened (edit mode).
> For example:
> when Notepad is opened there is: Undo, Cut, Copy, Paste, Delete, Select All
> or Internet Explorer window, which also has:Cut,Copy,Copy, Shortcut, Paste
> (some greyed out),
> or MsWord, which has Cut, Copy, Paste
> etc
> Are those Shell menus or belonging to each application indepedently?
>
> Maybe, I am asking too much?
> Thank you very much,
> Kathy
>
> "mayayana" <mayayaX***@rcXXn.com> wrote in message
> news:uQ0$RGXkJHA.1168@TK2MSFTNGP05.phx.gbl...
> >> What I tried:
> >> In:
> >> HKEY_CLASSES_ROOT\Directory\shell\
> >> I added new key: mymenu
> >> and
> >> HKEY_CLASSES_ROOT\*\shell\
> >> I added new key: mymenu
> >>
> >
> > OK, so now you have
> > HKCR\*\shell\mymenu\
> >
> >  Add the string "mymenu2" as the default value
> > in that key. Then add another key named Command,
> > under that key:
> >
> > HKCR\*\shell\mymenu\Command\
> >
> >  Add the string "notepad.exe %1" as the default
> > value in that key.
> >
> >   (Some people say it should be "notepad.exe "%1""
> > I don't remember the reason for that, but it doesn't
> > seem to be necessary.)
> >
> >  That should open the selected file in Notepad when
> > you click the "mymenu2" menu item. To test your own
> > program, in the Command key default value put the
> > path to your EXE:
> >  "C:\test\yourNewEXE.exe %1"
> >
> >   When the mymenu2 menu item is clicked now, your
> > program should be opened and you should get the selected
> > file(s) path in the Command string:
> >
> > Private Sub Form_Load()
> >   msgbox Command$
> > End Sub
> >
> >   It should work the same way under the Directory key.
> > I've added "Open with Notepad" on 95/98/ME/XP in
> > the past. I've also added "Open in New Window" for
> > folders under the Directory key. (That's a very handy
> > menu item that Microsoft, for some reason, doesn't
> > bother adding.)
> >
> >  Note on the menu text: I always put the menu text in
> > the default value of the key under shell, but it *seems*
> > to be the case that if you put no text then the key name
> > itself will be used.
> >
> >   I don't know why your "mymenu" didn't show up.
> > I assume it's because you didn't have a Command key
> > with a valid command line, and therefore the mymenu
> > key served no purpose.
> >
> > ------------------------------------------
> > If I export with regedit I get this:
> >
> > REGEDIT4
> >
> > [HKEY_CLASSES_ROOT\*\shell\Open with Notepad\Command]
> > @="notepad.exe %1"
> >
> > But I think it should really be this:
> >
> > REGEDIT4
> >
> > [HKEY_CLASSES_ROOT\*\shell\Open with Notepad]
> > @="Open with Notepad"
> >
> > [HKEY_CLASSES_ROOT\*\shell\Open with Notepad\Command]
> > @="notepad.exe %1"
> >
> > ------------------------------
> >
> >   Does that all make sense? Basically you're putting
> > a shell key under the relevant HKCR key. Then you're
> > putting your menu key under that, which can be anything
> > you like. Then you put the Command key under that.
> >
> >    You should be able to see
> > the same basic thing under the HKCR\txtfile key.
> > Any shell menu like Open, Edit, etc. is reflected in the
> > Registry, either under the extension key (example: HKCR\.txt)
> > or under the file type key. (example: HKCR\txtfile)
> >
> >
> >
>
>
>