Creating Explorer Menu Extensions

Just starting out? Need help? Post your questions and find answers here.
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Creating Explorer Menu Extensions

Post by Karbon »

Does anyone have any information on adding options to the (explorer?) menus that pop up when you right click on files?
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
hm
User
User
Posts: 30
Joined: Mon Oct 27, 2003 12:15 pm
Location: Germany
Contact:

Post by hm »

it's called a "shell extension handler", look in PSDK or MSDN.
it is implemented as COM in-process server.

along PSDK comes the SHELLEX example of MS.

there are also some ASM examples on the web.

cu
-hm
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

Does this do what you want?:
viewtopic.php?t=8668
--Kale

Image
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Nope, that creates shorcuts.. I'd like to add options to the explorer menu so you can pass files directly to it from any explorer window (Windows Explorer, not Internet Explorer).. Like WinZip does..

Looks like there is information http://msdn.microsoft.com/library/defau ... ndlers.asp but it looks like I'd need to create a COM DLL, and AFAIK that's not possible in PB at the moment?
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Writing a shell extension handler is not the easiest task, even if you do it
in a language that makes it easier to create COM objects than PB.

As you can read in the documentation, you'll have to export several
Interfaces, which in PB is quite a lot of work. (just look at my COM-downlaod
tutorial in the tips&tricks section, and you'll see.)

A context menu handler is only needed, if you need to dynamically add
menu items, depending on each individual file. If you only want an item
for all files of a type, it should be possible by just adding
some registry entrys.

See here for more details:
http://msdn.microsoft.com/library/defau ... ontext.asp

The PureBasic editor for example does that to add the standart "Open" item:

Code: Select all

; Now, update the registry to associate correctly the '.pb' with the editor.
;

If GetVersion_() & $ff0000  ; Windows NT/XP
  
  If RegCreateKeyEx_(#HKEY_CLASSES_ROOT, "Applications\PureBasic.exe\shell\open\command", 0, 0, #REG_OPTION_NON_VOLATILE, #KEY_ALL_ACCESS, 0, @NewKey, @KeyInfo) = #ERROR_SUCCESS
    StringBuffer$ = Chr(34)+FullPath+"PureBasic.exe"+Chr(34)+" "+Chr(34)+"%1"+Chr(34)
    RegSetValueEx_(NewKey, "", 0, #REG_SZ,  StringBuffer$, Len(StringBuffer$)+1)
    RegCloseKey_(NewKey)
  EndIf
  
  If RegCreateKeyEx_(#HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.pb", 0, 0, #REG_OPTION_NON_VOLATILE, #KEY_ALL_ACCESS, 0, @NewKey, @KeyInfo) = #ERROR_SUCCESS
    RegSetValueEx_(NewKey, "Application", 0, #REG_SZ,  "PureBasic.exe", Len("PureBasic.exe")+1)
    RegCloseKey_(NewKey)
  EndIf
  
Else  ; The same for Win9x
  
  If RegCreateKeyEx_(#HKEY_LOCAL_MACHINE, "Software\Classes\PureBasic.exe\shell\open\command", 0, 0, #REG_OPTION_NON_VOLATILE, #KEY_ALL_ACCESS, 0, @NewKey, @KeyInfo) = #ERROR_SUCCESS
    StringBuffer$ = Chr(34)+FullPath+"PureBasic.exe"+Chr(34)+" "+Chr(34)+"%1"+Chr(34)
    RegSetValueEx_(NewKey, "", 0, #REG_SZ,  StringBuffer$, Len(StringBuffer$)+1)
    RegCloseKey_(NewKey)
  EndIf
  
  If RegCreateKeyEx_(#HKEY_LOCAL_MACHINE, "Software\CLASSES\.pb", 0, 0, #REG_OPTION_NON_VOLATILE, #KEY_ALL_ACCESS, 0, @NewKey, @KeyInfo) = #ERROR_SUCCESS
    RegSetValueEx_(NewKey, "", 0, #REG_SZ,  "PureBasic.exe", Len("PureBasic.exe")+1)
    RegCloseKey_(NewKey)
  EndIf
  
EndIf
As you see, it adds the subkey "PureBasic.exe\shell\open\command", and
the default value is the action to take when the 'Open' menuitem is clicked.

If you add something like "PureBasic.exe\shell\execute\command", and
set the default value to "C:\PureBasic\Compilers\pbcompiler.exe %1", and
set the default value of the "PureBasic.exe\shell\execute" key to "Execute",
you get another popupmenu item called "Execute", which will runn the
source file directly.


Timo
quidquid Latine dictum sit altum videtur
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

Hmm, I've been trying freak's code on Vista but I don't get it to work :S
What I want to do is to add an item in the right click menu for .jpg images.

Edit; this seems to work on Vista:

Code: Select all

[HKEY_CLASSES_ROOT\jpegfile\shell\Upload with ImageUploader]
@="Upload with ImageUploader"

[HKEY_CLASSES_ROOT\jpegfile\shell\Upload with ImageUploader\command]
@="\"C:\\Users\\Joakim\\Desktop\\PureBasic\\ImageUploader.exe" %1"
I like logic, hence I dislike humans but love computers.
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Is there anything that works for both XP and Vista?
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

The Win9x part of my code above will work on XP and Vista if you change #HKEY_LOCAL_MACHINE to #HKEY_CURRENT_USER.
quidquid Latine dictum sit altum videtur
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

freak wrote:The Win9x part of my code above will work on XP and Vista if you change #HKEY_LOCAL_MACHINE to #HKEY_CURRENT_USER.
@Timo : I have just added the win 9x variant of your code to a program of mine and it works fine on XP and Vista. Strangely though, on both of these systems, running the code results not only in being able to execute my 'default program' against the registered file extension through the shell/open menu, but also by double clicking any file with the appropriate extension!

This is strange because the registry entries allowing for execution by double clicking reside within the HKEY_CLASSES_ROOT tree! I have checked and the relevant entries have been added automatically by the shell!

I have confirmed by manually removing all of these registry entries and running your Win 9x code again!

This is an unexpected side-effect. Not a bad one because I was just about to add the code to do this anyhow! :) I am just a little puzzled why the system should add these entries automatically?

Any idea?

Thanks.
I may look like a mule, but I'm not a complete ass.
Post Reply