In un programma scritto in VB6 uso salvare i files che lo compongono sull'HD.
La domanda è questa: E' possibile associare un'Icona (personalizzata) ai predetti files ?
Grazie per la collaborazione.![]()
In un programma scritto in VB6 uso salvare i files che lo compongono sull'HD.
La domanda è questa: E' possibile associare un'Icona (personalizzata) ai predetti files ?
Grazie per la collaborazione.![]()
LM
devi registrare l'estensione per il tuo applicativo e prendono automaticamente l'icona dell'exe
Vascello fantasma dei mentecatti nonchè baronetto della scara corona alcolica, piccolo spuccello di pezza dislessico e ubriaco- Colui che ha modificato l'orribile scritta - Gran Evacuatore Mentecatto - Tristo Mietitore Mentecatto chi usa uTonter danneggia anche te
Grazie per la risposta xegallo,
mi potresti spiegare meglio: "devi registrare l'estensione per il tuo applicativo ".
![]()
LM
Da una ricerca effettuata parrebbe che dovrei utilizzare l'API RegCreateKey.
Qualcuno ha già seguito questa strada?
LM
Ad esempio ...
codice: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 RegSetValue Lib "advapi32.dll" Alias _ "RegSetValueA" (ByVal hKey As Long, _ ByVal lpSubKey As String, _ ByVal dwType As Long, _ ByVal lpData As String, _ ByVal cbData As Long) As Long Private Const HKEY_CLASSES_ROOT = &H80000000 Private Const MAX_PATH = 260& Private Const REG_SZ = 1 Private Sub Form_Click() Dim sKeyName As String Dim sKeyValue As String Dim ret As Long Dim lphKey As Long sKeyName = "LMondiApp" sKeyValue = "Applicazione LMondi" ret = RegCreateKey(HKEY_CLASSES_ROOT, sKeyName, lphKey&) ret = RegSetValue(lphKey&, "", REG_SZ, sKeyValue, 0&) sKeyName = ".LMO" sKeyValue = "LMondiApp" ret = RegCreateKey(HKEY_CLASSES_ROOT, sKeyName, lphKey&) ret = RegSetValue(lphKey&, "", REG_SZ, sKeyValue, 0&) sKeyName = "LMondiApp" sKeyValue = "c:\progetto1.exe %1" ret = RegCreateKey(HKEY_CLASSES_ROOT, sKeyName, lphKey&) ret = RegSetValue(lphKey&, "shell\open\command", REG_SZ, sKeyValue, MAX_PATH) End Sub
oregon,
il tuo è un esempio molto chiaro; ciò nonostante mi servirebbero alcuni approfondimenti.
.. Private Sub Form_Click()
cosa significa, che devo inserire il codice in una Frm del progetto insieme alle altre che lo costituiscono e
pertanto ogni volta che il prog. viene avviato si verifica una registrazione? Non è sufficiente registrare una sola volta?
o viceversa in codice deve essere inserito in un progetto a se stante
e, quindi lanciato una sola volta?
.. In questo modo i files che vengono salvati sull'HD assumono l'icona che ho utilizzato nel progetto (per interderci: VB progettazione>Progetto>Proprietà di ...>Linguetta Crea>Applicazione: Titolo, Icona.
Come avrai capito non ho mai utilizzato l'API descritta e sono cauto perchè non vorrei creare errori nel registro.
Grazie per il tempo che mi hai dedicato.![]()
LM
Ho inserito il codice in Form_Click solo per prova ... era un esempio ...
Ovviamente tu lo dovrai inserire in una funzione da richiamare quando serve ...
Ciao oregon,
Quindi solo al primo avvio del programma.codice:"Ovviamente tu lo dovrai inserire in una funzione da richiamare quando serve"
Scusa, non sono un esperto del Reg. di Win, quindi non dare per scontato qualsiasi argomento al riguardo.
Ad esempio, attualmente all'avvio del programma controlo se esiste l'apposita cartella dati, come segue:
dovrei fare la stessa cosa per la registrazione di cui trattasi?codice:'Controlla se esiste la cartella DATI e le sottocartelle, altrimenti le crea: Dim FSO As Variant Set FSO = CreateObject("Scripting.FileSystemObject") If (FSO.FolderExists(App.Path & "\" & "DATI")) = False Then With FSO ... ... ...
![]()
LM
mmm io ho provato a farlo ma non associa nulla..![]()
Mi Trovavo questo sul PC:
Prova e Fammi Sapere Verò!codice: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![]()