Newsgroup: it.comp.lang.visual-basic
Titolo: Associare l'estensione del file

1. Come è possibile in VB5 associare una certa estensione ad un programma?
2. Come attribuire un'icona (diversa da quella del programma associato) ad
una certa estensione.
Ho provato a guardare nel visualizzatore API ma senza una guida sono nella
cacca.
Grazie, Roby

Ti passo un paio di consigli, presi direttamente dall'help del Borland C++
5.0, che a me sono stati molto utili. Inutile dire che ti consiglio di usare
un OCX che ti permetta di maneggiare il registro di configurazione, invece
di usare la Load & Save settings del VB.
Registering your extension is not particularly difficult but it must be done
precisely or users will never find your namespace extension. Consider the
following registry entries, some of which are required for any namespace
extension.
Namespace extensions, like all COM objects, must be registered in the CLSID
section. In addition, they also have to be "apartment aware", having the
named value ThreadingModel set to Apartment, as shown below.
HKEY_CLASSES_ROOT\CLSID\{CLSID}
HKEY_CLASSES_ROOT\CLSID\{CLSID}\InProcServer32\(default)=path\filename.dll
HKEY_CLASSES_ROOT\CLSID\{CLSID} \InProcServer32\"ThreadingModel" =
"Apartment"
If your namespace extension is going to run under a rooted Explorer, you
should add the following entries so the Open and Explorer verbs appear on
your namespace extension.
HKEY_CLASSES_ROOT\CLSID\{CLSID}\Shell\Open\Command\(default)
                  =c:\windows\explorer.exe/root,%1
HKEY_CLASSES_ROOT\CLSID\{CLSID}\Shell\Explore\Command\(default)
                  =c:\windows\explorer.exe/e,/root/%1
You can also include entries under the following key for the default icon.
HKEY_CLASSES_ROOT\CLSID\{CLSID}\DefaultIcon\(default)="path\filename.dll",Ic
onIndex
[...]
Other registry entries you should know about include those required for
putting items into MyComputer or on the Desktop. The following entries list
all the items in those two locations:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer
               \MyComputer\NameSpace
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer
               \Desktop\NameSpace
Finally, the following entry is currently required only for Windows NT but
it should always be included for future compatibility. This is the list of
extensions that the shell will load. Extensions not on this list will not be
loaded by the shell on NT.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\ShellExtensio
ns
               \Approved\{CLSID}="Extension Name"
[....Se invece ti interessa associare anche un file-viewer:]
This section shows how to register a hypothetical file viewer for "AcmeWord
Document" files with the .AWD filename extension. The file viewer is
implemented in an in-process server DLL called ACMEWRDV.DLL. The DLL has
this class identifier: 00021116-0000-0000-C000-000000000046. The program
that installs the file viewer creates the following registry entries.
HKEY_CLASSES_ROOT
    \QuickView
        \.AWD = AcmeWord Document
            \{00021117-0000-0000-C000-000000000046} = AcmeWord Document
                                                      Viewer
    \CLSID
        \{00021117-0000-0000-C000-000000000046} = AcmeWord Document
                                                  Viewer
            \InprocServer32 = c:\acmeword\acmewrdv.dll
                            = ThreadingModel = "Apartment"
The .REG file, which is an ASCII text file, contains these entries. (Note
that wrapped lines are indented on the second line.)
HKEY_CLASSES_ROOT\QuickView\.AWD = AcmeWord Document
HKEY_CLASSES_ROOT\QuickView\.AWD \{00021117-0000-0000-C000-
    000000000046} = AcmeWord Document Viewer
HKEY_CLASSES_ROOT\CLSID\{00021117-0000-0000-C000-000000000046} =
    AcmeWord Document Viewer
HKEY_CLASSES_ROOT\CLSID\{00021117-0000-0000-C000-000000000046}
    \InprocServer32 = c:\acmeword\acmewrdv.dll
                    = ThreadingModel = "Apartment"
The Quick View program uses these registry entries to associate a path with
the class identifier of a file viewer's in-process server DLL.
[...la cosa più semplice rimane invece questa:
1) ti prendi HKEY_CLASSES_ROOT e crei una chiave ".???" con un valore
predefinito di "mia_estensione";
2) sempre su HKEY_CLASSES_ROOT crei un'altra chiave "mia_estensione" e ci
ficchi dentro le altre sottochiavi: DefaultIcon (se ti interessa un'icona
diversa da quella del programma con cui apri) e, soprattutto, shell; a sua
volta divisa in open, print,ecc.. a loro volta con la sottochiave "command"
3) in HKEY_CLASSES_ROOT/mia.estensione/shell/open/command metti la stringa
di comando che ti interessa.
].