VB关闭其他进程的输入法
新建上面的几个按钮和list,打开记事本或者win32pad,单击向记事本发送消息,程序会按ctrl+空格关闭中文输入法,并发送aaa到记事本。只适用于前台进程。
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 SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_MOUSEACTIVATE = &H21
'以下几个API用于关闭前台进程输入法:
'-------------------------------------------------------------------------------------------------------
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function GetCurrentThread Lib "kernel32" () As Long
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetKeyboardLayout Lib "user32" (ByVal dwLayout As Long) As Long
Private Declare Function ImmIsIME Lib "imm32.dll" (ByVal hkl As Long) As Long
Private Declare Function ImmGetDescription Lib "imm32.dll" Alias "ImmGetDescriptionA" (ByVal hkl As Long, ByVal lpsz As String, ByVal ubuflen As Long) As Long
'-------------------------------------------------------------------------------------------------------
Private Sub Command1_Click()
'查找记事本句柄
Dim dHwnd As Long
Dim tHwnd As Long
dHwnd = FindWindow("Notepad", vbNullString)
If dHwnd > 0 Then
tHwnd = FindWindowEx(dHwnd, ByVal 0&, "Edit", vbNullString)
End If
SetForegroundWindow tHwnd
SendMessage tHwnd, 33, 0, 0
Sleep 2000 '延迟2秒确保窗口带到前台
'以下代码把前台进程的输入法关闭:
'-------------------------------------------------------------------------------------------------------
Dim hwnd As Long
Dim hCurThread As Long
Dim sCaption As String
Dim sBuffer As String
Dim hCurKBDLayout As Long
hwnd = GetForegroundWindow
sCaption = Space(255)
GetWindowText hwnd, sCaption, 255
If InStr(sCaption, Chr(0)) Then
sCaption = Left(sCaption, InStr(sCaption, Chr(0)) - 1)
End If
hCurThread = GetWindowThreadProcessId(hwnd, ByVal 0&)
hCurKBDLayout = GetKeyboardLayout(hCurThread)
If ImmIsIME(hCurKBDLayout) = 1 Then
sBuffer = Space(255)
RetCount = ImmGetDescription(ByVal hCurKBDLayout, sBuffer, 255)
sBuffer = Left(sBuffer, InStr(sBuffer, Chr(0)) - 1)
Else
sBuffer = "English(American)"
End If
List1.AddItem "当前窗口标题:" & sCaption
List1.AddItem " 当前输入法: " & sBuffer
If sBuffer <> "English(American)" Then SendKeys "^ "
Sleep 1000 '延迟1秒确保ctrl+空格生效
'-------------------------------------------------------------------------------------------------------
SendKeys "aaa"
' MsgBox pwszKLID
End Sub
Private Sub Command2_Click()
'查找win32pad句柄
Dim dHwnd As Long
Dim tHwnd As Long
dHwnd = FindWindow("win32padClass", vbNullString)
If dHwnd > 0 Then
tHwnd = FindWindowEx(dHwnd, ByVal 0&, "RichEdit20A", vbNullString)
End If
SetForegroundWindow tHwnd '把父窗体带到前台
SendMessage tHwnd, 33, 0, 0 '把子窗体带到前台
Sleep 2000 '延迟2秒确保窗口带到前台
'以下代码把前台进程的输入法关闭:
'-------------------------------------------------------------------------------------------------------
Dim hwnd As Long
Dim hCurThread As Long
Dim sCaption As String
Dim sBuffer As String
Dim hCurKBDLayout As Long
hwnd = GetForegroundWindow
sCaption = Space(255)
GetWindowText hwnd, sCaption, 255
If InStr(sCaption, Chr(0)) Then
sCaption = Left(sCaption, InStr(sCaption, Chr(0)) - 1)
End If
hCurThread = GetWindowThreadProcessId(hwnd, ByVal 0&)
hCurKBDLayout = GetKeyboardLayout(hCurThread)
If ImmIsIME(hCurKBDLayout) = 1 Then
sBuffer = Space(255)
RetCount = ImmGetDescription(ByVal hCurKBDLayout, sBuffer, 255)
sBuffer = Left(sBuffer, InStr(sBuffer, Chr(0)) - 1)
Else
sBuffer = "English(American)"
End If
List1.AddItem "当前窗口标题:" & sCaption
List1.AddItem " 当前输入法: " & sBuffer
If sBuffer <> "English(American)" Then SendKeys "^ "
Sleep 1000 '延迟1秒确保ctrl+空格生效
'-------------------------------------------------------------------------------------------------------
SendKeys "aaa"
End Sub
Private Sub Command3_Click()
End
End Sub
VB关闭其他进程的输入法的更多相关文章
- C# 如何强制关闭WINWORD进程
private void KillProcess(string processName) //调用方法,传参{try{ Process[] thisproc = Process.GetProcesse ...
- C#关闭word进程
C#关闭word进程 foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcessesByName(&q ...
- wxPython 对话框关闭后进程无法退出的原因
wxPython中不要用对话框作为主程序wx.Dialog,这会导致程序关闭后进程无法退出.一种可行的做法是用wx.Frame代替
- vb.net 结束进程
Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click ...
- VB.net结束进程
Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click ...
- windows和linux下关闭Tomcat进程
windows和linux下解决Tomcat进程 windows下启动Tomcat报错,8080端口号被占用,报错信息如下 两种解决方法,一种是关闭了这个端口号,另外一种是修改Tomcat下的serv ...
- Mac 下 查看 使用某端口的进程和关闭该进程的命令
查看使用某端口的进程 最简单的命令是: lsof -i :端口号 如果要使用管理员权限那么就是: sudo lsof -i :端口号 所以查看 使用某端口号3000的进程可以使用: lsof -i : ...
- 彻底关闭Excle进程的几个方法
之前研究过的问题,最近有朋友问,这里再总结下做一个笔记. 我们在应用程序里面通过创建Excle应用对象打开Excle的情况下,如果不注意几个问题,可能无法彻底关闭Excle进程,来考察下面的几种情况: ...
- mac查看当前调用tcp的进程并关闭指定进程
查看所有tcp进程 监听的端口 lsof -iTCP -sTCP:LISTEN 查看指定端口信息 lsof -i: 关闭指定进程 kill -
随机推荐
- 一个简单的c# 贪吃蛇程序
一个简单的c#贪吃蛇程序 程序分为界面设计和程序设计:界面设计和程序设计均参考了一些游戏实例,但是所有代码内容是本人编写. 由于看到别人写的程序并没有署名,这里的署名全部都是csdn官网. 游戏界面设 ...
- eBox(stm32) 之中断结构
eBox的中断结构参考了mbed,和我们平时所用的中断结构有些差异,不容易理解,最近仔细看了底层代码,终于搞清楚了,总结一下 一 首先要要搞清楚的几个概念:类的静态成员,实例成员 ...
- ajax 如何接受 PHP页面返回的json数组
JSON JSON(JavaScript Object Notation)是Douglas Crockford提出的.他是一个轻量级的数据交换格式,基于JavaScript对象字面量. 我们可以将之前 ...
- icon fonts
iconfont网站 http://www.iconfont.cn(推荐) http://fontello.com/ http://fontawesome.io/ https://icomoon. ...
- Linux_scp
scp是secure copy的简写,用于在Linux下进行远程拷贝文件的命令,和它类似的命令有cp,不过cp只是在本机进行拷贝不能跨服务器,而且scp传输是加密的.可能会稍微影响一下速度.当你服务器 ...
- centos7 卸载openJDK 安装jdk7
[root@cms02 root]# rpm -qa | grep jdk java--openjdk-headless-1.7.0.75-2.5.4.2.el7_0.x86_64 java--ope ...
- 《Spark 官方文档》机器学习库(MLlib)指南
spark-2.0.2 机器学习库(MLlib)指南 MLlib是Spark的机器学习(ML)库.旨在简化机器学习的工程实践工作,并方便扩展到更大规模.MLlib由一些通用的学习算法和工具组成,包括分 ...
- 精通AngularJS 读书笔记(2)
AngularJS 速成 视图 因为AngularJS 依靠浏览器去解析模板,所以要保证模板是有效的HTML.尤其要小心闭合号HTML标签(未闭合好的标签不会产生任何错误信息,但会让视图不能正确渲染) ...
- css基础样式四
上次我们讲到了相对定位: 这次我们了解下绝对定位; 绝对定位: #box_relative { position: absolute; left: 30px; top: 20px; } 绝对定位会脱离 ...
- [原创]WKWebview点击图片查看大图
大家都知道,WKWebview是没有查看大图的属性或者方法的,所以只能通过js与之交互来实现这一功能,原理:通过js获取页面的图片,把它存放到数组,给图片添加点击事件,通过index显示大图就行了 其 ...