Oppure

Loading
24/07/09 13:00
marco1
Io, per dichiarare nuovi tipi di file, in rete ho trovato questo:

Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long

'Purpose     :  Creates a file association for a give file extension.
'Inputs      :  sAppExtension                   The file extension to associate.
'               sApplicationPath                The name of the file to open the specified files with.
'               sDescription                    The description of the file type eg. "Excel Workbook".
'               sIconPath                       The path to the file where the icon is stored.
'               [sIconIndex]                    The index of the icon within the path. If not specified
'                                               uses the first icon.
'Outputs     :  Returns True on success
'Author      :  Andrew Baker
'Date        :  30/01/2001 11:29
'Notes       :  If updating an existing value, you may need to restart the computer before the
'               changes take effect.
'               Example usage:
'               bResult = FileAssociationCreate(".txt", "notepad.exe", "A Notepad File")
'Revisions   :

Public Function FileAssociationCreate(sAppExtension As String, sApplicationPath As String, sDescription As String, Optional ByVal sIconPath As String, Optional sIconIndex As String = ",1") As Boolean
    Dim bResult As Boolean, sKeyName As String
    Const HKEY_CLASSES_ROOT = &H80000000
    
    If Len(sIconPath) = 0 Then
        'Use the application file for the icon
        sIconPath = sApplicationPath
    End If
    'Write associations into registry
    sKeyName = Right$(sAppExtension, 3) & "file"
    bResult = zRegistryCreateKey(HKEY_CLASSES_ROOT, sAppExtension, sKeyName)
    bResult = bResult And zRegistryCreateKey(HKEY_CLASSES_ROOT, sKeyName & "\DefaultIcon", sIconPath & sIconIndex)
    bResult = bResult And zRegistryCreateKey(HKEY_CLASSES_ROOT, sKeyName, sDescription)
    bResult = bResult And zRegistryCreateKey(HKEY_CLASSES_ROOT, sKeyName & "\shell\open\command", sApplicationPath & " %1")
    FileAssociationCreate = bResult
End Function

'Purpose     :  Creates a key or sets an existing keys value in the registry
'Inputs      :  lRootKey                    A constant specifying which part of the registry to
'                                           write to, eg. HKEY_CLASSES_ROOT
'               sRegPath                    The path to write the value of the key to.
'               sValue                      The value of the key.
'Outputs     :
'Author      :  Andrew Baker
'Date        :  30/01/2001 11:53
'Notes       :  Used by FileAssociationCreate
'Revisions   :

Private Function zRegistryCreateKey(lRootKey As Long, sRegPath As String, sValue As String) As Boolean
    Dim lhwnKey As Long
    Dim lRetVal As Long
    Const REG_SZ = 1
    
    On Error GoTo ErrFailed
    
    lRetVal = RegCreateKey(lRootKey, sRegPath, lhwnKey)
    If lRetVal = 0 Then
        'Successfully created/opened the key
        'Write value
        lRetVal = RegSetValueEx(lhwnKey, "", 0, REG_SZ, ByVal sValue, Len(sValue))
        'Close key
        lRetVal = RegCloseKey(lhwnKey)
    End If
    zRegistryCreateKey = (lRetVal = 0)
    Exit Function

ErrFailed:
    zRegistryCreateKey = False
End Function


Che a me in VB6 funziona perfettamente... tranne le icone...

in questa funzione :

FileAssociationCreate(sAppExtension As String, sApplicationPath As String, sDescription As String, Optional ByVal sIconPath As String, Optional sIconIndex As String = ",1") As Boolean


più precisamente qui:

Optional ByVal sIconPath As String, Optional sIconIndex As String = ",1") As Boolean


nn capisco cosa voglono le variabili
sIconPath e sIconIndex

chi saprebbe aiutarmi???
aaa
24/07/09 13:06
GrG
a sIconPath devi dare il percorso dell'icona tipo "C:\tuaicona.ico" per l'sIconIndex non mi è chiarissimo sinceramente... comunque vuole un parametro tipo string prova a fargli "a" :P
aaa
24/07/09 13:11
marco1
...ho provato "a" ... ma mi viene sempe l'icona stile System... quella di un semflice file binario...
aaa
24/07/09 15:43
marco1
e in oltre il totem ha consiglato di usare questo codice per aprire il file quando
l'applicazione viene avviata da un click su uno dei suoi file:

if My.Application.CommandLineArgs.Count > 0 then
'Ci sono parametri: il primo è il percorso del file da aprire
Dim Path as string = My.Application.CommandLineArgs(0)
end if

ma mi semdra che sia x vb.net e a me servirebbe x VB6quale sarebbe la versione???
aaa
24/07/09 15:56
GrG
Postato originariamente da marco1:

e in oltre il totem ha consiglato di usare questo codice per aprire il file quando
l'applicazione viene avviata da un click su uno dei suoi file:

if My.Application.CommandLineArgs.Count > 0 then
'Ci sono parametri: il primo è il percorso del file da aprire
Dim Path as string = My.Application.CommandLineArgs(0)
end if

ma mi semdra che sia x vb.net e a me servirebbe x VB6quale sarebbe la versione???


non ne sono molto sicuro ma dovrebbe essere così:
if command <> "" then
dim Path as string
Path = command
end if


EDIT:
Comunque, riprova, non dare nessun valore a index e dopo che hai provato RIAVVIA per rendere effettive le modifiche, dovrebbe funzionare...
Ultima modifica effettuata da GrG 24/07/09 16:14
aaa
24/07/09 16:33
marco1
Ha funzionato... hai ragione... non ho riavviato il PC pero mi sono accorto che prima aveva dei problemi grafici... grazie...
aaa
24/07/09 17:03
GrG
Postato originariamente da marco1:
mi sono accorto che prima aveva dei problemi grafici...


Ma quindi li hai risolti o li hai ancora?
aaa
27/07/09 14:04
marco1
nono... ho risolto tutto... prima non aveva aggornato le finestre perche si era un'po incastrato... :rofl: :rofl: :rofl:
aaa