FindWindowEx vrací hWndText As Long textboxu ("Edit" handle) Zde je příklad pro vb6:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String _
) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String _
) As Long
Private Declare Function SendMessageText Lib "user32" Alias "SendMessageA" ( _
ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As String _
) As Long
Private Const WM_SETTEXT As Long = &HC
Private Sub CommandButton1_Click()
Dim hWndParent As Long
Dim hWndText As Long
'Find the Notepad window
hWndParent = FindWindow("Notepad", vbNullString)
If hWndParent Then
'Find the first text box in Notepad
hWndText = FindWindowEx(hWndParent, 0, "Edit", vbNullString)
If hWndText Then
'set the text
Call SendMessageText(hWndText, WM_SETTEXT, 0, TextBox1.Text)
End If
End If
End Sub
Viz odkazy např.: http://forum.builder.cz/read.php?19,2964798 http://www.vbforums.com/showthread.php?p... vb.Net Stiskem tlačítka,obsah textboxu do schránky a poslat CTRL-V do nového notepadu Na formu je textbox1 do kterého zapsat text taky button1 a button2 s příklady dle odkazů pod příkladem :
Public Class Form1
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Then Exit Sub
Dim MyAppID
Clipboard.Clear()
Clipboard.SetText(TextBox1.Text)
MyAppID = Shell("NOTEPAD.EXE", 1)
AppActivate(MyAppID)
SendKeys.Send("^V") ' send CTRL-V
End Sub
'called in a button click
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim pInstance As Process
pInstance = GetRunningInstance("NotePad")
If Not pInstance Is Nothing Then
Dim handle As IntPtr = pInstance.MainWindowHandle
If Not IntPtr.Zero.Equals(handle) Then
FindInstance.ShowWindow(handle, 1)
FindInstance.SetForegroundWindow(handle)
pInstance.WaitForInputIdle()
End If
Else
'not found, create new instance
pInstance = System.Diagnostics.Process.Start("notepad")
pInstance.WaitForInputIdle()
End If
If Not pInstance Is Nothing And Not TextBox1.Text = "" Then
Clipboard.Clear()
Clipboard.SetText(TextBox1.Text)
SendKeys.Send("^V") ' send CTRL-V
End If
End Sub
Public Shared Function GetRunningInstance(ByVal processName As String) As Process
Dim proclist() As Process = _
Process.GetProcessesByName(processName)
For Each p As Process In proclist
If p.Id <> Process.GetCurrentProcess().Id Then
Return p
End If
Next
Return Nothing
End Function
End Class
Public NotInheritable Class FindInstance
<System.Runtime.InteropServices.DllImport("user32.dll", _
EntryPoint:="SetForegroundWindow", _
CallingConvention:=Runtime.InteropServices.CallingConvention.StdCall, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Public Shared Function _
SetForegroundWindow(ByVal handle As IntPtr) As Boolean
' Leave function empty
End Function
<System.Runtime.InteropServices.DllImport("user32.dll", _
EntryPoint:="ShowWindow", _
CallingConvention:=Runtime.InteropServices.CallingConvention.StdCall, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Public Shared Function ShowWindow(ByVal handle As IntPtr, _
ByVal nCmd As Int32) As Boolean
End Function
End Class
Viz odkazy např.: http://www.xtremevbtalk.com/showthread.p... ...a zjištění běžící instance notepadu: http://www.xtremevbtalk.com/archive/inde... jen do začátku... Mnoho zdaru!
|