|
Хотите знать, какая раскладка
клавиатуры у любой программы, запущенной в
данный момент? Будь то Microsoft Word, простейший
Блокнот или любая программа для редактирования
текстов. Теперь нет ничего проще. Благодаря
форуму http://bbs.vbstreets.ru и
человеку, ответившему на этот вопрос, вы можете
использовать этот пример в своих программах. Прежде
всего, вам понадобится модуль из ранее
опубликованного примера "Поиск hwnd процесса на
панели задач", ну а на основной форме
добавьте элемент CommandButton. '---КОД МОДУЛЯ---
Private Declare Function EnumWindows& Lib "user32" (ByVal lpEnumFunc As
Long, ByVal lParam 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 IsWindowVisible& Lib "user32" (ByVal hwnd As Long)
Private Declare Function GetParent& Lib "user32" (ByVal hwnd As Long)
Dim sPattern As String, hFind As Long
Function EnumWinProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim k As Long, sName As String
If IsWindowVisible(hwnd) And GetParent(hwnd) = 0 Then
sName = Space$(128)
k = GetWindowText(hwnd, sName, 128)
If k > 0 Then
sName = Left$(sName, k)
If lParam = 0 Then sName = UCase(sName)
If sName Like sPattern Then
hFind = hwnd
EnumWinProc = 0
Exit Function
End If
End If
End If
EnumWinProc = 1
End Function
Public Function FindWindowWild(sWild As String, Optional bMatchCase As Boolean = True) As
Long
sPattern = sWild
If Not bMatchCase Then sPattern = UCase(sPattern)
EnumWindows AddressOf EnumWinProc, bMatchCase
FindWindowWild = hFind
End Function
'---КОД ФОРМЫ---
Private Declare Function GetKeyboardLayout Lib "user32" (ByVal dwLayout As Long)
As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As
Long, lpdwProcessId As Long) As Long
Private 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
Private Const LOCALE_SENGLANGUAGE = &H1001
Public Function GetLanguageInfo(ByVal hwnd As Long) As String
Dim sReturn As String, nRet As Long
Dim pID As Long, tId As Long, LCID As Long
tId = GetWindowThreadProcessId(hwnd, pID)
LCID = LoWord(GetKeyboardLayout(tId))
sReturn = String$(128, 0)
nRet = GetLocaleInfo(LCID, LOCALE_SENGLANGUAGE, sReturn, Len(sReturn))
If nRet > 0 Then GetLanguageInfo = Left$(sReturn, nRet - 1)
End Function
Public 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 Sub Command1_Click()
'MsgBox GetLanguageInfo(FindWindowWild("FineReader*", False))
MsgBox GetLanguageInfo(FindWindowWild("Microsoft Word*", False))
End Sub
|
|