Make your own free website on Tripod.com
Check For Language Layout Change

Author: Arkadiy Olovyannikov

Run this code. When you will change the language setting (the little "En" blue square in your status bar) the program will tell you to which language you've switched.

Module Code

Declare Function CallNextHookEx Lib "user32" _
   (ByVal hHook As Long, ByVal ncode As Long, _
   ByVal wParam As Long, lParam As Any) As Long

Declare Function SetWindowsHookEx Lib "user32" _
  Alias "SetWindowsHookExA" (ByVal idHook As Long, _
  ByVal lpfn As Long, ByVal hmod As Long, _
  ByVal dwThreadId As Long) As Long

Declare Function UnhookWindowsHookEx Lib _
  "user32" (ByVal hHook As Long) As Long

Declare Function GetLocaleInfo Lib "kernel32" _
  Alias "GetLocaleInfoA" (ByVal Locale As Long, _
  ByVal LCType As Long, ByVal lpLCData As String, _
  ByVal cchData As Long) As Long

Public Const WH_SHELL = 10

Public Const HSHELL_LANGUAGE = 8

Public Const LOCALE_ILANGUAGE             As Long = &H1
Public Const LOCALE_SLANGUAGE             As Long = &H2
Public Const LOCALE_SENGLANGUAGE          As Long = &H1001
Public Const LOCALE_SABBREVLANGNAME       As Long = &H3
Public Const LOCALE_SCOUNTRY              As Long = &H6
Public Const LOCALE_SENGCOUNTRY           As Long = &H1002
Public Const LOCALE_SABBREVCTRYNAME       As Long = &H7

Public hHook As Long

Public Function ShellHookProc(ByVal idHook As Long, _
      ByVal wParam As Long, ByVal lParam As Long) As Long
    If idHook = HSHELL_LANGUAGE Then
       Dim LocID As Long
       LocID = LoWord(lParam)
       Form1.Cls
' You can use other LOCALE_ const to get localized names of
' language/country
       Form1.Print "Language ID ", _
         GetlanguageInfo(LocID, LOCALE_ILANGUAGE)
       Form1.Print "Language ", GetlanguageInfo(LocID, _
         LOCALE_SENGLANGUAGE)
       Form1.Print "Country ", GetlanguageInfo(LocID, _
         LOCALE_SENGCOUNTRY)
    End If
    ShellHookProc = CallNextHookEx(hHook, idHook, wParam, _
       ByVal lParam)
End Function

Private Function LoWord(DWORD As Long) As Integer
   If DWORD And &H8000& Then
      LoWord = &H8000 Or (DWORD And &H7FFF&)
   Else
      LoWord = DWORD And &HFFFF&
   End If
End Function

Private Function GetlanguageInfo(ByVal dwLocaleID As Long, _
     ByVal dwLCType As Long) As String
   Dim sReturn As String, nRet As Long
   sReturn = String$(128, 0)
   nRet = GetLocaleInfo(dwLocaleID, dwLCType, sReturn, _
       Len(sReturn))
   GetlanguageInfo = Left$(sReturn, nRet - 1)
End Function

Form Code

Private Sub Form_Load()
  hHook = SetWindowsHookEx(WH_SHELL, AddressOf ShellHookProc, 0&, 0&)
End Sub

Private Sub Form_Unload(Cancel As Integer)
   If hHook Then UnhookWindowsHookEx hHook
End Sub

Go Back