推荐回答
Imports System.TextImports System.Runtime.InteropServicesPublic Class Form1 '' 相关API函数声明,注释掉的这里没用到,但是也比较常用吧,这些函数的功能都能搜到。 Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ByVal lpClassName As String, ByVal lpWindowName As String As IntPtr Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ByVal hWnd1 As IntPtr, ByVal hWnd2 As IntPtr, ByVal lpsz1 As String, ByVal lpsz2 As String As IntPtr Private Delegate Function EnumChildProcByVal hWnd As IntPtr, ByVal lParam As Integer As Boolean Private Declare Function EnumChildWindows Lib "user32.dll" ByVal hWndParent As IntPtr, ByVal lpEnumFunc As EnumChildProc, ByVal lParam As Integer As Boolean Private Declare Auto Function SendMessage Lib "User32.dll" ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As String As Integer ''Private Declare Function CheckDlgButton Lib "user32" Alias "CheckDLGButtonA" ByVal hDlg As IntPtr, ByVal nIDButton As IntPtr, ByVal wCheck As Integer As Integer Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" ByVal hWnd As IntPtr, ByVal lpClassName As StringBuilder, ByVal nMaxCount As Integer As Integer ''Private Declare Function GetWindowThreadProcessId Lib "user32" Alias "GetWindowThreadProcessId" ByVal hwnd As IntPtr, ByVal lpdwProcessId As Long As Integer Private Declare Auto Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLength" ByVal hwnd As IntPtr As Integer Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" ByVal hwnd As IntPtr, ByVal lpString As StringBuilder, ByVal cch As Integer As Integer '' 相关消息定义,也有没用到的 Const WM_SETTEXT = &HC Const WM_GETTEXT = &HD ''Const WM_SETFOCUS = &H7 ''Const WM_KILLFOCUS = &H8 ''Const WM_CLOSE = &H10 ''Const WM_SYSCOMMAND = &H112 ''Const SC_CLOSE = &HF060& ''Const SC_MINIMIZE = &HF020& Const BM_GETCHECK = &HF0 Const BM_SETCHECK = &HF1 Const BM_GETSTATE = &HF2 Const BM_SETSTATE = &HF3 Const BM_SETSTYLE = &HF4 Const BM_CLICK = &HF5 ''Const BM_GETIMAGE = &HF6 ''Const BM_SETIMAGE = &HF7 Const BST_UNCHECKED = &O0 Const BST_CHECKED = &O1 Const BST_INDETERMINATE = &O2 '' 储存窗口句柄 Dim WindowHandle As IntPtr '' 储存两个,枚举时自动调用回调函数,完成编辑框句柄的获取 EnumChildWindowsWindowHandle, AddressOf EnumChildProcC, 0 '' 寻找复选框 CheckHandle = FindWindowExWindowHandle, IntPtr.Zero, vbNullString, "记住密码" Dim str As New StringBuilder Dim j As Integer = 0 '' 对编辑框文本赋值 For j = 0 To EditHandle.Count - 1 SendMessageEditHandlej, WM_SETTEXT, 0, "Text" ''GetWindowTextEditHandlej, str, 20 ''EditWindowsText.AddStr.ToString ''Str.Clear Next If EditHandle.Count = 0 Then MsgBox"未找到输入框!" End If If CheckHandle.ToInt32 <> 0 Then ''CheckDlgButtonWindowHandle, id, 1 '' 对复选框进行鼠标单击操作 SendMessageCheckHandle, BM_CLICK, 0, 0 ''SendMessageCheckHandle, BM_SETCHECK, True, 0 End If End Sub End Class。
齐显影2019-12-21 18:37:59
提示您:回答为网友贡献,仅供参考。