Click here to copy the following block | Option Explicit
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
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 GetWindow Lib "user32.dll" (ByVal hWnd As Long, ByVal wCmd As Long) As Long Private Declare Function GetWindowWord Lib "user32.dll" (ByVal hWnd As Long, ByVal nIndex As Long) As Integer Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Private Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long Private Declare Function SetWindowPos Lib "user32.dll" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long Private Declare Function ShowWindow Lib "user32.dll" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long |
Click here to copy the following block | Public Type TASK_STRUCT TaskName As String TaskID As Long End Type
Public TaskList(1000) As TASK_STRUCT Public NumTasks As Long
Public Function IsTask(hwndTask As Long) As Boolean Dim WndStyle As Long Const IsTaskStyle = WS_VISIBLE Or WS_BORDER
WndStyle = GetWindowLong(hwndTask, GWL_STYLE) If (WndStyle And IsTaskStyle) = IsTaskStyle Then IsTask = True End Function
Public Sub FillTaskList(hWnd As Long) Dim hwndTask As Long Dim intLen As Long Dim strTitle As String Dim cnt As Integer
cnt = 0 hwndTask = GetWindow(hWnd, GW_HWNDFIRST) Do While hwndTask If hwndTask <> hWnd And IsTask(hwndTask) Then intLen = GetWindowTextLength(hwndTask) + 1 strTitle = Space(intLen) intLen = GetWindowText(hwndTask, strTitle, intLen) If intLen > 0 Then TaskList(cnt).TaskName = strTitle TaskList(cnt).TaskID = hwndTask cnt = cnt + 1 End If End If hwndTask = GetWindow(hwndTask, GW_HWNDNEXT) Loop NumTasks = cnt End Sub
Public Sub SwitchTo(hWnd As Long) Dim ret As Long Dim WStyle As Long
WStyle = GetWindowLong(hWnd, GWL_STYLE) If WStyle And WS_MINIMIZE Then ret = ShowWindow(hWnd, SW_RESTORE) End If ret = SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW) End Sub |
Click here to copy the following block |
Option Explicit
Sub cmdExit_Click() Unload Me End Sub
Sub cmdRefresh_Click() Dim i As Integer
lstApp.Clear FillTaskList Me.hWnd For i = 0 To NumTasks - 1 lstApp.AddItem TaskList(i).TaskName lstApp.ItemData(lstApp.NewIndex) = TaskList(i).TaskID Next End Sub
Sub cmdSwitch_Click() Dim hWnd As Long
If lstApp.ListIndex < 0 Then Beep: Exit Sub hWnd = lstApp.ItemData(lstApp.ListIndex) SwitchTo hWnd End Sub
Sub Form_Load() cmdRefresh.Value = True End Sub
Sub lstApp_DblClick() cmdSwitch.Value = True End Sub |
|