我想知道如何将字符串发送到另一个应用程序的列表框。我已经知道怎么做但现在我遇到了另一个问题。该字符串将发送到不同的列表框或文本框。我使用的代码如下所示。我的问题是hWndChildAfter
GetWindow()
是FindWindowEx(hWndParent, hWndChildAfter, lpszClass, lpszWindow)
吗?
'Declarations/ETC
Const WM_SETTEXT As Long = &HC
Private Declare Auto Function FindWindow Lib "user32.dll" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Declare Auto Function FindWindowEx Lib "user32.dll" (ByVal hWndParent As IntPtr, ByVal hWndChildAfter As IntPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr
Declare Function GetWindow Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal uCmd As Integer) As IntPtr
Declare Function SendMessageHM Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As String) As Int32
Enum GetWindow_Cmd
GW_HWNDFIRST = 0
GW_HWNDLAST = 1
GW_HWNDNEXT = 2
GW_HWNDPREV = 3
GW_OWNER = 4
GW_CHILD = 5
GW_ENABLEDPOPUP = 6
End Enum
'Usage
Dim hWnd1 As IntPtr = FindWindow(FormClass, FormCaption)
Dim hWndR2 As IntPtr = GetWindow(hWnd1, GetWindow_Cmd.GW_CHILD)
SendMessageHM(hWndR2, WM_SETTEXT, 0, TextBox1.Text)
我想像下面的代码那样做但不会工作。
'Declarations/ETC
Const WM_SETTEXT As Long = &HC
Private Declare Auto Function FindWindow Lib "user32.dll" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Declare Auto Function FindWindowEx Lib "user32.dll" (ByVal hWndParent As IntPtr, ByVal hWndChildAfter As IntPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr
Declare Function GetWindow Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal uCmd As Integer) As IntPtr
Declare Function SendMessageHM Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As String) As Int32
Enum GetWindow_Cmd
GW_HWNDFIRST = 0
GW_HWNDLAST = 1
GW_HWNDNEXT = 2
GW_HWNDPREV = 3
GW_OWNER = 4
GW_CHILD = 5
GW_ENABLEDPOPUP = 6
End Enum
'Usage
Dim MainWindowHandle As IntPtr
Dim ChildAfter As IntPtr
Dim ListBoxHandle As IntPtr
'Get the FormHandle
MainWindowHandle = FindWindow(FormClass, FormCaption)
'Get the ChildAfter of the ListBox
ChildAfter = FindWindowEx(MainWindowHandle, IntPtr.Zero, ChildClass, ChildCaption)
'Get the handle of the ListBox
ListBoxHandle = FindWindowEx(MainWindowHandle, ChildAfter, TargetClass, TargetCaption)
'Send String to ListBox
SendMessageHM(ListBoxHandle, WM_SETTEXT, 0, TextBox1.Text)
非常感谢任何建议。