Autor Tema: Obtener el Nombre de un Tipo de Archivo  (Leído 2556 veces)

0 Usuarios y 1 Visitante están viendo este tema.

DarkStreaM

  • Bytes
  • *
  • Mensajes: 22
  • Reputación: +1/-4
  • Los Sentimientos son la fuente de todos los miedos
    • Ver Perfil
Obtener el Nombre de un Tipo de Archivo
« 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  ;)
« última modificación: Marzo 02, 2011, 06:07:04 pm por DarkStreaM »

raul338

  • Terabyte
  • *****
  • Mensajes: 894
  • Reputación: +62/-8
  • xD fan!!!!! xD
    • Ver Perfil
    • Raul's Weblog
Re:Obtener el Nombre de un Tipo de Archivo
« Respuesta #1 en: Marzo 02, 2011, 06:13:04 pm »
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

Código: (vb) [Seleccionar]
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

xkiz ™

  • Moderador Global
  • Gigabyte
  • *****
  • Mensajes: 283
  • Reputación: +30/-11
    • Ver Perfil
    • xkiz ™