![]() |
#2
睿翼2012-03-27 20:10
|

'获得窗体的句柄
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