Visual Basic - Api´s

Life is soft - evento anual de software empresarial
 
Vista:

Api´s

Publicado por Ismael (12 intervenciones) el 17/01/2007 16:26:00
Hola,

Alguíen sabe si utilizando las API´s de windows para seleccionar una carpeta se le puede indicar un ruta por defecto al abrirse...
El código que me pasaron hace poco es el siguiente

Option Explicit
Private Type BrowseInfo
hWndOwner As Long
pIDLRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type
Const BIF_RETURNONLYFSDIRS = 1
Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)

Function AsciiZ(texto As String) As String
' Esta función se utiliza para devolver la parte del string
' hasta el primer chr(0). Las funciones del API suelen emplear
' un chr(0) para marcar el final de las cadenas de texto
Dim i As Integer

i = InStr(texto, Chr(0))
If i = 0 Then
AsciiZ = texto
Else
AsciiZ = Left(texto, i - 1)
End If
End Function

Function Carpeta(frmVentana As Form)
Dim iNull As Integer, lpIDList As Long, lResult As Long
Dim sPath As String, udtBI As BrowseInfo

With udtBI
'Set the owner window
.hWndOwner = frmVentana.hWnd
'lstrcat appends the two strings and returns the memory address
.lpszTitle = lstrcat("C:\", Space(0))
'Return only if the user selected a directory
.ulFlags = BIF_RETURNONLYFSDIRS
End With

'Show the 'Browse for folder' dialog
lpIDList = SHBrowseForFolder(udtBI)
If lpIDList Then
sPath = String$(260, 0)
'Get the path from the IDList
SHGetPathFromIDList lpIDList, sPath
'free the block of memory
CoTaskMemFree lpIDList
sPath = AsciiZ(sPath)
End If
Carpeta = sPath
End Function

Private Sub Form_Activate()
Dim x As String

x = Carpeta(Me)
End Sub

Gracias de antemano.
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