Hai !!!
Du Programmierst ein Editor und hast eigene Datei erweiterung, und wenn du auf die Datei klickst soll deine Anwendung gestartet werden, kein Problem, hier ist die Code
Willst du für deine Eigene Datei erweiterung eigene Symbol, auch kein Problemm hier ist die Code
Viel Spaß damit!!
PS:BITTE KEINE ANTWORT !!!!
Du Programmierst ein Editor und hast eigene Datei erweiterung, und wenn du auf die Datei klickst soll deine Anwendung gestartet werden, kein Problem, hier ist die Code
Visual Basic-Quellcode
- Option Explicit
- ' zun?chst alle ben?tigten API-Deklarationen
- Private Const HKEY_LOCAL_MACHINE = &H80000002
- Private Const KEY_ALL_ACCESS = &H3F
- Private Const KEY_SET_VALUE = &H2
- Private Const KEY_CREATE_SUB_KEY = &H4
- Private Const REG_PRIMARY_KEY = "Software\Classes\"
- Private Const REG_SHELL_KEY = "Shell\"
- Private Const REG_SHELL_OPEN_KEY = "Open\"
- Private Const REG_SHELL_OPEN_COMMAND_KEY = "Command"
- Private Const REG_SZ = 1
- Private Const REG_OPTION_NON_VOLATILE = 0
- Private Const ERROR_SUCCESS = 0&
- Private Type SECURITY_ATTRIBUTES
- nLength As Long
- lpSecurityDescriptor As Long
- bInheritHandle As Boolean
- End Type
- Private Declare Function RegCloseKey Lib "advapi32.dll" _
- (ByVal hKey As Long) As Long
- Private Declare Function RegOpenKeyEx Lib "advapi32.dll" _
- Alias "RegOpenKeyExA" (ByVal hKey As Long, _
- ByVal lpSubKey As String, ByVal ulOptions As Long, _
- ByVal samDesired As Long, phkResult As Long) As Long
- 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, lpSecurityAttributes As _
- SECURITY_ATTRIBUTES, phkResult As Long, _
- lpdwDisposition As Long) As Long
- Private Declare Function RegSetValue Lib "advapi32.dll" _
- Alias "RegSetValueA" (ByVal hKey As Long, _
- ByVal lpSubKey As Any, ByVal dwType As Long, _
- ByVal lpData As String, ByVal cbData As Long) As Long
- Private Function OpenKey(lhKey As Long, SubKey As String, _
- ulOptions As Long) As Long
- Dim lhKeyOpen As Long
- Dim lResult As Long
- lhKeyOpen = 0
- lResult = RegOpenKeyEx(lhKey, SubKey, 0, ulOptions, _
- lhKeyOpen)
- If lResult <> ERROR_SUCCESS Then
- OpenKey = 0
- Else
- OpenKey = lhKeyOpen
- End If
- End Function
- Private Function CreateKey(lhKey As Long, SubKey As _
- String, NewSubKey As String) As Boolean
- Dim lhKeyOpen As Long
- Dim lhKeyNew As Long
- Dim lDisposition As Long
- Dim lResult As Long
- Dim Security As SECURITY_ATTRIBUTES
- lhKeyOpen = OpenKey(lhKey, SubKey, _
- KEY_CREATE_SUB_KEY)
- lResult = RegCreateKeyEx(lhKeyOpen, NewSubKey, 0, "", _
- REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, Security, _
- lhKeyNew, lDisposition)
- If lResult = ERROR_SUCCESS Then
- CreateKey = True
- RegCloseKey (lhKeyNew)
- Else
- CreateKey = False
- End If
- RegCloseKey (lhKeyOpen)
- End Function
- Private Function SetValue(lhKey As Long, SubKey As _
- String, sValue As String) As Boolean
- Dim lhKeyOpen As Long
- Dim lResult As Long
- Dim lTyp As Long
- Dim lByte As Long
- lByte = Len(sValue)
- lTyp = REG_SZ
- lhKeyOpen = OpenKey(lhKey, SubKey, KEY_SET_VALUE)
- lResult = RegSetValue(lhKey, SubKey, lTyp, sValue, _
- lByte)
- If lResult <> ERROR_SUCCESS Then
- SetValue = False
- Else
- SetValue = True
- RegCloseKey (lhKeyOpen)
- End If
- End Function
- ' Datei-Verkn?pfung in der Registry speichern
- ' Datei-Verkn?pfung in der Registry speichern
- ' sFileExt = Dateiendung (z.B. .txt)
- ' sFileDescr = Beschreibung (z.B. Textdokument)
- ' sAppID = Programm-Kennung (z.B. Mein Texteditor)
- ' sOpenCmd = vollst?ndiger Dateiname der Anwendung
- ' inkl. Parameter %1
- ' (z.B. App.Path & "\" & App.EXEName & ".exe %1"
- Public Function RegisterFile(sFileExt As String, _
- sFileDescr As String, sAppID As String, _
- sOpenCmd As String) As Boolean
- Dim hKey As Long
- Dim bSuccess As Boolean
- bSuccess = False
- hKey = HKEY_LOCAL_MACHINE
- ' File-Extension
- If CreateKey(hKey, REG_PRIMARY_KEY, sFileExt) Then
- If SetValue(hKey, REG_PRIMARY_KEY & sFileExt, _
- sAppID) Then
- ' AppID
- If CreateKey(hKey, REG_PRIMARY_KEY, sAppID) Then
- ' AppDescription
- If SetValue(hKey, REG_PRIMARY_KEY & sAppID, _
- sFileDescr) Then
- ' OpenCommand
- If CreateKey(hKey, REG_PRIMARY_KEY & sAppID, _
- REG_SHELL_KEY & REG_SHELL_OPEN_KEY & _
- REG_SHELL_OPEN_COMMAND_KEY) Then
- bSuccess = SetValue(hKey, REG_PRIMARY_KEY & _
- sAppID & "\" & REG_SHELL_KEY & _
- REG_SHELL_OPEN_KEY & _
- REG_SHELL_OPEN_COMMAND_KEY, sOpenCmd)
- End If
- End If
- End If
- End If
- End If
- RegisterFile = bSuccess
- End Function
- Beispiel
- ' .txt-Dateien registrieren
- RegisterFile ".txt", "Textdokument", "MeinTexteditor", _
- App.Path & "\" & App.EXEName & ".exe %1"
Willst du für deine Eigene Datei erweiterung eigene Symbol, auch kein Problemm hier ist die Code
Visual Basic-Quellcode
- Dim objSubKey As Microsoft.Win32.RegistryKey
- Dim objSubKey2 As Microsoft.Win32.RegistryKey
- Dim Wert As String = "Dein Name"
- Dim sKey As String = ".deine Endung"
- Dim sKey2 As String = ".deine Endung\ShellNew"
- Dim sEntry As String = "Content Type"
- Dim sValue As String = "text/plain"
- Dim sEntry2 As String = "PerceivedType"
- Dim sValue2 As String = "text"
- Dim sEntry3 As String = "Nullfile"
- objSubKey = My.Computer.Registry.ClassesRoot.CreateSubKey(sKey)
- objSubKey.SetValue("", Wert)
- objSubKey.SetValue(sEntry, sValue)
- objSubKey.SetValue(sEntry2, sValue2)
- objSubKey2 = My.Computer.Registry.ClassesRoot.CreateSubKey(sKey2)
- objSubKey2.SetValue(sEntry3, "")
- Dim objSubKey3 As Microsoft.Win32.RegistryKey
- Dim sKey3 As String = "Dein Name"
- Dim sKey4 As String = "Dein Name\shell\open\command"
- Dim skey5 As String = "Dein Name\DefaultIcon"
- Dim sValue3 As String = "Dein Name"
- Dim objSubKey5 As Microsoft.Win32.RegistryKey
- Dim sValue5 As String = """" + My.Application.Info.DirectoryPath + "" + ""der Pfad der exe mit dem es geöffnet werden soll"" + " %1"
- Dim sValue6 As String = """" + My.Application.Info.DirectoryPath + "pfad zum icon.ico" + """"
- Dim objSubKey4 As Microsoft.Win32.RegistryKey
- objSubKey3 = My.Computer.Registry.ClassesRoot.CreateSubKey(sKey3)
- objSubKey3.SetValue("", sValue3)
- objSubKey4 = My.Computer.Registry.ClassesRoot.CreateSubKey(sKey4)
- objSubKey4.SetValue("", sValue5)
- objSubKey5 = My.Computer.Registry.ClassesRoot.CreateSubKey(skey5)
- objSubKey5.SetValue("", sValue6)
Viel Spaß damit!!
PS:BITTE KEINE ANTWORT !!!!
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Agent“ ()