Crea un nuovo progetto, aggiungi 3 CommandButton e chiamali:
cmdSwitch, cmdRefresh e cmdExit
Aggiungi pure un controllo ListBox e chiamalo lstApp
copia, incolla e prova:
codice:
Const WS_MINIMIZE = &H20000000
Const HWND_TOP = 0
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_SHOWWINDOW = &H40
Const GW_HWNDFIRST = 0
Const GW_HWNDNEXT = 2
Const GWL_STYLE = (-16)
Const SW_RESTORE = 9
Dim IsTask As Long
Const WS_VISIBLE = &H10000000
Const WS_BORDER = &H800000
Const WS_CLIPSIBLINGS = &H4000000
Const WS_THICKFRAME = &H40000
Const WS_GROUP = &H20000
Const WS_TABSTOP = &H10000
Private Declare Function ShowWindow Lib "User32" _
(ByVal hWnd As Long, ByVal flgs As Long) As Long
Private Declare Function GetWindow Lib "User32" _
(ByVal hWnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowWord Lib "User32" _
(ByVal hWnd As Long, ByVal wIndx 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 GetWindowText Lib "User32" Alias "GetWindowTextA" _
(ByVal hWnd As Long, ByVal lpSting As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetWindowTextLength Lib "User32" Alias "GetWindowTextLengthA" _
(ByVal hWnd As Long) As Long
Private Declare Function SetWindowPos Lib "User32" (ByVal hWnd As Long, _
ByVal insaft As Long, ByVal x%, ByVal y%, ByVal cx%, ByVal cy%, _
ByVal flgs As Long) As Long
Private Declare Function GetModuleFileName Lib "kernel32" Alias _
"GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName _
As String, ByVal nSize As Long) As Long
Sub cmdExit_Click()
Unload Me
Set Activate = Nothing
End Sub
Sub cmdRefresh_Click()
FindAllApps
End Sub
Sub cmdSwitch_Click()
Dim hWnd As Long
Dim x As Long
Dim lngWW As Long
If lstApp.ListIndex < 0 Then Beep: Exit Sub
hWnd = lstApp.ItemData(lstApp.ListIndex)
lngWW = GetWindowLong(hWnd, GWL_STYLE)
If lngWW And WS_MINIMIZE Then
x = ShowWindow(hWnd, SW_RESTORE)
End If
x = SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, _
SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW)
End Sub
Sub FindAllApps()
Dim hwCurr As Long
Dim intLen As Long
Dim strTitle As String
Dim NomeFile As String
Dim lung As Long
Dim prova As String
lstApp.Clear
hwCurr = GetWindow(Me.hWnd, GW_HWNDFIRST)
Do While hwCurr
If hwCurr <> Me.hWnd And TaskWindow(hwCurr) Then
intLen = GetWindowTextLength(hwCurr) + 1
strTitle = Space$(intLen)
intLen = GetWindowText(hwCurr, strTitle, intLen)
lung = GetModuleFileName(hwCurr, NomeFile, 100)
prova = NomeFile
If intLen > 0 Then
lstApp.AddItem strTitle & lung
lstApp.ItemData(lstApp.NewIndex) = hwCurr
End If
End If
hwCurr = GetWindow(hwCurr, GW_HWNDNEXT)
Loop
End Sub
Sub Form_Load()
IsTask = WS_VISIBLE Or WS_BORDER
FindAllApps
End Sub
Sub Form_Paint()
FindAllApps
End Sub
Sub lstApp_DblClick()
cmdSwitch.Value = True
End Sub
Function TaskWindow(hwCurr As Long) As Long
Dim lngStyle As Long
lngStyle = GetWindowLong(hwCurr, GWL_STYLE)
If (lngStyle And IsTask) = IsTask Then TaskWindow = True
End Function
fammi un fischio se non funziona.