我正在尝试找到一种方法来识别打开文件对话框并向“文件名”字段发送消息。之后它需要向按钮发送“Enter”键或“Open”命令。
我在 VB 中这样做,但如果有人也可以在 C# 中提供帮助,我相信我可以应付。
我整天都在研究 API 并提出了几种可能性,但我不熟悉如何在 DotNet4 中实现它。我曾经在 VB6 中使用 API,但现在情况似乎有些不同了。
如果有人可以为我提供一个小例子,我将不胜感激。
我看过的一些 API 是 FindWindow 和 FindWindowEx。
编辑:
我发现了一些值得一看的代码。此代码需要在模块内部使用。当我找到更多答案时,我会发布更多内容。
Imports System.Runtime.InteropServices
Imports System.Text
Module modEnumWindows
Private windowList As New ArrayList
Private errMessage As String
Public Delegate Function MyDelegateCallBack(ByVal hwnd As Integer, ByVal lParam As Integer) As Boolean
Declare Function EnumWindows Lib "user32" (ByVal x As MyDelegateCallBack, ByVal y As Integer) As Integer
Declare Auto Function GetClassName Lib "user32" _
(ByVal hWnd As IntPtr, _
ByVal lpClassName As System.Text.StringBuilder, _
ByVal nMaxCount As Integer) As Integer
Declare Auto Function GetWindowText Lib "user32" _
(ByVal hWnd As IntPtr, _
ByVal lpClassName As System.Text.StringBuilder, _
ByVal nMaxCount As Integer) As Integer
Private Function EnumWindowProc(ByVal hwnd As Integer, ByVal lParam As Integer) As Boolean
'working vars
Dim sTitle As New StringBuilder(255)
Dim sClass As New StringBuilder(255)
Try
Call GetClassName(hwnd, sClass, 255)
Call GetWindowText(hwnd, sTitle, 255)
windowList.Add(sClass.ToString & ", " & hwnd & ", " & sTitle.ToString)
Catch ex As Exception
errMessage = ex.Message
EnumWindowProc = False
Exit Function
End Try
EnumWindowProc = True
End Function
Public Function getWindowList(ByRef wList As ArrayList, Optional ByVal errorMessage As String = "") As Boolean
windowList.Clear()
Try
Dim del As MyDelegateCallBack
del = New MyDelegateCallBack(AddressOf EnumWindowProc)
EnumWindows(del, 0)
getWindowList = True
Catch ex As Exception
getWindowList = False
errorMessage = errMessage
Exit Function
End Try
'wList.Clear()
wList = windowList
End Function
End Module
通过使用它,您将能够识别窗口文本、HWND 和类。希望这对人们有所帮助。对我来说,下一步将是确定我希望将数据发送到的字段。