2

メッセージ ボックスからテキストを読み取るには、c#/vb.net 内に単純な win api が必要です。メッセージ ボックスのタイトルを読み取る関数がありますが、コンテンツ テキストを取得する方法がわかりません。メッセージボックスのタイトル関数は次のとおりです。

' Function to retrieve the popup window associated with the form, as well as to
' find the child windows of the popup...
Private Declare Auto Function GetWindow Lib "user32.dll" ( _
    ByVal hWnd As IntPtr, ByVal uCmd As Long) As IntPtr

' Sendmessage overload that is used to send messages to the button on the
' dialog window...
Private Declare Auto Function SendMessage Lib "user32.dll" Alias "SendMessage" _
    (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, _
     ByRef lParam As IntPtr) As IntPtr

' Sendmessage overloads used to retrieve the window text...
Private Declare Auto Function SendMessageA Lib "user32.dll" _
    Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal Msg As Integer, _
        ByVal wParam As IntPtr, ByRef lParam As IntPtr) As IntPtr

...

' This function returns the text of the window, used so that we can confirm that
' we have the right dialog window...
Private Function GetWindowText(ByVal WindowHandle As IntPtr) As String
    Dim ptrRet As IntPtr
    Dim ptrLength As IntPtr

    ' Get length for buffer...
    ptrLength = SendMessageA( _
        WindowHandle, WM_GETTEXTLENGTH, IntPtr.Zero, IntPtr.Zero)

    ' Create buffer for return value...
    Dim sb As New System.Text.StringBuilder(ptrLength.ToInt32 + 1)

    ' Get window text...
    ptrRet = SendMessageString( _
        WindowHandle, WM_GETTEXT, ptrLength.ToInt32 + 1, sb)

    ' Get return value...
    Return sb.ToString
End If
4

1 に答える 1

3

間違ったウィンドウ ハンドルを使用している可能性があります。テキストは、メッセージ ボックス内のクライアント ウィンドウによって表示されます。GetDlgItem() を pinvoke し、ID 65535 を渡すことでハンドルを取得できます。

于 2012-04-28T17:26:10.133 に答える