110,534
社区成员
发帖
与我相关
我的任务
分享
Imports System.Runtime.InteropServices
Imports System.Net
Imports System.IO
Imports System.Text
Public Class Form1
Private Const WM_SETTEXT As Integer = &HC
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
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 FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As IntPtr, ByVal hWnd2 As IntPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As IntPtr
Private Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As IntPtr, ByVal lpEnumFunc As EnumChildProcCallback, ByVal lParam As Integer) As Integer
Private Delegate Function EnumChildProcCallback(ByVal hWnd As IntPtr, ByVal lParam As Integer) As Boolean
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
Dim s As String
Private Function EnumChildProc(ByVal hWnd As IntPtr, ByVal lParam As Integer) As Boolean
Dim A As New StringBuilder(255)
GetClassName(hWnd, A, 256)
If UCase(A.ToString) = "EDIT" Then
s = A.ToString
End If
EnumChildProc = True
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Parenthwd As New IntPtr()
Parenthwd = FindWindow("Notepad", vbNullString)
Dim d As IntPtr
EnumChildWindows(Parenthwd, New EnumChildProcCallback(AddressOf EnumChildProc), 0)
d = FindWindowEx(Parenthwd, IntPtr.Zero, s, vbNullString)
SendMessage(d, WM_SETTEXT, 0, TextBox1.Text)
End Sub
Private Function FindPID() As Integer
For Each PR As Process In Process.GetProcesses
If PR.ProcessName = "notepad" Then
Return PR.Id
End If
Next
End Function
End Class