Results 1 to 3 of 3

Thread: New File Extensions

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 1999
    Location
    Huntsville, AR 72740, USA
    Posts
    90

    Question

    How would I go about creating a file extension, and registering it with the host system?
    To Seek is to start on the never ending road to wisdom. To fail to seek, the path to death.

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Code:
    '// Registry windows api calls
    Private Declare Function RegCreateKey& Lib "advapi32.DLL" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpszSubKey As String, lphKey As Long)
    Private Declare Function RegSetValue& Lib "advapi32.DLL" Alias "RegSetValueA" (ByVal hKey As Long, ByVal lpszSubKey As String, ByVal fdwType As Long, ByVal lpszValue As String, ByVal dwLength As Long)
    '// Required constants
    Private Const HKEY_CLASSES_ROOT = &H80000000
    Private Const MAX_PATH = 256&
    Private Const REG_SZ = 1
    
    '// procedure you call to associate the tmg extension with your program.
    Private Sub MakeDefault()
        Dim sKeyName  As String  '// Holds Key Name in registry.
        Dim sKeyValue As String  '// Holds Key Value in registry.
        Dim ret       As Long    '// Holds error status if any from API calls.
        Dim lphKey    As Long    '// Holds created key handle from RegCreateKey.
       
        '// This creates a Root entry called "TextMagic"
        sKeyName = "TextMagic" '// Application Name
        sKeyValue = "TextMagic Document" '// File Description
        ret = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey)
        ret = RegSetValue&(lphKey&, Empty, REG_SZ, sKeyValue, 0&)
    
        '// This creates a Root entry called .tmg associated with "TextMagic".
        sKeyName = ".tmg" '// File Extension
        sKeyValue = "TextMagic" '// Application Name
        ret = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey)
    
        ret = RegSetValue&(lphKey, Empty, REG_SZ, sKeyValue, 0&)
    
        '//This sets the command line for "TextMagic".
        sKeyName = "TextMagic" '// Application Name
        If App.Path Like "*\" Then
            sKeyValue = App.Path & App.EXEName & ".exe %1" '// Application Path
        Else
            sKeyValue = App.Path & "\" & App.EXEName & ".exe %1" '// Application Path
        End If
        ret = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey)
        ret = RegSetValue&(lphKey, "shell\open\command", REG_SZ, sKeyValue, MAX_PATH)
    End Sub
    
    Private Sub Form_Load()
        '// ensure we only register once. When debugging etc, remove the SaveSetting line, so your program will
        '// always attempt to register the file extension
        If GetSetting(App.Title, "Settings", "RegisteredFile", 0) =  0 Then
            '// associate tmg extension with this app
            MakeDefault
            SaveSetting App.Title, "Settings", "RegisteredFile", 1
        End If
    End Sub
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    Megatron
    Guest
    See this link

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