Ich benutze beruflich fast ausschliesslich C#, weshalb ich keine praktischen Erfahrungen mit White
in VB.NET gemacht habe.
Hier mal eine eben zusammengeflickte SW zum Steuern von Calc.
Du musst nur vorher die Core Assembly als referenz einbinden.
Imports Core.UIItems
Imports Core.UIItems.WindowItems
Public Class Form1
Inherits System.Windows.Forms.Form
Public Sub New()
InitializeComponent()
End Sub
Private m_CalcProcess As Process
Private m_Application As Core.Application
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button1.Click
Dim info As System.Diagnostics.ProcessStartInfo = New _
System.Diagnostics.ProcessStartInfo("calc.exe")
info.WorkingDirectory = "."
m_Application = Core.Application.Launch(info)
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As _
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If (m_Application IsNot Nothing) Then
m_Application.Kill()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button2.Click
Dim calc As CalcApp = CalcApp.FromTitle("Rechner", m_Application)
calc.TwoButton().Click()
calc.MultiplyButton().Click()
calc.TwoButton().Click()
calc.OKButton().Click()
Label1.Text = calc.ResultTextBox.Text
End Sub
'Das Formular überschreibt den Löschvorgang, um die Komponentenliste zu
' bereinigen.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Wird vom Windows Form-Designer benötigt.
Private components As System.ComponentModel.IContainer
'Hinweis: Die folgende Prozedur ist für den Windows Form-Designer
' erforderlich.
'Das Bearbeiten ist mit dem Windows Form-Designer möglich.
'Das Bearbeiten mit dem Code-Editor ist nicht möglich.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.Button2 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(12, 12)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(107, 23)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Starte Rechner"
Me.Button1.UseVisualStyleBackColor = True
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(142, 55)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(39, 13)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Label1"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(12, 55)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(107, 23)
Me.Button2.TabIndex = 2
Me.Button2.Text = "Berechne 2 * 2"
Me.Button2.UseVisualStyleBackColor = True
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(218, 92)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Button2 As System.Windows.Forms.Button
End Class
Public Class CalcApp
Protected m_Window As Window
Protected m_Cache As New Dictionary(Of String, UIItem)
Public Sub New(ByVal window As Window)
m_Window = window
End Sub
Protected Function GetItem(Of T As UIItem)(ByVal name As String) As T
If Not m_Cache.ContainsKey(name) Then
m_Cache.Add(name, m_Window.Get(Of T)(name))
End If
Return m_Cache(name)
End Function
Default Public ReadOnly Property Button(ByVal Index As String) As _
Core.UIItems.Button
Get
Return GetItem(Of Core.UIItems.Button)(Index)
End Get
End Property
Public ReadOnly Property OKButton() As Core.UIItems.Button
Get
Return GetItem(Of Core.UIItems.Button)("=")
End Get
End Property
Public ReadOnly Property MultiplyButton() As Core.UIItems.Button
Get
Return GetItem(Of Core.UIItems.Button)("*")
End Get
End Property
Public ReadOnly Property TwoButton() As Core.UIItems.Button
Get
Return GetItem(Of Core.UIItems.Button)("2")
End Get
End Property
Public ReadOnly Property ResultTextBox() As Core.UIItems.TextBox
Get
Return GetItem(Of Core.UIItems.TextBox)("")
End Get
End Property
Public Shared Function FromTitle(ByVal Title As String, ByVal application _
As Core.Application) As CalcApp
Dim windows As List(Of Window) = application.GetWindows()
Dim win = From window In windows Where window.Title = Title
If (win IsNot Nothing) Then
Return New CalcApp(win(0))
End If
Return Nothing
End Function
End Class |