Private Sub handleTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles handleTimer.Tick
If Me.handleWatch.ElapsedMilliseconds < Me.Timeout Then
Me.Hook.TargetHandle = NativeMethods.FindWindow(Me._dialogueClassName, Me.dialogueTitle)
If Me.Hook.TargetHandle <> IntPtr.Zero Then
Me.handleTimer.Stop()
Me.Hook.SetHook()
Me.ProcessHookedDialogue()
End If
Else
'The target window was not found within the timeout period.
Me.handleTimer.Stop()
MessageBox.Show(String.Format("The RMS '{0}' dialogue was not found.", _
Me.DialogueTitle), _
"Dialogue Not Found", _
MessageBoxButtons.OK, _
MessageBoxIcon.Error)
Me.DialogResult = System.Windows.Forms.DialogResult.Abort
End If
End Sub
Protected Overrides Sub ProcessHookedDialogue()
MyBase.ProcessHookedDialogue()
If Me.AutoLogin Then
Dim dialogueHandle As IntPtr = Me.Hook.TargetHandle
'Get the handles of the user ID and password fields and the OK button.
Dim userIDFieldHandle As IntPtr = NativeMethods.FindWindowEx(dialogueHandle, _
IntPtr.Zero, _
My.Resources.RmsTextBoxClassNameString, _
String.Empty)
Dim passwordFieldHandle As IntPtr = NativeMethods.FindWindowEx(dialogueHandle, _
userIDFieldHandle, _
My.Resources.RmsTextBoxClassNameString, _
String.Empty)
Dim frameHandle As IntPtr = NativeMethods.FindWindowEx(dialogueHandle, _
IntPtr.Zero, _
My.Resources.RmsFrameClassNameString, _
String.Empty)
Dim okButtonHandle As IntPtr = NativeMethods.FindWindowEx(frameHandle, _
IntPtr.Zero, _
My.Resources.RmsButtonClassNameString, _
"OK")
If userIDFieldHandle <> IntPtr.Zero Then
'Enter the user ID.
NativeMethods.SendMessage(userIDFieldHandle, _
NativeConstants.WM_SETTEXT, _
0, _
Me.userID)
End If
If passwordFieldHandle <> IntPtr.Zero Then
'Enter the password.
NativeMethods.SendMessage(passwordFieldHandle, _
NativeConstants.WM_SETTEXT, _
0, _
Me.password)
End If
If okButtonHandle <> IntPtr.Zero Then
'Click the OK button.
NativeMethods.SendMessage(okButtonHandle, _
NativeConstants.BM_CLICK, _
0, _
0)
End If
End If
End Sub