Cómo hago para detectar las carpetas que tengo abiertas con el explorer y para cerrar una si quiero?
Cómo hago para detectar las carpetas que tengo abiertas con el explorer y para cerrar una si quiero?
Hola te paso el ejemplo
abrega un list1 y un command1
En un modulo
y en el formularioCódigo:Option Explicit Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal wIndx As Long) As Long Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Const GW_HWNDFIRST = 0 Private Const GW_HWNDNEXT = 2 Private Const SC_CLOSE = &HF060& Private Const WM_SYSCOMMAND = &H112 Sub ListarCarpetas(Ctrl, Form) Dim hwCurr As Long Dim intLen As Long Dim strTitle As String Ctrl.Clear hwCurr = GetWindow(Form.hwnd, GW_HWNDFIRST) Do While hwCurr If IsFolder(hwCurr) Then intLen = GetWindowTextLength(hwCurr) + 1 strTitle = Space$(intLen) intLen = GetWindowText(hwCurr, strTitle, intLen) Ctrl.AddItem strTitle End If hwCurr = GetWindow(hwCurr, GW_HWNDNEXT) Loop End Sub Public Function IsFolder(ByVal hwnd As String) As Boolean 'Devuelve el ClassName de una ventana, indicando el título de la misma Dim sClassName As String Dim nMaxCount As Long nMaxCount = 256 sClassName = Space$(256) nMaxCount = GetClassName(hwnd, sClassName, nMaxCount) If Left$(sClassName, nMaxCount) = "CabinetWClass" Then IsFolder = True End Function Public Sub CerrarCarpeta(ByVal Titulo As String) Dim hwnd As Long hwnd = FindWindow(vbNullString, Titulo) Call SendMessage(hwnd, WM_SYSCOMMAND, SC_CLOSE, ByVal 0&) End Sub
SaludosCódigo:Private Sub Command1_Click() CerrarCarpeta List1 End Sub Private Sub Form_Load() 'o en un timer para que se acutalise Call ListarCarpetas(List1, Me) End Sub