Friend Class Form1
Inherits System.Windows.Forms.Form
Private Declare Function GetKeyboardLayoutName Lib "user32" Alias "GetKeyboardLayoutNameA" (ByVal pwszKLID As String) As Integer
Private Declare Function LoadKeyboardLayout Lib "user32" Alias "LoadKeyboardLayoutA" (ByVal pwszKLID As String, ByVal flags As Integer) As Integer
Private Declare Function GetLastError Lib "kernel32" () As Integer
Const KLF_ACTIVATE As Integer = &H1
Const Lang_AR_SAU As String = "00000401" 'Arabic
Const Lang_EN_USA As String = "00000409" 'English
Const Lang_FR_FRA As String = "0000040C" 'French
Private Sub Command3_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command3.Click
Me.Text = CStr(SetKbLayout(Lang_FR_FRA))
End Sub
Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click
Me.Text = CStr(SetKbLayout(Lang_EN_USA))
End Sub
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
Me.Text = CStr(SetKbLayout(Lang_AR_SAU))
End Sub
Public Function SetKbLayout(ByRef strLocaleId As String) As Boolean
On Error Resume Next
Dim strLocId As String 'used to retrieve current KeyboardLayout
strLocId = New String(Chr(0), 9)
GetKeyboardLayoutName(strLocId)
If strLocId = (strLocaleId & Chr(0)) Then
SetKbLayout = True
Exit Function
Else
strLocId = New String(Chr(0), 9)
strLocId = CStr(LoadKeyboardLayout(strLocaleId & Chr(0), KLF_ACTIVATE))
End If
GetKeyboardLayoutName(strLocId)
If strLocId = (strLocaleId) Then SetKbLayout = True
End Function
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
Command1.Text = "Arabic"
Command2.Text = "English"
Command3.Text = "French"
End Sub
End Class