Public Class Form1 <DllImport("user32")> Private Shared Function FindWindow(lpClassName As String, lpWindowName As String) As IntPtr End Function <DllImport("user32")> Private Shared Function FindWindowEx(hWnd1 As IntPtr, hWnd2 As IntPtr, lpsz1 As String, lpsz2 As String) As IntPtr End Function <DllImport("user32")> Private Shared Function SendMessage(hWnd As IntPtr, wMsg As UInteger, wParam As Integer, lParam As String) As Long End Function Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click '起動している「メモ帳」に「こんにちは!」を書き込む Dim hNotePad As IntPtr = FindWindow("Notepad", Nothing) Dim hEdit As IntPtr = FindWindowEx(hNotePad, IntPtr.Zero, "Edit", Nothing) Const WM_SETTEXT = &HC SendMessage(hEdit, WM_SETTEXT, 0, "こんにちは!") End Sub End Class