Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding my program to right click menu

Status
Not open for further replies.

impulse24

IS-IT--Management
Jul 13, 2001
167
0
0
US
Hi,

I have written a program that when you select a file, it will convert the file to a different format. How do I include this program in the right click menu of Windows. I think I have to compile my program as a dll, and then somehow associate it in the registry But don't know how. Any help would be appreciated.
 
Impulse,

Are you looking to distribute the EXE and need this in the install script? because if so, I can't really help you there. But if you are looking to just create a shortcut on your machine, just place a shortcut to the program in the SendTo folder.

C:\Documents and Settings\username\SendTo

(i'm using W2K. On Win9x it's C:\Windows\SendTo)

Then your program will show up when you right click -> Send To -> right there. I use that capability to send a lot of things to Notepad. (i.e. things I don't really trust and want to make sure they're clean) And if you are going to do this, compile it as an EXE because it will be an executable. You run a program to convert the files.

Hope that helps.

-crater
 
thanks crater...actually im looking to distribute this..like when you have winzip installed and right click a file you have the option to zip the file. I want to add this ability with my app. So that when you right click on a file you can perform the action. I would like to select any file in explorer, right click and select Convert(my program), and my program launches to convert.
 
You need something similar to the following. This is a registry merge file, save it as with the extension .reg, and then merge it into the registry (normal warnings about modifying the registry apply). Naturally, you can write some VB to do the same thing if you'd prefer...

REGEDIT4

[HKEY_CLASSES_ROOT\*]

[HKEY_CLASSES_ROOT\*\Shell]

[HKEY_CLASSES_ROOT\*\Shell\Open]
@="&Convert"

[HKEY_CLASSES_ROOT\*\Shell\Open\Command]
@="\"full_path_to_your_program\" \"%1\""

And here's the VB that does something similar:
[tt]
Option Explicit

Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, ByVal lpSecurityAttributes As Any, phkResult As Long, lpdwDisposition As Long) As Long
Private Declare Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const REG_OPTION_NON_VOLATILE = 0
Private Const KEY_ALL_ACCESS = &H3F
Private Const REG_SZ = 1


Private Function AddMeToExplorerShortcutMenu()
Dim result As Long
Dim phKey As Long
Dim Disposition As Long
Dim KeyString As String
Dim mySec As SECURITY_ATTRIBUTES

result = RegCreateKeyEx(HKEY_CLASSES_ROOT, "*\Shell\Open", 0&, vbNullString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0&, phKey, Disposition)
If result = 0 Then
KeyString = "&New Info" + Chr$(0) ' This is the text that appears on the menu
result = RegSetValueExString(phKey, "", 0&, REG_SZ, KeyString, Len(KeyString))
RegCloseKey phKey ' Clean up
result = RegCreateKeyExString(HKEY_CLASSES_ROOT, "*\Shell\Open\Command", 0&, vbNullString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0&, phKey, Disposition)
KeyString = Chr(34) + App.Path + "\" + App.EXEName + Chr(34) + " %1" + Chr$(0)
result = RegSetValueExString(phKey, "", 0&, REG_SZ, KeyString, Len(KeyString))
RegCloseKey phKey ' Clean up
End If
End Function
 
I guess I should point out that to use the VB variant properly you need to compile the program first. The first time it is run it will make the association for you. Running it from the IDE, however, won't achieve very much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top