1

サーバー上で特定の [OK] ダイアログを探すタイマーが winforms にあります (メモリ不足のサード パーティ製アプリケーションで [OK] をクリックしてから再起動します。他に回避策はありません)。したがって、サーバーとリモートデスクトップウィンドウをリモートデスクトップすると、アクティブになります(実際のリモートデスクトップウィンドウはアクティブであり、クリックする必要がある[OK]を持つ実際のウィンドウではありません。 OK、動作します)、プログラムは正常に動作します。OKのウィンドウを見つけたら、OKボタンをクリックします。リモート デスクトップではない場合、またはリモート デスクトップ ウィンドウがアクティブでない (または選択されていない) 場合、ウィンドウが検出され、[OK] ボタンが表示されますが、[OK] ボタンをクリックできません。

そこで、タイマーで [OK] をクリックするために使用しているものを次に示します。

Private Sub TimerCloseOK_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerCloseOK.Tick
    Dim dialogBoxText As String = "My Program - Application Error"
    Dim hwnd As IntPtr = FindWindow("#32770", dialogBoxText)
    Dim WindowID As String = hwnd.ToString
    Dim buttonTitle As String
    buttonTitle = "OK"
    Dim dialogButtonHandle As IntPtr = FindWindowEx(hwnd, IntPtr.Zero, "Button", "OK")
    If Len(WindowID) > 0 And Integer.Parse(WindowID) <> 0 Then
        'CLICK OK
        SendMessage(dialogButtonHandle, BM_CLICK, 1, 0)
        mbCounter = mbCounter + 1
        Application.DoEvents()
        lCount.Text = mbCounter
    End If
End Sub
4

1 に答える 1

0

これはどうですか?

dim control1 as Control = Control.FromHandle(hwnd)
dim button1 as Button = TryCast(control1, Button)
If button1 IsNot Nothing Then button1.PerformClick()

編集: プロジェクトに属する Windows.Forms.Button で ButtonClick を実行すると仮定します (それ以外の場合Control.FromHandleは、有効なハンドルに対しても何も返しません)。

于 2012-06-11T09:56:25.027 に答える