如何找到應用程序中所有可用的控件。 是否可以與應用程序交互應用程序。我需要將應用程序中的值設置爲在特定控件中運行在我係統中的另一個應用程序(窗口)。通過在vb.net中傳遞進程ID來找到應用程序中的所有控件(win應用程序)
-2
A
回答
0
如果你堅持從一個應用程序的數據到你認爲可以接受的方式;數據庫,文本文件,XML。然後,一個應用程序更新持久數據存儲,另一個應用程序檢查數據存儲以獲取信息。
+0
spy ++工具將在應用程序中找到控件。但我需要在找到沒有交互數據庫的控件後設置值。並且只有一個應用程序可以處理其他或第三方應用程序,我無法訪問UI代碼。請參考以下鏈接http://msdn.microsoft.com/en-us/magazine/cc163617.aspx#S8 – Dharani 2013-03-06 06:43:47
1
該代碼將獲得與在系統中運行的進程相關的所有控制值。在此代碼中有2個文件1.ApiWindow是一個類文件和其他main()類。 Main()將使用ApiWindow類並獲取Spy ++工具的控制值。我們可以處理這些控件,並且可以使用SendMessage(child.hWnd,WM_SETTEXT,0,「Ur Value」)來設置特定控件的值。 這個hwnd將獲得句柄id,WM_SETTEXT將傳遞一條消息來更新給定的文本。聲明WM_SETTEXT爲全局變量 ,比如Const WM_SETTEXT = & HC。
注:在運行該程序使Visual集刊 「以管理員身份運行」
代碼:
Imports System.Collections.Generic
Imports System.Runtime.InteropServices
Imports System.Text
Public Class ApiWindow
Public MainWindowTitle As String = ""
Public ClassName As String = ""
Public hWnd As Int32
End Class
''' <summary>
''' Enumerate top-level and child windows
''' </summary>
''' <example>
''' Dim enumerator As New WindowsEnumerator()
''' For Each top As ApiWindow in enumerator.GetTopLevelWindows()
''' Console.WriteLine(top.MainWindowTitle)
''' For Each child As ApiWindow child in enumerator.GetChildWindows(top.hWnd)
''' Console.WriteLine(" " + child.MainWindowTitle)
''' Next child
''' Next top
''' </example>
Public Class WindowsEnumerator
Private Delegate Function EnumCallBackDelegate(ByVal hwnd As Integer, ByVal lParam As Integer) As Integer
' Top-level windows.
Private Declare Function EnumWindows Lib "user32" _
(ByVal lpEnumFunc As EnumCallBackDelegate, ByVal lParam As Integer) As Integer
' Child windows.
Private Declare Function EnumChildWindows Lib "user32" _
(ByVal hWndParent As Integer, ByVal lpEnumFunc As EnumCallBackDelegate, ByVal lParam As Integer) As Integer
' Get the window class.
Private Declare Function GetClassName _
Lib "user32" Alias "GetClassNameA" _
(ByVal hwnd As Integer, ByVal lpClassName As StringBuilder, ByVal nMaxCount As Integer) As Integer
' Test if the window is visible--only get visible ones.
Private Declare Function IsWindowVisible Lib "user32" _
(ByVal hwnd As Integer) As Integer
' Test if the window's parent--only get the one's without parents.
Private Declare Function GetParent Lib "user32" _
(ByVal hwnd As Integer) As Integer
' Get window text length signature.
Private Declare Function SendMessage _
Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
' Get window text signature.
Private Declare Function SendMessage _
Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As StringBuilder) As Int32
Private _listChildren As New List(Of ApiWindow)
Private _listTopLevel As New List(Of ApiWindow)
Private _topLevelClass As String = ""
Private _childClass As String = ""
''' <summary>
''' Get all top-level window information
''' </summary>
''' <returns>List of window information objects</returns>
Public Overloads Function GetTopLevelWindows() As List(Of ApiWindow)
EnumWindows(AddressOf EnumWindowProc, &H0)
Return _listTopLevel
End Function
Public Overloads Function GetTopLevelWindows(ByVal className As String) As List(Of ApiWindow)
_topLevelClass = className
Return Me.GetTopLevelWindows()
End Function
''' <summary>
''' Get all child windows for the specific windows handle (hwnd).
''' </summary>
''' <returns>List of child windows for parent window</returns>
Public Overloads Function GetChildWindows(ByVal hwnd As Int32) As List(Of ApiWindow)
' Clear the window list.
_listChildren = New List(Of ApiWindow)
' Start the enumeration process.
EnumChildWindows(hwnd, AddressOf EnumChildWindowProc, &H0)
' Return the children list when the process is completed.
Return _listChildren
End Function
Public Overloads Function GetChildWindows(ByVal hwnd As Int32, ByVal childClass As String) As List(Of ApiWindow)
' Set the search
_childClass = childClass
Return Me.GetChildWindows(hwnd)
End Function
''' <summary>
''' Callback function that does the work of enumerating top-level windows.
''' </summary>
''' <param name="hwnd">Discovered Window handle</param>
''' <returns>1=keep going, 0=stop</returns>
Private Function EnumWindowProc(ByVal hwnd As Int32, ByVal lParam As Int32) As Int32
' Eliminate windows that are not top-level.
If GetParent(hwnd) = 0 AndAlso CBool(IsWindowVisible(hwnd)) Then
' Get the window title/class name.
Dim window As ApiWindow = GetWindowIdentification(hwnd)
' Match the class name if searching for a specific window class.
If _topLevelClass.Length = 0 OrElse window.ClassName.ToLower() = _topLevelClass.ToLower() Then
_listTopLevel.Add(window)
End If
End If
' To continue enumeration, return True (1), and to stop enumeration
' return False (0).
' When 1 is returned, enumeration continues until there are no
' more windows left.
Return 1
End Function
''' <summary>
''' Callback function that does the work of enumerating child windows.
''' </summary>
''' <param name="hwnd">Discovered Window handle</param>
''' <returns>1=keep going, 0=stop</returns>
Private Function EnumChildWindowProc(ByVal hwnd As Int32, ByVal lParam As Int32) As Int32
Dim window As ApiWindow = GetWindowIdentification(hwnd)
' Attempt to match the child class, if one was specified, otherwise
' enumerate all the child windows.
If _childClass.Length = 0 OrElse window.ClassName.ToLower() = _childClass.ToLower() Then
_listChildren.Add(window)
End If
Return 1
End Function
''' <summary>
''' Build the ApiWindow object to hold information about the Window object.
''' </summary>
Private Function GetWindowIdentification(ByVal hwnd As Integer) As ApiWindow
Const WM_GETTEXT As Int32 = &HD
Const WM_GETTEXTLENGTH As Int32 = &HE
Dim window As New ApiWindow()
Dim title As New StringBuilder()
' Get the size of the string required to hold the window title.
Dim size As Int32 = SendMessage(hwnd, WM_GETTEXTLENGTH, 0, 0)
' If the return is 0, there is no title.
If size > 0 Then
title = New StringBuilder(size + 1)
SendMessage(hwnd, WM_GETTEXT, title.Capacity, title)
End If
' Get the class name for the window.
Dim classBuilder As New StringBuilder(64)
GetClassName(hwnd, classBuilder, 64)
' Set the properties for the ApiWindow object.
window.ClassName = classBuilder.ToString()
window.MainWindowTitle = title.ToString()
window.hWnd = hwnd
Return window
End Function
End Class
''」有Main函數類開始
Imports System.Text
Module Module1
Private Declare Function SendMessage _
Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As String) As Int32
Const WM_GETTEXT As Int32 = &HD
Const WM_GETTEXTLENGTH As Int32 = &HE
Const WM_CREATE As Int32 = &H1
Const WM_SETTEXT = &HC
Sub Main()
Static count As Integer = 0
Dim enumerator As New WindowsEnumerator()
Dim sb As New StringBuilder()
For Each top As ApiWindow In enumerator.GetTopLevelWindows
count = 0
Console.WriteLine(top.MainWindowTitle)
For Each child As ApiWindow In enumerator.GetChildWindows(top.hWnd)
Console.WriteLine(child.MainWindowTitle)
'here you can find the value of control you want and can can set the required
' count = count + 1
' If (child.MainWindowTitle.Contains("Initial value in text box")) Then
' Console.WriteLine(count.ToString)
'Console.ReadKey()
'End If
'now find the count of ur control in the sample page and set the values
' If (count = 104 And top.MainWindowTitle.Contains("Form1")) Then
'SendMessage(child.hWnd, WM_SETTEXT, 0, "required Textbox value")
' End If
Next child
Next top
Console.Read()
End Sub
End Module
相關問題
- 1. 如何通過PID查找應用程序名稱(進程ID)
- 2. 通過JavaScript中的D-click將應用程序傳遞給應用程序
- 3. 從C#/ VB.net/VC++應用程序到Java應用程序的通信過程
- 4. 通過win消息在應用程序之間進行通信
- 5. 部署VB.net 2010 Win Forms應用程序
- 6. 通過應用程序ID在OSX shell中獲取應用程序的路徑
- 7. 如何通過編程在iphone應用程序中找到UTM?
- 8. 尋找應用程序的中心 - VB.net
- 9. Android應用程序未在「所有應用程序」中顯示
- 10. 在VB.NET win應用程序中使用自定義角色
- 11. 在VB.Net中託管Silverlight應用程序WinForm應用程序
- 12. 找到原來的應用程序ID - 爲蘋果iOS應用
- 13. 如何在應用程序關閉時閱讀我應用程序中的所有應用程序通知?
- 14. 在ASP.NET MVC應用程序中通過URL傳遞參數
- 15. 在應用程序安裝過程中傳遞GET參數
- 16. 通過應用程序ID檢索與FQL的所有評論
- 17. 通過應用程序加載程序上傳應用程序時出錯
- 18. 通用收件箱應用程序顯示來自不同聊天應用程序的所有傳入消息
- 19. NSBundle pathForResource:ofType:找不到應用程序包中的所有文件
- 20. c#win應用程序
- 21. 在Angular應用程序中找不到引導程序文件
- 22. 如何通過使用.NET應用程序的過程來調試ActiveX控件?
- 23. iPhone/iPod Touch應用程序的通配符應用程序ID
- 24. 我的應用程序中的多個Facebook應用程序ID
- 25. 如何在VB.Net win表單應用程序中使用進度條
- 26. 在Win 8 Metro應用程序的App.xaml中定義應用程序欄
- 27. 通過應用程序名稱獲取所有應用程序 - TestStack.White .NET
- 28. 沒有安裝任何應用程序將數據從應用程序傳遞到應用程序
- 29. 供應配置文件中的應用程序ID用於iPhone應用程序
- 30. 如何通過命令行將iOS應用程序上傳到應用程序
其數據的類型想要粘貼? – andy 2013-03-06 04:54:17
我需要粘貼文本數據。 – Dharani 2013-03-06 05:21:47