【VB API】API获得记事本编辑框文本的问题
我编写了一个API获得记事本编辑框文本的小程序,但是句柄获得成功,但是文本确不能获得,求教各位高手。代码如下:程序代码:
'获得窗体的句柄 Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long '获得窗体的文本 Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long Private Const WM_SETTEXT = &HC Private Sub Command1_Click() Dim WindowHandle As Long Dim sBuffer As String WindowHandle = FindWindow(vbNullString, "新建文本文档 (2).txt - 记事本") Text1.Text = WindowHandle '显示记事本窗体句柄,显示正确 sBuffer = Space(255) GetWindowText WindowHandle, sBuffer, 255 Text2.Text = sBuffer '此处结果为记事本的标题,显示正确 Ehwnd = FindWindowEx(WindowHandle, 0, "Edit", vbNullString) Text3.Text = Ehwnd '显示记事本编辑框的句柄,显示正确 sBuffer = Space(255) GetWindowText Ehwnd, sBuffer, 255 Text4.Text = sBuffer '此处结果为空,什么都没有,问题出现在这里 End Sub