Jump to content

context menu - add new section (for certain extensions)


Recommended Posts

Posted

Alright, you know how WinRAR and other programs add their own little subsection to the context menu of certain extensions? Like this...

WinRAR >

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

| Extract files... |

| Extract Here |

| Extract to Archive\ |

| Convert archive... |

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

Well I wanted to know how to add something like this myself? Except I was going to add it only for certain filetypes...

I was going to setup subsections for the following types:

Image Files (.BMP/.JPG/.GIF/.PNG)

Movie Files (.AVI/.WMV/.MPG)

Text Files (.NFO/.DIZ/.SFV)

How would I go about doing this? That part of registry editing is completely over my head, as I haven't really found a great resource explaining everything.

I'm fairly sure this is quite a bit of reg tweaking involved here. Doesn't really matter what the commands are in the sub-menus, I just need a basic template to get me headed in the right direction.

This is basically what I need:

FILE -> SUBMENU -> COMMAND1 %1

FILE -> SUBMENU -> COMMAND2 %1

FILE -> SUBMENU -> COMMAND3 %1

If I was using a commandline tool for all of these, how would I go about using the filename in the syntax?

program -src="%1" -out="blah" -moreswitches

Also, is it possible to get just the directory of file %1? Then I could use -out="%1dir\new\" for the output. If anything I said here seems retarded or doesn't make sense, I'll attempt to clarify... but that seems like the best way to describe everything. So, if anybody could help with this at all, that would kick a**. Thanks in advance!


Posted (edited)

OK. I'll try to answer part of it.

The shell integration is very easy. To have a right click item what I do is...

For example if I right click a .flac file I can convert it to .mp3.

when you right click an extension the extension is registered to a file type like.

REG ADD "HKCR\.FLAC" /VE /D "FLACFile" /f

So it sees .flac and says it's a flacfile and looks to see what to do with it.

REG ADD "HKCR\FLACFile" /ve /d "Flac File" /f
REG ADD "HKCR\FLACFile\shell\Convert all to .mp3" /f
REG ADD "HKCR\FLACFile\shell\Convert all to .mp3\command" /ve /d "\"to-lame.cmd\" \"%%L\"" /f

That will show the text "Convert all to .mp3" when I right click the .flac file. If I click that it will call the batch file "to-lame.cmd" which is located in my system32 folder. Get it.

That's the bassis for creating a shell right click.

Put those 4 lines in a batch file and run it. Right click a .flac and there it is.

I should note. only use the top two lines if it's a new file type. For a common file type they will be in the registry already. .flac in mine points to ZPFLACfile because it's accociated to zoom player.

FYI my to-lame.cmd is

@echo off
cd /d %~dp0
if not exist mp3\ mkdir mp3

echo.
echo Decoding to .wav before converting to .mp3
echo.

for %%i in (*.flac) do flac -d "%%i" -o "mp3\%%~ni.wav"
cd mp3\
for %%j in (*.wav) do lame -h -V 0 --vbr-new "%%j" "%%~nj.mp3"
rem delete any temp .wav files in the mp3 folder
del /q "*.wav"
goto :eof

It will convert all .flac files in a folder to .mp3.

So you just have to decide what your doing with your image, movie and text files to decide on your batch files or exes to call.

I hope this help a bit.

Tomorrow when I'm sober I'll reread this and see what I can add.

:EDIT:

I'm not sure I understand...."Also, is it possible to get just the directory of file %1?"

This will do a dir command of all .mp3 files in a folder and send it to a text file.

dir /b /a-d *.mp3 > temp.txt

You can read the text file from a batch with

for /F "tokens=* delims= " %%G in (temp.txt) do call :suba %%G

That will send all lines in temp.txt to subrutine :suba one at a time. Use goto :eof at the end of the subrutine to get the next line from temp.txt.

To process just a single item passed to a batch file via the right click use %~nx1 in the batch. Beware of spaces though in what's passed.

Edited by jaws75
Posted (edited)

well, to get a submenu like winrar, you need to code something called a "shell extension" (you can't have submenues with reg settings AFAICT).

Here's a tutorial : http://www.codeproject.com/shell/shellextguideindex.asp

It doesn't cover the "submenu" part, but if you understand the rest of it, the submenu will be easy to add.

There is easier/faster methods, one is to use the classic "sendto" menu, another is to use a pre-made shell extension called "CMenu" (search on MSFN, there's a thread about it). Main disadvantage is you'll get your entries for *all* filetypes.

To get the directory of "%1", you need to call a batch, and inside this batch use something like :

your-program.exe -src-dir="%~p1" -src-name-without-ext="%~n1" -src-ext="%~x1" -src-drive="%~d1" -src-full-path="%~dp1" -src-name-plus-ext="%~nx1" -src-short-full-path-with-name-plus-ext="%~sdpnx1" -out-dir="C:\out" -evenmoreswithches

See the FOR /? last help page for more info on this.

(i'd bet it would be possible to use %~... in the registry by calling cmd.exe /e:on /c @for %i in (%1) do @your-program.exe -src-dir="%~pi"... but i never tried)

++

Edited by Delprat
  • 2 weeks later...
Posted
How would I go about doing this? That part of registry editing is completely over my head, as I haven't really found a great resource explaining everything.

You can't create submenus in the context menu with tweaking the registry.

There are quite a few freebies that allow for creating custom entries in a submenu per filetype.

Open Expert and Fast Explorer are the best ones IMO.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...