如何获得文本框下拉框类的输入或选择的内容
请问如何实现这些功能
如何获得文本框下拉框类的输入或选择的内容,这些内容是软件运行中输入的,不是在设计时候就现存的内容
1、获得指定标题的窗体的所有按钮、文本框、下拉框等空间的名称和句柄(窗体并非处于焦点)
2、如果获得了上述窗口各输入控件的句柄, 如一个文本框,文本框里输入了几个字后,能否提取到输入的内容
不胜感激
[解决办法]
下面两个代码 请同时运行 代码2 获取或改变代码1 的Text1内容
'******************** 代码 1
Option Explicit
Private Sub Form_Load()
Text1.Text = "CBM666 到此一游"
Me.Caption = "隔岸观火"
End Sub
'********* 代码 2 用来抓代码1里面的Text1的内容
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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 Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_GETTEXT = &HD
Const WM_SETTEXT = &HC
Const WM_GETTEXTLENGTH = &HE
Dim Phwnd&, ChildHwnd&, Tmpstr$, Textlen&
Private Sub Form_Load()
Command1.Caption = "获取内容"
Command2.Caption = "改变内容"
End Sub
Private Sub Command1_Click()
Phwnd = FindWindow(vbNullString, "隔岸观火")
If Phwnd <> 0 Then
ChildHwnd = FindWindowEx(Phwnd, 0, "ThunderTextBox", vbNullString)
If ChildHwnd > 0 Then MsgBox GetText(ChildHwnd)
End If
End Sub
Private Sub Command2_Click()
Phwnd = FindWindow(vbNullString, "隔岸观火")
If Phwnd <> 0 Then
ChildHwnd = FindWindowEx(Phwnd, 0, "ThunderTextBox", vbNullString)
If ChildHwnd > 0 Then SendMessage ChildHwnd, WM_SETTEXT, 0, ByVal "123456789"
End If
End Sub
Function GetText(Thwnd As Long) As String
Textlen = SendMessage(Thwnd, WM_GETTEXTLENGTH, 0, 0)
If Textlen = 0 Then GetText = "": Exit Function
Textlen = Textlen + 1
Tmpstr = Space(Textlen)
Textlen = SendMessage(Thwnd, WM_GETTEXT, Textlen, ByVal Tmpstr)
GetText = Left(Tmpstr, Textlen)
End Function