Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

How to register an extention

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to register an extention

    I saw question on PB/CC forum and remembered about VB code, found somewhere.
    After PB reconstruction it looks so:

    Code:
        #Compile Exe
        #Register None
        #Dim All
        #Include "Win32Api.Inc"
    
        %HKEY_CLASSES_ROOT = &H80000000
        %REG_SZ = 1
    
        $Extention = ".Bas"
        $Title = "Power Basic"
        $Path = "C:\PbDll60\Bin\PbEdit.exe"
        $Cmt = "PB/DLL source code"
    
        Function PbMain
           Dim KeyName   As Asciiz * 256
           Dim KeyValue  As Asciiz * 256
           Dim KeyHandle As Long
    
           KeyName = $Extention: KeyValue = $Title
           RegCreateKey %HKEY_CLASSES_ROOT, KeyName, KeyHandle
           RegSetValue KeyHandle, "", %REG_SZ, KeyValue, 0&
           RegCloseKey KeyHandle
    
           KeyName = $Title: KeyValue = $Cmt
           RegCreateKey %HKEY_CLASSES_ROOT, KeyName, KeyHandle
           RegSetValue KeyHandle, "", %REG_SZ, KeyValue, 0&
           RegCloseKey KeyHandle
    
           KeyName = $Title: KeyValue = $Path + " %1"
           RegCreateKey %HKEY_CLASSES_ROOT, KeyName, KeyHandle
           RegSetValue KeyHandle, "shell\open\command", %REG_SZ, KeyValue, %MAX_PATH
           RegCloseKey KeyHandle
       End Function
    Note. that some of settings will be actual after reboot only.

  • #2
    Here's some code that I use in my programs:
    Code:
    '------------------------------------------------------------------------------
    ' Add an icon to the system registry for a given file extension.
    '
    ' Example:
    '
    '   Success = RegisterIcon(".BAS","c:\pbdll50\bin\pbdll.exe","PB/DLL","PB/DLL")
    '
    FUNCTION RegisterIcon ALIAS "RegisterIcon" _
                         (Extension AS ASCIIZ,_     'extension with period
                          Icon AS ASCIIZ,_          'icon filename (with path)
                          Application AS ASCIIZ, _  'associated application
                          Description AS ASCIIZ _   'application description
                         ) EXPORT AS LONG
     
      LOCAL hKey AS LONG
     
      IF (LEN(Extension) * LEN(Description) * LEN(Icon)) = 0 THEN
        EXIT FUNCTION
      END IF
     
    ' ** Set description text
      hKey = RegOpenSection(%HKEY_CLASSES_ROOT, Extension)
     
      IF ISFALSE(hKey) THEN
        EXIT FUNCTION
      END IF
     
      RegSetString hKey, "", Description
      RegClose hKey
     
    ' ** Set description text
      hKey = RegOpenSection(%HKEY_CLASSES_ROOT, Description)
     
      IF ISFALSE(hKey) THEN
        EXIT FUNCTION
      END IF
     
      RegSetString hKey, "", Description
      RegClose hKey
     
    ' ** Set Icon
      hKey = RegOpenSection(%HKEY_CLASSES_ROOT, Description+"\DefaultIcon")
     
      IF ISFALSE(hKey) THEN
        EXIT FUNCTION
      END IF
     
      RegSetString hKey, "", Icon
      RegClose hKey
     
    ' ** Set default application for the file extension
      IF LEN(Application) = 0 THEN
        FUNCTION = %TRUE
        EXIT FUNCTION
      END IF
     
      hKey = RegOpenSection(%HKEY_CLASSES_ROOT, Description+"\shell\open\command")
     
      IF ISFALSE(hKey) THEN
        EXIT FUNCTION
      END IF
     
      RegSetString hKey, "", Application
      RegClose hKey
     
      FUNCTION = %TRUE
     
    END FUNCTION

    ------------------
    Home of the BASIC Gurus
    www.basicguru.com
    Home of the BASIC Gurus
    www.basicguru.com

    Comment

    Working...
    X