Visual Basic Foro
Programación => Visual Basic 6 => Mensaje iniciado por: DarkStreaM en Marzo 02, 2011, 05:51:49 pm
-
Lo que deseo es Poder obtener el Nombre de una extension, por ejemplo
Cual es el nombre de "rar" o ".rar" y que devuelva "Archivo WinRAR", o ".bmp" y que devuelva "Imagen de Mapa de Bits"
Eso :o
Desde ya Gracias :P
ya lo solucione D:!
Con la API
Private Declare Function SHGetFileInfo Lib "shell32.dll" Alias "SHGetFileInfoA" (ByVal pszPath As String, ByVal dwFileAttributes As Long, psfi As SHFILEINFO, ByVal cbFileInfo As Long, ByVal uFlags As Long) As Long
Cierren el tema ;)
-
Se busca asi, supongamos *.bmp
Buscamos en HKEY_CLASSES_ROOT ".bmp" y veremos en el valor por defecto el tipo de archivo que es, y buscamos el mismo y obtenemos la descripcion.
En codigo, sera asi :P
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 RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegQueryValueExNULL Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As Long, lpcbData As Long) As Long
Private Declare Function RegQueryValueExString Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const REG_SZ As Long = 1
Private Const KEY_ALL_ACCESS = &H3F
Private Function GetDefaultValue(Extension As String) As String
Dim Handle As Long
Dim Data As String
Dim cch As Long
Call RegOpenKeyEx(HKEY_CLASSES_ROOT, Extension, 0, KEY_ALL_ACCESS, Handle)
Call RegQueryValueExNULL(Handle, vbNullString, 0&, 0&, 0&, cch)
If cch > 0 Then
Data = String$(cch - 1, 0)
Call RegQueryValueExString(Handle, vbNullString, 0&, 0&, Data, cch)
GetDefaultValue = Data
End If
Call RegCloseKey(Handle)
End Function
Private Sub Form_Load()
Debug.Print GetDefaultValue(GetDefaultValue(".jpg"))
Debug.Print GetDefaultValue(GetDefaultValue(".bmp"))
Debug.Print GetDefaultValue(GetDefaultValue(".zip"))
Debug.Print GetDefaultValue(GetDefaultValue(".wav"))
Debug.Print GetDefaultValue(GetDefaultValue(".arre")) ' Devuelve vacio, o sea que se muestra "Archivo ARRE" :|
End Sub
-
SHGetFileInfo - Obtener descripción de archivo (http://www.recursosvisualbasic.com.ar/htm/listado-api/276-shgetfileinfo.htm)