本文介绍了如何阅读使用消息框内容文字及QUOT; user32.dll中"功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个简单的胜利API内部C#/ vb.net,读取文本出一个消息框。我有一个函数来读取一个消息框的标题,但我不知道如何获得内容的文字。该消息框标题的功能是:

功能来检索与表单关联的弹出窗口,以及对发现弹出的子窗口...私人声明自动功能GetWindow库user32.dll中(_    BYVAL的hWnd作为IntPtr的,BYVAL uCmd长)作为IntPtr的是,用于将消息发送到上按钮'的SendMessage超载对话窗口...私人声明自动SendMessage函数库user32.dll中别名SendMessage函数_    (BYVAL的HWND作为IntPtr的,BYVAL消息作为整数,wParam参数BYVAL作为整数,_     为ByRef lParam中的IntPtr)作为IntPtr的用于检索窗口文本SendMessage函数重载...私人声明自动功能SendMessageA库user32.dll中_    别名SendMessageA(BYVAL的HWND作为IntPtr的,BYVAL消息作为整数,_        BYVAL wParam中的IntPtr,为ByRef lParam中的IntPtr)作为IntPtr的

...

'该函数返回窗口的文本,使用这样我们就可以确认我们有正确的对话窗口......私有函数GetWindowText函数(BYVAL WindowHandle作为IntPtr的)作为字符串    昏暗ptrRet作为IntPtr的    昏暗ptrLength作为IntPtr的    获取长度缓冲...    ptrLength = SendMessageA(_        WindowHandle,WM_GETTEXTLENGTH,IntPtr.Zero,IntPtr.Zero)    创建缓冲区返回值...    昏暗某人作为新System.Text.StringBuilder(ptrLength.ToInt32 + 1)    获取窗口文本...    ptrRet = SendMessageString(_        WindowHandle,WM_GETTEXT,ptrLength.ToInt32 + 1,SB)    获取返回值...    返回sb.ToString结束如果

解决方案

您可能使用了错误的窗口句柄。该文本是由在消息框中客户端窗口中显示。您可以通过PInvoke的函数GetDlgItem()获得它的手柄,通过ID 65535间谍++获得洞察构成了消息框窗口中的部分。

I need a simple win api inside c# / vb.net, to read a text out of a message box. I have a function to read a message box title, but i have no idea how to get the content text.The messagebox title function is:

' 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
解决方案

You are probably using the wrong window handle. The text is displayed by a client window inside the message box. You can get its handle by pinvoke GetDlgItem(), passing ID 65535. Use Spy++ to get insight into the parts that make up the message box window.

这篇关于如何阅读使用消息框内容文字及QUOT; user32.dll中"功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 13:06