精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● VB和Basic>>〓〓..各种开发技巧..〓〓>>算法、技巧和其他>>新写:输入法专题 (精)

主题:新写:输入法专题 (精)
发信人: bcrun(网狐)
整理人: winsy(2003-03-05 16:32:51), 站内信件
 详细内容文件:
http://free.newease.com/vbjia/down/vbime.zip
摘录如下:

VERSION 5.00
Begin VB.Form frmMain 
   Caption         =   "输入法操作演示"
   ClientHeight    =   3360
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4875
   LinkTopic       =   "Form1"
   ScaleHeight     =   3360
   ScaleWidth      =   4875
   StartUpPosition =   2  '屏幕中心
   Begin VB.CommandButton Command1 
      Caption         =   "关于..."
      Height          =   390
      Left            =   3645
      TabIndex        =   3
      Top             =   225
      Width           =   855
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   765
      TabIndex        =   1
      Text            =   "Text1"
      Top             =   1965
      Width           =   3015
   End
   Begin VB.ComboBox Combo1 
      Height          =   300
      Left            =   765
      Style           =   2  'Dropdown List
      TabIndex        =   0
      Top             =   915
      Width           =   3015
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "输入测试框:"
      Height          =   180
      Left            =   765
      TabIndex        =   2
      Top             =   1635
      Width           =   990
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'参考文献:CSDN中“取得目前所有的输入法”的示例
'例1:取得目前所有的输入法
Private Declare Function GetKeyboardLayoutList Lib "user32" _
        (ByVal nBuff As Long, lpList 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 Declare Function ImmIsIME Lib "imm32.dll" (ByVal HKL As Long) As Long
'ActivateKeyboardLayout激活一个新的键盘布局。键盘布局定义了按键在一种物理性键盘上的位置与含义
'此函数第二个参数的意义我尚未看懂,姑且设为0
Private Declare Function ActivateKeyboardLayout Lib "user32" _
        (ByVal HKL As Long, ByVal flags As Long) As Long
Private Declare Function GetKeyboardLayout Lib "user32" _
        (ByVal dwLayout As Long) As Long
Dim hKB(24) As Long, BuffLen As Long

Private Sub Combo1_Click()
ActivateKeyboardLayout hKB(Combo1.ItemData(Combo1.ListIndex)), 0

End Sub

Private Sub Command1_Click()
frmAbout.Show , Me
End Sub

Private Sub Form_Load()
Dim NoOfKBDLayout As Long, i As Long, j As Long
'Dim hKB(24) As Long, BuffLen As Long
Dim Buff As String
Dim RetStr As String
Dim RetCount As Long
'Form2.Show

Buff = String(255, 0)
'hCurKBDLayout得到本线程键盘布局的句柄
hCurKBDLayout = GetKeyboardLayout(0) '取得目前keyboard layout
'NoOfKBDLayout,装载到内存的键盘布局的数量
NoOfKBDLayout = GetKeyboardLayoutList(25, hKB(0)) '取得所有输入法的hkeys
For i = 1 To NoOfKBDLayout
   If ImmIsIME(hKB(i - 1)) = 1 Then '中文输入法
      BuffLen = 255
      RetCount = ImmGetDescription(hKB(i - 1), Buff, BuffLen)
      RetStr = Left(Buff, RetCount)
      Combo1.AddItem RetStr
      Combo1.ItemData(Combo1.NewIndex) = i - 1
   Else
      RetStr = "英语(美国)" '"English (American)"   '假设我们的win95非Ime 者只有English
      Combo1.AddItem RetStr           '若有其他者,要去取得keyboardLayout
      Combo1.ItemData(Combo1.NewIndex) = i - 1
   End If                             ' Name再去Registry中找其对应的名称
   If hKB(i - 1) = hCurKBDLayout Then
      Combo1.Text = RetStr
   End If
Next
'ActivateKeyboardLayout hKB(5), 2 '恢复原来输入法
End Sub




Public Function GetIMENo(Str1 As String) As Long
'此函数目的为取得名称中包括Str1(如"五笔")的第一个输入法以便切换
End Function



----
==================================
网名:网狐
程序:中手
来自:www.vbgood.com
      vbyes.ccoo.com (论坛)
==================================

[关闭][返回]