home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form frmInput
- Caption = "Input State Viewer"
- ClientHeight = 3000
- ClientLeft = 2340
- ClientTop = 2055
- ClientWidth = 3885
- LinkTopic = "Form1"
- PaletteMode = 1 'UseZOrder
- ScaleHeight = 3000
- ScaleWidth = 3885
- Begin VB.CommandButton cmdAttach
- Caption = "Detach"
- Height = 315
- Index = 1
- Left = 120
- TabIndex = 13
- Top = 2580
- Width = 1275
- End
- Begin VB.CommandButton cmdAttach
- Caption = "Attach"
- Height = 315
- Index = 0
- Left = 120
- TabIndex = 12
- Top = 2280
- Width = 1275
- End
- Begin VB.Timer tmrDelayOp
- Enabled = 0 'False
- Left = 3300
- Top = 1440
- End
- Begin VB.TextBox txtDelay
- Height = 285
- Left = 2940
- TabIndex = 10
- Text = "0"
- Top = 2280
- Width = 855
- End
- Begin VB.CommandButton cmdSet
- Caption = "Set Foreground"
- Height = 315
- Index = 2
- Left = 1440
- TabIndex = 9
- Top = 2580
- Width = 1335
- End
- Begin VB.CommandButton cmdSet
- Caption = "Set Active"
- Height = 315
- Index = 1
- Left = 1440
- TabIndex = 8
- Top = 2280
- Width = 1335
- End
- Begin VB.CommandButton cmdSet
- Caption = "Set Focus"
- Height = 315
- Index = 0
- Left = 1440
- TabIndex = 7
- Top = 1980
- Width = 1335
- End
- Begin VB.TextBox txtSet
- Height = 285
- Left = 120
- TabIndex = 6
- Top = 1980
- Width = 1275
- End
- Begin VB.Timer Timer1
- Interval = 500
- Left = 3300
- Top = 780
- End
- Begin VB.TextBox Text2
- Height = 315
- Left = 2100
- TabIndex = 1
- Text = "Text2"
- Top = 420
- Width = 1455
- End
- Begin VB.TextBox Text1
- Height = 315
- Left = 180
- TabIndex = 0
- Text = "Text1"
- Top = 420
- Width = 1515
- End
- Begin VB.Label Label1
- Caption = "Delay:"
- Height = 195
- Left = 2940
- TabIndex = 11
- Top = 1980
- Width = 855
- End
- Begin VB.Label lblForm
- Caption = "Label1"
- Height = 255
- Left = 180
- TabIndex = 5
- Top = 120
- Width = 3375
- End
- Begin VB.Label lblForeground
- Height = 255
- Left = 180
- TabIndex = 4
- Top = 1560
- Width = 3495
- End
- Begin VB.Label lblActive
- Height = 255
- Left = 180
- TabIndex = 3
- Top = 1200
- Width = 3495
- End
- Begin VB.Label lblFocus
- Height = 255
- Left = 180
- TabIndex = 2
- Top = 840
- Width = 3495
- End
- Attribute VB_Name = "frmInput"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- ' Copyright
- 1997 Desaware Inc. All Rights Reserved
- Option Explicit
- Dim OpToDo%
- Dim WndToDo&
- Private Declare Function AttachThreadInput Lib "user32" (ByVal idAttach As Long, ByVal idAttachTo As Long, ByVal fAttach As Long) As Long
- Private Declare Function GetActiveWindow Lib "user32" () As Long
- Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long
- Private Declare Function GetFocus Lib "user32" () As Long
- Private Declare Function GetForegroundWindow Lib "user32" () As Long
- Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
- Private Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long
- Private Declare Function SetFocusAPI Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
- Private Declare Function SetActiveWindow Lib "user32" (ByVal hwnd As Long) As Long
- Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
- Private Sub cmdAttach_Click(Index As Integer)
- Dim wnd&
- Dim dl&
- Dim pid&
- Dim destid&
- Dim fAttach%
- wnd = Val(txtSet.Text)
- destid& = GetWindowThreadProcessId(wnd, pid)
- ' Make sure values are valid
- ' Note the need to compare with zero!
- If destid& = 0 Or IsWindow(wnd) = 0 Then
- MsgBox "Invalid hWnd"
- Exit Sub
- End If
- If Index = 0 Then fAttach = True
- dl& = AttachThreadInput(destid&, GetCurrentThreadId(), fAttach)
- If dl& Then
- MsgBox "Operation succeeded"
- Else
- MsgBox "Operation failed"
- End If
- End Sub
- Private Sub cmdSet_Click(Index As Integer)
- Dim UseDelay&
- WndToDo = Val(txtSet.Text)
- OpToDo = Index
- UseDelay = Val(txtDelay.Text)
- If UseDelay <> 0 Then
- tmrDelayOp.Interval = UseDelay * 1000
- tmrDelayOp.Enabled = True
- Else
- DoOperation
- End If
-
- End Sub
- Private Sub Form_Load()
- Text1.Text = Str$(Text1.hwnd)
- Text2.Text = Str$(Text2.hwnd)
- lblForm.Caption = Str$(hwnd)
- End Sub
- Private Sub Timer1_Timer()
- lblActive = "Active Window: " & Str$(GetActiveWindow())
- lblFocus = "Focus Window: " & Str$(GetFocus())
- lblForeground = "Foreground Window: " & Str$(GetForegroundWindow())
- End Sub
- Public Sub DoOperation()
- Dim dl&
- Select Case OpToDo
- Case 0
- dl& = SetFocusAPI(WndToDo)
- Case 1
- dl& = SetActiveWindow(WndToDo)
- Case 2
- dl& = SetForegroundWindow(WndToDo)
- End Select
- tmrDelayOp.Enabled = False ' Make sure timer is off
- End Sub
- Private Sub tmrDelayOp_Timer()
- DoOperation
- End Sub
-