gpt4 book ai didi

c# - 如何使用 "user32.dll"函数读取消息框内容文本

转载 作者:行者123 更新时间:2023-12-04 05:48:41 25 4
gpt4 key购买 nike

我需要在 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

最佳答案

您可能使用了错误的窗口句柄。文本由消息框内的客户端窗口显示。您可以通过 pinvoke GetDlgItem() 获取其句柄,传递 ID 65535。使用 Spy++ 深入了解码成消息框窗口的部分。

关于c# - 如何使用 "user32.dll"函数读取消息框内容文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10365784/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com