|
-
Jun 1st, 2007, 08:24 PM
#1
Thread Starter
Addicted Member
[Resolved] Opening File Types
Does anyone know how to make it so everytime I click on a .test file then it opens up my project???
e.g. when i click on help.test i want it to open up project1.exe
Last edited by nuclear112; Jun 1st, 2007 at 11:27 PM.
-
Jun 1st, 2007, 09:24 PM
#2
Re: Opening File Types
You would have to create a file association manually or programmatically (search forum for samples if you want this approach).
-
Jun 1st, 2007, 09:29 PM
#3
Thread Starter
Addicted Member
Re: Opening File Types
i kinda found out how to do it. But now all I need to know is how to change the icon of the .test
Im pretty sure it uses the registry...
-
Jun 1st, 2007, 09:29 PM
#4
Addicted Member
Re: Opening File Types
Code:
Public Type MnuCommands
Captions As New Collection
Commands As New Collection
End Type
Public Type FileType
Commands As MnuCommands
Extension As String
ProperName As String
FullName As String
ContentType As String
IconPath As String
IconIndex As Integer
End Type
Public Declare Function RegCreateKey Lib "advapi32" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpszSubKey As String, phkResult As Long) As Long
Public Declare Function RegSetValueEx Lib "advapi32" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpszValueName As String, ByVal dwReserved As Long, ByVal fdwType As Long, lpbData As Any, ByVal cbData As Long) As Long
Public Sub CreateExtension(newfiletype As FileType)
Dim IconString As String
Dim Result As Long, Result2 As Long, ResultX As Long
Dim ReturnValue As Long, HKeyX As Long
Dim cmdloop As Integer
IconString = newfiletype.IconPath & "," & newfiletype.IconIndex
If Left$(newfiletype.Extension, 1) <> "." Then
newfiletype.Extension = "." & newfiletype.Extension
End If
RegCreateKey HKEY_CLASSES_ROOT, newfiletype.Extension, Result
ReturnValue = RegSetValueEx(Result, "", 0, REG_SZ, ByVal newfiletype.ProperName, LenB(StrConv(newfiletype.ProperName, vbFromUnicode)))
If newfiletype.ContentType <> "" Then
ReturnValue = RegSetValueEx(Result, "Content Type", 0, REG_SZ, ByVal CStr(newfiletype.ContentType), LenB(StrConv(newfiletype.ContentType, vbFromUnicode)))
End If
RegCreateKey HKEY_CLASSES_ROOT, newfiletype.ProperName, Result
If Not IconString = ",0" Then
RegCreateKey Result, "DefaultIcon", Result2
ReturnValue = RegSetValueEx(Result2, "", 0, REG_SZ, ByVal IconString, LenB(StrConv(IconString, vbFromUnicode)))
End If
ReturnValue = RegSetValueEx(Result, "", 0, REG_SZ, ByVal newfiletype.FullName, LenB(StrConv(newfiletype.FullName, vbFromUnicode)))
RegCreateKey Result, ByVal "Shell", ResultX
For cmdloop = 1 To newfiletype.Commands.Captions.Count
RegCreateKey ResultX, ByVal newfiletype.Commands.Captions(cmdloop), Result
RegCreateKey Result, ByVal "Command", Result2
Dim CurrentCommand$
CurrentCommand = newfiletype.Commands.Commands(cmdloop)
ReturnValue = RegSetValueEx(Result2, "", 0, REG_SZ, ByVal CurrentCommand$, LenB(StrConv(CurrentCommand$, vbFromUnicode)))
RegCloseKey Result
RegCloseKey Result2
Next
RegCloseKey Result2
End Sub
-
Jun 1st, 2007, 09:35 PM
#5
Thread Starter
Addicted Member
Re: Opening File Types
 Originally Posted by cxj98
Code:
Public Type MnuCommands
Captions As New Collection
Commands As New Collection
End Type
Public Type FileType
Commands As MnuCommands
Extension As String
ProperName As String
FullName As String
ContentType As String
IconPath As String
IconIndex As Integer
End Type
Public Declare Function RegCreateKey Lib "advapi32" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpszSubKey As String, phkResult As Long) As Long
Public Declare Function RegSetValueEx Lib "advapi32" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpszValueName As String, ByVal dwReserved As Long, ByVal fdwType As Long, lpbData As Any, ByVal cbData As Long) As Long
Public Sub CreateExtension(newfiletype As FileType)
Dim IconString As String
Dim Result As Long, Result2 As Long, ResultX As Long
Dim ReturnValue As Long, HKeyX As Long
Dim cmdloop As Integer
IconString = newfiletype.IconPath & "," & newfiletype.IconIndex
If Left$(newfiletype.Extension, 1) <> "." Then
newfiletype.Extension = "." & newfiletype.Extension
End If
RegCreateKey HKEY_CLASSES_ROOT, newfiletype.Extension, Result
ReturnValue = RegSetValueEx(Result, "", 0, REG_SZ, ByVal newfiletype.ProperName, LenB(StrConv(newfiletype.ProperName, vbFromUnicode)))
If newfiletype.ContentType <> "" Then
ReturnValue = RegSetValueEx(Result, "Content Type", 0, REG_SZ, ByVal CStr(newfiletype.ContentType), LenB(StrConv(newfiletype.ContentType, vbFromUnicode)))
End If
RegCreateKey HKEY_CLASSES_ROOT, newfiletype.ProperName, Result
If Not IconString = ",0" Then
RegCreateKey Result, "DefaultIcon", Result2
ReturnValue = RegSetValueEx(Result2, "", 0, REG_SZ, ByVal IconString, LenB(StrConv(IconString, vbFromUnicode)))
End If
ReturnValue = RegSetValueEx(Result, "", 0, REG_SZ, ByVal newfiletype.FullName, LenB(StrConv(newfiletype.FullName, vbFromUnicode)))
RegCreateKey Result, ByVal "Shell", ResultX
For cmdloop = 1 To newfiletype.Commands.Captions.Count
RegCreateKey ResultX, ByVal newfiletype.Commands.Captions(cmdloop), Result
RegCreateKey Result, ByVal "Command", Result2
Dim CurrentCommand$
CurrentCommand = newfiletype.Commands.Commands(cmdloop)
ReturnValue = RegSetValueEx(Result2, "", 0, REG_SZ, ByVal CurrentCommand$, LenB(StrConv(CurrentCommand$, vbFromUnicode)))
RegCloseKey Result
RegCloseKey Result2
Next
RegCloseKey Result2
End Sub
... How do I use this script? what do I put in for file type?
-
Jun 1st, 2007, 09:40 PM
#6
Addicted Member
Re: Opening File Types
I understand what do you achieve with this program, what you do, just paste this code into your VB IDE and test it, after you will know what's result.
-
Jun 1st, 2007, 09:47 PM
#7
Thread Starter
Addicted Member
Re: Opening File Types
Code:
Dim filety As FileType
filety = "test"
CreateExtension filety
doesn't work
-
Jun 1st, 2007, 11:05 PM
#8
Re: Opening File Types
If you don't need a programmatic solution, the steps for doing it manually are detailed here
-
Jun 1st, 2007, 11:27 PM
#9
Thread Starter
Addicted Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|