home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / task / tswitch.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-12-27  |  6.8 KB  |  155 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Task Switch"
  5.    ClientHeight    =   3720
  6.    ClientLeft      =   3045
  7.    ClientTop       =   2145
  8.    ClientWidth     =   3930
  9.    Height          =   4125
  10.    Icon            =   "TSwitch.frx":0000
  11.    Left            =   2985
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   3720
  16.    ScaleWidth      =   3930
  17.    ShowInTaskbar   =   0   'False
  18.    Top             =   1800
  19.    Width           =   4050
  20.    Begin VB.ListBox lstApp 
  21.       Height          =   2985
  22.       Left            =   0
  23.       TabIndex        =   3
  24.       Top             =   0
  25.       Width           =   3855
  26.    End
  27.    Begin VB.CommandButton cmdExit 
  28.       Caption         =   "&Exit"
  29.       Height          =   495
  30.       Left            =   2640
  31.       TabIndex        =   2
  32.       Top             =   3120
  33.       Width           =   1215
  34.    End
  35.    Begin VB.CommandButton cmdSwitch 
  36.       Caption         =   "&Switch"
  37.       Height          =   495
  38.       Left            =   1320
  39.       TabIndex        =   1
  40.       Top             =   3120
  41.       Width           =   1215
  42.    End
  43.    Begin VB.CommandButton cmdRefresh 
  44.       Caption         =   "&Refresh"
  45.       Height          =   495
  46.       Left            =   0
  47.       TabIndex        =   0
  48.       Top             =   3120
  49.       Width           =   1215
  50.    End
  51. Attribute VB_Name = "Form1"
  52. Attribute VB_Creatable = False
  53. Attribute VB_Exposed = False
  54. Option Explicit
  55. 'WIN16/32 Directive
  56. #If Win16 Then
  57.     Declare Function ShowWindow Lib "User" (ByVal hWnd As Integer, ByVal flgs As Integer) As Integer
  58.     Declare Function GetWindow Lib "User" (ByVal hWnd As Integer, ByVal wCmd As Integer) As Integer
  59.     Declare Function GetWindowWord Lib "User" (ByVal hWnd As Integer, ByVal wIndx As Integer) As Integer
  60.     Declare Function GetWindowLong Lib "User" (ByVal hWnd As Integer, ByVal wIndx As Integer) As Long
  61.     Declare Function GetWindowText Lib "User" (ByVal hWnd As Integer, ByVal lpSting As String, ByVal nMaxCount As Integer) As Integer
  62.     Declare Function GetWindowTextLength Lib "User" (ByVal hWnd As Integer) As Integer
  63.     Declare Function SetWindowPos Lib "User" (ByVal hWnd As Integer, ByVal insaft As Integer, ByVal x%, ByVal y%, ByVal cx%, ByVal cy%, ByVal flgs As Integer) As Integer
  64. #Else
  65.     Private Declare Function ShowWindow Lib "User32" (ByVal hWnd As Long, ByVal flgs As Long) As Long
  66.     Private Declare Function GetWindow Lib "User32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
  67.     Private Declare Function GetWindowWord Lib "User32" (ByVal hWnd As Long, ByVal wIndx As Long) As Long
  68.     Private Declare Function GetWindowLong Lib "User32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal wIndx As Long) As Long
  69.     Private Declare Function GetWindowText Lib "User32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpSting As String, ByVal nMaxCount As Long) As Long
  70.     Private Declare Function GetWindowTextLength Lib "User32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
  71.     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
  72. #End If
  73. Const WS_MINIMIZE = &H20000000  ' Style bit 'is minimized'
  74. Const HWND_TOP = 0              ' Move to top of z-order
  75. Const SWP_NOSIZE = &H1          ' Do not re-size window
  76. Const SWP_NOMOVE = &H2          ' Do not reposition window
  77. Const SWP_SHOWWINDOW = &H40     ' Make window visible/active
  78. Const GW_HWNDFIRST = 0          ' Get first Window handle
  79. Const GW_HWNDNEXT = 2           ' Get next window handle
  80. Const GWL_STYLE = (-16)         ' Get Window's style bits
  81. Const SW_RESTORE = 9            ' Restore window
  82. Dim IsTask As Long              ' Style bits for normal task
  83. ' The following bits will be combined to define properties
  84. ' of a 'normal' task top-level window.  Any window with ' these set will be
  85. ' included in the list:
  86. Const WS_VISIBLE = &H10000000      ' Window is not hidden
  87. Const WS_BORDER = &H800000         ' Window has a border
  88. ' Other bits that are normally set include:
  89. Const WS_CLIPSIBLINGS = &H4000000  ' can clip windows
  90. Const WS_THICKFRAME = &H40000      ' Window has thick border
  91. Const WS_GROUP = &H20000           ' Window is top of group
  92. Const WS_TABSTOP = &H10000         ' Window has tabstop
  93. Sub cmdExit_Click()
  94. Unload Me               ' Get me out of here!
  95. 'Set Me = Nothing  ' Kill Form reference for good measure
  96. End Sub
  97. Sub cmdRefresh_Click()
  98. FindAllApps  ' Update list of tasks
  99. End Sub
  100.                Sub cmdSwitch_Click()
  101.                Dim hWnd As Long    ' handle to window
  102.                Dim x As Long          ' work area
  103.                Dim lngWW As Long      ' Window Style bits
  104.                If lstApp.ListIndex < 0 Then Beep: Exit Sub
  105.                ' Get window handle from listbox array
  106.                hWnd = lstApp.ItemData(lstApp.ListIndex)
  107.                ' Get style bits for window
  108.                lngWW = GetWindowLong(hWnd, GWL_STYLE)
  109.                ' If minimized do a restore
  110.                If lngWW And WS_MINIMIZE Then
  111.                        x = ShowWindow(hWnd, SW_RESTORE)
  112.                End If
  113.                ' Move window to top of z-order/activate; no move/resize
  114.                x = SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, _
  115.                        SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW)
  116.                End Sub
  117. Sub FindAllApps()
  118. Dim hwCurr As Long
  119. Dim intLen As Long
  120. Dim strTitle As String
  121. ' process all top-level windows in master window list
  122. lstApp.Clear
  123. hwCurr = GetWindow(Me.hWnd, GW_HWNDFIRST)  ' get first window
  124. Do While hwCurr  ' repeat for all windows
  125.   If hwCurr <> Me.hWnd And TaskWindow(hwCurr) Then
  126.     intLen = GetWindowTextLength(hwCurr) + 1 ' Get length
  127.     strTitle = Space$(intLen) ' Get caption
  128.     intLen = GetWindowText(hwCurr, strTitle, intLen)
  129.     If intLen > 0 Then ' If we have anything, add it
  130.       lstApp.AddItem strTitle
  131. ' and let's save the window handle in the itemdata array
  132.       lstApp.ItemData(lstApp.NewIndex) = hwCurr
  133.     End If
  134.   End If
  135.   hwCurr = GetWindow(hwCurr, GW_HWNDNEXT)
  136. End Sub
  137. Sub Form_Load()
  138. IsTask = WS_VISIBLE Or WS_BORDER  ' Define bits for normal task
  139. FindAllApps                       ' Update list
  140. End Sub
  141.                Sub Form_Paint()
  142.                FindAllApps  ' Update List
  143.                End Sub
  144. Sub Label1_Click()
  145. FindAllApps  ' Update list
  146. End Sub
  147.                Sub lstApp_DblClick()
  148.                cmdSwitch.Value = True
  149.                End Sub
  150. Function TaskWindow(hwCurr As Long) As Long
  151. Dim lngStyle As Long
  152. lngStyle = GetWindowLong(hwCurr, GWL_STYLE)
  153. If (lngStyle And IsTask) = IsTask Then TaskWindow = True
  154. End Function
  155.