Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Visual Basic 6 - Declere new key
Forum - Visual Basic 6 - Declere new key

Avatar
marco1 (Normal User)
Pro


Messaggi: 157
Iscritto: 12/02/2009

Segnala al moderatore
Postato alle 15:00
Venerdė, 24/07/2009
Io, per dichiarare nuovi tipi di file, in rete ho trovato questo:

Codice sorgente - presumibilmente VB.NET

  1. Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
  2. Private Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long
  3. 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
  4.  
  5. 'Purpose     :  Creates a file association for a give file extension.
  6. 'Inputs      :  sAppExtension                   The file extension to associate.
  7. '               sApplicationPath                The name of the file to open the specified files with.
  8. '               sDescription                    The description of the file type eg. "Excel Workbook".
  9. '               sIconPath                       The path to the file where the icon is stored.
  10. '               [sIconIndex]                    The index of the icon within the path. If not specified
  11. '                                               uses the first icon.
  12. 'Outputs     :  Returns True on success
  13. 'Author      :  Andrew Baker
  14. 'Date        :  30/01/2001 11:29
  15. 'Notes       :  If updating an existing value, you may need to restart the computer before the
  16. '               changes take effect.
  17. '               Example usage:
  18. '               bResult = FileAssociationCreate(".txt", "notepad.exe", "A Notepad File")
  19. 'Revisions   :
  20.  
  21. Public Function FileAssociationCreate(sAppExtension As String, sApplicationPath As String, sDescription As String, Optional ByVal sIconPath As String, Optional sIconIndex As String = ",1") As Boolean
  22.     Dim bResult As Boolean, sKeyName As String
  23.     Const HKEY_CLASSES_ROOT = &H80000000
  24.    
  25.     If Len(sIconPath) = 0 Then
  26.         'Use the application file for the icon
  27.         sIconPath = sApplicationPath
  28.     End If
  29.     'Write associations into registry
  30.     sKeyName = Right$(sAppExtension, 3) & "file"
  31.     bResult = zRegistryCreateKey(HKEY_CLASSES_ROOT, sAppExtension, sKeyName)
  32.     bResult = bResult And zRegistryCreateKey(HKEY_CLASSES_ROOT, sKeyName & "\DefaultIcon", sIconPath & sIconIndex)
  33.     bResult = bResult And zRegistryCreateKey(HKEY_CLASSES_ROOT, sKeyName, sDescription)
  34.     bResult = bResult And zRegistryCreateKey(HKEY_CLASSES_ROOT, sKeyName & "\shell\open\command", sApplicationPath & " %1")
  35.     FileAssociationCreate = bResult
  36. End Function
  37.  
  38. 'Purpose     :  Creates a key or sets an existing keys value in the registry
  39. 'Inputs      :  lRootKey                    A constant specifying which part of the registry to
  40. '                                           write to, eg. HKEY_CLASSES_ROOT
  41. '               sRegPath                    The path to write the value of the key to.
  42. '               sValue                      The value of the key.
  43. 'Outputs     :
  44. 'Author      :  Andrew Baker
  45. 'Date        :  30/01/2001 11:53
  46. 'Notes       :  Used by FileAssociationCreate
  47. 'Revisions   :
  48.  
  49. Private Function zRegistryCreateKey(lRootKey As Long, sRegPath As String, sValue As String) As Boolean
  50.     Dim lhwnKey As Long
  51.     Dim lRetVal As Long
  52.     Const REG_SZ = 1
  53.    
  54.     On Error GoTo ErrFailed
  55.    
  56.     lRetVal = RegCreateKey(lRootKey, sRegPath, lhwnKey)
  57.     If lRetVal = 0 Then
  58.         'Successfully created/opened the key
  59.         'Write value
  60.         lRetVal = RegSetValueEx(lhwnKey, "", 0, REG_SZ, ByVal sValue, Len(sValue))
  61.         'Close key
  62.         lRetVal = RegCloseKey(lhwnKey)
  63.     End If
  64.     zRegistryCreateKey = (lRetVal = 0)
  65.     Exit Function
  66.  
  67. ErrFailed:
  68.     zRegistryCreateKey = False
  69. End Function



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

in questa funzione :

Codice sorgente - presumibilmente VB.NET

  1. 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:

Codice sorgente - presumibilmente VB.NET

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



nn capisco cosa voglono le variabili
sIconPath e sIconIndex

chi saprebbe aiutarmi???

PM Quote
Avatar
GrG (Member)
Guru^2


Messaggi: 3430
Iscritto: 21/08/2007

Segnala al moderatore
Postato alle 15:06
Venerdė, 24/07/2009
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

PM Quote
Avatar
marco1 (Normal User)
Pro


Messaggi: 157
Iscritto: 12/02/2009

Segnala al moderatore
Postato alle 15:11
Venerdė, 24/07/2009
...ho provato "a" ... ma mi viene sempe l'icona stile System... quella di un semflice file binario...

PM Quote
Avatar
marco1 (Normal User)
Pro


Messaggi: 157
Iscritto: 12/02/2009

Segnala al moderatore
Postato alle 17:43
Venerdė, 24/07/2009
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???

PM Quote
Avatar
GrG (Member)
Guru^2


Messaggi: 3430
Iscritto: 21/08/2007

Segnala al moderatore
Postato alle 17:56
Venerdė, 24/07/2009
Testo quotato

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ė:
Codice sorgente - presumibilmente VB.NET

  1. if command <> "" then
  2. dim Path as string
  3. Path = command
  4. 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 il 24/07/2009 alle 18:14
PM Quote
Avatar
marco1 (Normal User)
Pro


Messaggi: 157
Iscritto: 12/02/2009

Segnala al moderatore
Postato alle 18:33
Venerdė, 24/07/2009
Ha funzionato... hai ragione... non ho riavviato il PC pero mi sono accorto che prima aveva dei problemi grafici... grazie...

PM Quote
Avatar
GrG (Member)
Guru^2


Messaggi: 3430
Iscritto: 21/08/2007

Segnala al moderatore
Postato alle 19:03
Venerdė, 24/07/2009
Testo quotato

Postato originariamente da marco1:
mi sono accorto che prima aveva dei problemi grafici...



Ma quindi li hai risolti o li hai ancora?

PM Quote
Avatar
marco1 (Normal User)
Pro


Messaggi: 157
Iscritto: 12/02/2009

Segnala al moderatore
Postato alle 16:04
Lunedė, 27/07/2009
nono... ho risolto tutto... prima non aveva aggornato le finestre perche si era un'po incastrato... :rofl:  :rofl: :rofl:

PM Quote
Avatar
GrG (Member)
Guru^2


Messaggi: 3430
Iscritto: 21/08/2007

Segnala al moderatore
Postato alle 17:01
Lunedė, 27/07/2009
:):):)

Ok, ci sentiamo al prossimo problema xD

PM Quote