Results 1 to 9 of 9

Thread: [Resolved] Opening File Types

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    169

    [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.

  2. #2

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    169

    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...

  4. #4
    Addicted Member cxj98's Avatar
    Join Date
    Feb 2007
    Posts
    170

    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

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    169

    Re: Opening File Types

    Quote 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?

  6. #6
    Addicted Member cxj98's Avatar
    Join Date
    Feb 2007
    Posts
    170

    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.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    169

    Re: Opening File Types

    Code:
    Dim filety As FileType
    filety = "test"
    CreateExtension filety
    doesn't work

  8. #8
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Opening File Types

    If you don't need a programmatic solution, the steps for doing it manually are detailed here

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    169

    Re: Opening File Types

    thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width