Visual Basic - Ver Archivo

Life is soft - evento anual de software empresarial
 
Vista:

Ver Archivo

Publicado por Carlos (4 intervenciones) el 19/10/2004 23:02:46
No se como hacer en RunTime desde VB5 para abrir un archivo con la aplicación asociada correspondiente.
Por ejemplo, si yo utilizo el “Explorador de Windows” y voy a un archivo conocido, digamos un “.HTML” y luego hago doble click sobre el mencionado archivo, entonces se ejecuta automáticamente el “Internet Explorer” y me muestra ese archivo. ¿Hay alguna función o procedimiento que me permita hacer esto?.
Gracias
Carlos
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Ver Archivo

Publicado por miguel (1042 intervenciones) el 19/10/2004 23:55:32
El comando Shell te permite ejecutar cualquier archivo siempre y cuando tengas el sofware que le corresponde para poder ejecutarlo, ejemplo si quieres ejecutar un archivo word seria
Dim MyValue
MyValue = Shell("rundll32.exe url.dll,FileProtocolHandler " & "C:\Miguel.doc", vbMaximizedFocus)
'pdf
Dim MyValue
MyValue = Shell("rundll32.exe url.dll,FileProtocolHandler " & "C:\Miguel.pdf", vbMaximizedFocus)

Nota:Es importante poner la ruta donde se encuentra
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Gracias

Publicado por Carlos (4 intervenciones) el 20/10/2004 15:28:17
Miguel, te agradezco mucho tu respuesta
Carlos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

ShellExecuteEx (Parte 1)

Publicado por Ruri (583 intervenciones) el 20/10/2004 04:19:32
Carlos: ShellExecuteEx se utiliza para abrir cualquier tipo de archivo. Es la que utiliza el explorador de windows, pasás el nombre del archivo y la función se encarga de abrir el programa adecuado... El código es bastante largo así que te lo paso por etapas.
Abrí un nuevo módulo standar y pegá el código que está entre líneas
______________________________________________________
Option Explicit
DefLng A-Z

Public Declare Function ShellExecuteEx Lib "shell32.dll" Alias "ShellExecuteExA" (ByRef LPSHELLEXECUTEINFO As SHELLEXECUTEINFO) As Long

Public Const SEE_MASK_IDLIST As Long = &H4
Public Const SEE_MASK_INVOKEIDLIST As Long = &HC
Public Const SEE_MASK_ICON As Long = &H10
Public Const SEE_MASK_HOTKEY As Long = &H20
Public Const SEE_MASK_NOCLOSEPROCESS As Long = &H40
Public Const SEE_MASK_CONNECTNETDRV As Long = &H80
Public Const SEE_MASK_FLAG_DDEWAIT As Long = &H100
Public Const SEE_MASK_DOENVSUBST As Long = &H200
Public Const SEE_MASK_FLAG_NO_UI As Long = &H400
Public Const SEE_MASK_UNICODE As Long = &H4000
Public Const SEE_MASK_NO_CONSOLE As Long = &H8000
Public Const SEE_MASK_ASYNCOK As Long = &H100000
Public Const SEE_MASK_HMONITOR As Long = &H200000

Public Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
HWND As Long
lpVerb As String
lpFile As String
lpParameters As String
lpDirectory As String
nShow As Long
hInstApp As Long
' campos opcionales
lpIDList As Long
lpClass As String
hkeyClass As Long
dwHotKey As Long
hIcon As Long
hProcess As Long
End Type

Public Enum ShellVerb
shvEditar = 1
shvExplorar = 2
shvAbrir = 3
shvImprimir = 4
shvPropiedades = 5
End Enum

Public Enum eMostrarPrograma
mpSW_HIDE = 0
mpSW_MAXIMIZE = 3
mpSW_MINIMIZE = 6
mpSW_RESTORE = 9
mpSW_SHOW = 5
mpSW_SHOWDEFAULT = 10
mpSW_SHOWMAXIMIZED = 3
mpSW_SHOWMINIMIZED = 2
mpSW_SHOWNA = 8
mpSW_SHOWNOACTIVATE = 4
mpSW_SHOWNORMAL = 1
End Enum
________________________________________________________
Continúa en el próximo mensaje ...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Agradecimiento

Publicado por Carlos (4 intervenciones) el 20/10/2004 15:27:07
Ruri, te agradezco mucho tu respuesta
Carlos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

ShellExecuteEx (Parte 2)

Publicado por Ruri (583 intervenciones) el 20/10/2004 04:20:38
Carlos: Pegá el código que está entre líneas a continuación del anterior
______________________________________________________
Public Function ShellDoc(ByVal strRuta As String, Optional Parametros As String = "", Optional Verbo As ShellVerb = shvAbrir, Optional strDir As String = "", Optional TipoVentana As eMostrarPrograma = vbNormalFocus, Optional ByVal HWND As Long = 0) As Boolean
Dim shType As SHELLEXECUTEINFO
If strDir = "" Then strDir = DirectorioDeTrabajo(strRuta)
With shType
.cbSize = Len(shType)
.HWND = HWND
.lpDirectory = strDir
.lpFile = strRuta
.lpParameters = Parametros
If Verbo < shvEditar Or Verbo > shvPropiedades Then Verbo = shvAbrir
.lpVerb = Choose(Verbo, "edit", "explore", "open", "print", "properties")
.nShow = TipoVentana
.fMask = SEE_MASK_CONNECTNETDRV Or SEE_MASK_DOENVSUBST Or _
SEE_MASK_FLAG_DDEWAIT Or SEE_MASK_HOTKEY Or IIf(Verbo = 5, SEE_MASK_INVOKEIDLIST, 0)
End With
ShellDoc = (ShellExecuteEx(shType) <> 0)
End Function

Public Function DirectorioDeTrabajo(ByVal Ruta As String) As String
On Local Error Resume Next
Dim S() As String, e As Long
S = Split(Ruta, "\", -1, vbTextCompare)
e = ElementosDeLaMatriz(S)
If e > 0 Then
If UBound(S) > 0 Then
ReDim Preserve S(0 To (UBound(S) - 1)) As String
Else
ReDim Preserve S(0) As String
End If
DirectorioDeTrabajo = Join(S, "\")
Else
DirectorioDeTrabajo = ""
End If
Erase S
End Function

Public Function EsUnaMatrizVacia(ByRef Matriz As Variant) As Boolean
On Local Error Resume Next
Dim lng As Long
lng = UBound(Matriz)
EsUnaMatrizVacia = (Err.Number <> 0)
End Function

Public Function ElementosDeLaMatriz(ByRef Matriz As Variant) As Long
On Local Error Resume Next
If EsUnaMatrizVacia(Matriz) = True Then ElementosDeLaMatriz = 0: Exit Function
ElementosDeLaMatriz = (UBound(Matriz) - LBound(Matriz) + 1)
End Function
________________________________________________________
Continúa en el próximo mensaje ...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

ShellExecuteEx (Parte 3)

Publicado por Ruri (583 intervenciones) el 20/10/2004 04:25:28
Carlos: Ahora sólo queda llamar a la función. Desde tu formulario (o de donde sea) lo llamás así
_____________________________________________________
Dim Path as String
Path="E:\Educacion\VB6\ShellExecuteEx.pdf" 'Vos sabrás como conseguís la ruta del archivo que querés abrir

ShellDoc Path, , shvAbrir, , mpSW_SHOWNORMAL, Me.HWND
_____________________________________________________
Me.HWND es el manejador de la ventana llamante, no es necesario,puede pasarse 0

Fijate que la enumeración ShellVerb admite varias acciones como imprimir, abrir o mostrar las propiedades del programa.

Espero que te sirva
Saludos Ruri

Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar