.net随笔-vb.net打开外部程序发送键盘信号(3)
生活随笔
收集整理的這篇文章主要介紹了
.net随笔-vb.net打开外部程序发送键盘信号(3)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
使用DllImport
Imports System.Runtime.InteropServices Public Class Form1<DllImport("user32.DLL", EntryPoint:="FindWindow")>Private Shared Function FindWindow(ByVal lpClassName As String,ByVal lpWindowName As String) As IntegerEnd FunctionPrivate Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.ClickDim hWnd As IntegerDim ProcID As Integer' 通過shell函數(shù)運(yùn)行一個(gè)新實(shí)例ProcID = Shell("CALC.EXE", AppWinStyle.NormalFocus)hWnd = FindWindow(vbNullString, "計(jì)算器")If hWnd ThenMessageBox.Show("找到計(jì)算器")ElseMessageBox.Show("沒找到計(jì)算器")End IfEnd SubEnd ClassDeclare Auto Function
Public Class Form1Private Declare Auto Function FindWindow Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntegerPrivate Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.ClickDim hWnd As IntegerDim ProcID As Integer' 通過shell函數(shù)運(yùn)行一個(gè)新實(shí)例ProcID = Shell("CALC.EXE", AppWinStyle.NormalFocus)hWnd = FindWindow(vbNullString, "計(jì)算器")If hWnd ThenMessageBox.Show("找到計(jì)算器")ElseMessageBox.Show("沒找到計(jì)算器")End IfEnd SubEnd Class Imports System.Runtime.InteropServicesPublic Class Form1Private Declare Auto Function FindWindow Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntegerPrivate Declare Auto Function FindWindowEx Lib "user32" (ByVal hWndParent As Integer, ByVal hWndChildAfter As Integer, ByVal lpszClass As String, ByVal lpszWindow As String) As IntegerPrivate Declare Auto Function SetForegroundWindow Lib "user32" (ByVal hWnd As Integer) As IntegerPrivate Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA"(ByVal hWnd As Integer, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As String) As IntegerPrivate Const WM_SETTEXT As Integer = &HCPrivate Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click' 通過shell函數(shù)運(yùn)行一個(gè)新實(shí)例Shell("notepad.EXE", AppWinStyle.NormalFocus)Dim hWnd As Integer = FindWindow(vbNullString, "無標(biāo)題 - 記事本")If hWnd ThenSendMessage(hWnd, WM_SETTEXT, 0, Trim(TextBox1.Text))Dim myhwnd As Integer = FindWindowEx(hWnd, IntPtr.Zero, "Edit", "")If myhwnd ThenSendMessage(myhwnd, WM_SETTEXT, 0, Trim(TextBox2.Text))ElseMessageBox.Show("沒找到記事本編輯")End IfElseMessageBox.Show("沒找到記事本")End IfEnd SubEnd Class總結(jié)
以上是生活随笔為你收集整理的.net随笔-vb.net打开外部程序发送键盘信号(3)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 手机在线测试黄疸软件,在家怎么用手机测黄
- 下一篇: 请求头Content-Type:appl