Author: dchapyshev
Date: Tue Apr 22 14:01:56 2008
New Revision: 33106
URL:
http://svn.reactos.org/svn/reactos?rev=33106&view=rev
Log:
- Keyboard layout switching works now in ReactOS!
Modified:
trunk/reactos/base/applications/kbswitch/kbswitch.c
trunk/reactos/base/applications/kbswitch/kbswitch.h
Modified: trunk/reactos/base/applications/kbswitch/kbswitch.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/kbswitch…
==============================================================================
--- trunk/reactos/base/applications/kbswitch/kbswitch.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/kbswitch/kbswitch.c [iso-8859-1] Tue Apr 22 14:01:56
2008
@@ -9,7 +9,6 @@
#include "kbswitch.h"
#define WM_NOTIFYICONMSG (WM_USER + 248)
-#define BUFSIZE 256
HINSTANCE hInst;
HWND hwnd;
@@ -48,14 +47,14 @@
{
DWORD dwBufLen;
HKEY hKey;
- TCHAR szTempLCID[CCH_LAYOUT_ID + 1];
+ TCHAR szTempLCID[MAX_PATH];
// Get the Layout ID
if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Preload"), 0,
KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
{
- dwBufLen = sizeof(szTempLCID);
-
- if(RegQueryValueEx(hKey, szLayoutNum, NULL, NULL, (LPBYTE)szTempLCID,
&dwBufLen) != ERROR_SUCCESS)
+ dwBufLen = MAX_PATH;
+
+ if (RegQueryValueEx(hKey, szLayoutNum, NULL, NULL, (LPBYTE)szTempLCID,
&dwBufLen) != ERROR_SUCCESS)
{
RegCloseKey(hKey);
return FALSE;
@@ -65,11 +64,11 @@
}
// Look for a substitude of this layout
- if(RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Substitutes"), 0,
KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
- {
- dwBufLen = sizeof(szTempLCID);
-
- if(RegQueryValueEx(hKey, szTempLCID, NULL, NULL, (LPBYTE)szLCID, &dwBufLen)
!= ERROR_SUCCESS)
+ if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Substitutes"), 0,
KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
+ {
+ dwBufLen = MAX_PATH;
+
+ if (RegQueryValueEx(hKey, szTempLCID, NULL, NULL, (LPBYTE)szLCID, &dwBufLen)
!= ERROR_SUCCESS)
{
// No substitute found, then use the old LCID
lstrcpy(szLCID, szTempLCID);
@@ -97,11 +96,11 @@
if(!GetLayoutID(szLayoutNum, szLCID))
return FALSE;
- wsprintf(szBuf, _T("SYSTEM\\CurrentControlSet\\Control\\Keyboard
Layouts\\%s"), szLCID);
+ _stprintf(szBuf, _T("SYSTEM\\CurrentControlSet\\Control\\Keyboard
Layouts\\%s"), szLCID);
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, (LPCTSTR)szBuf, 0, KEY_QUERY_VALUE, &hKey)
== ERROR_SUCCESS)
{
- dwBufLen = MAX_PATH * sizeof(TCHAR);
+ dwBufLen = MAX_PATH;
if(RegQueryValueEx(hKey, _T("Layout Text"), NULL, NULL, (LPBYTE)szName,
&dwBufLen) != ERROR_SUCCESS)
{
@@ -113,6 +112,13 @@
}
return TRUE;
+}
+
+BOOL CALLBACK
+EnumWindowsProc(HWND hwnd, LPARAM lParam)
+{
+ SendMessage(hwnd, WM_INPUTLANGCHANGEREQUEST, 0, lParam);
+ return TRUE;
}
static VOID
@@ -121,14 +127,13 @@
HKL hKl;
TCHAR szLayoutNum[CCH_ULONG_DEC + 1];
TCHAR szLCID[CCH_LAYOUT_ID + 1];
- DWORD Ret;
_ultot(uLayoutNum, szLayoutNum, 10);
GetLayoutID(szLayoutNum, szLCID);
// Switch to the new keyboard layout
hKl = LoadKeyboardLayout(szLCID, KLF_ACTIVATE);
- Ret = SystemParametersInfo(SPI_SETDEFAULTINPUTLANG, 0, &hKl,
SPIF_SENDWININICHANGE);
+ EnumWindows(EnumWindowsProc, (LPARAM) hKl);
}
static HMENU
@@ -137,7 +142,7 @@
HMENU hMenu;
HKEY hKey;
DWORD dwIndex, dwSize;
- LPTSTR szExit;
+ TCHAR szExit[MAX_PATH];
TCHAR szLayoutNum[CCH_ULONG_DEC + 1];
TCHAR szName[MAX_PATH];
@@ -160,7 +165,7 @@
RegCloseKey(hKey);
}
- LoadString(hInst, IDS_EXIT, (LPTSTR)&szExit, 0);
+ LoadString(hInst, IDS_EXIT, szExit, MAX_PATH);
AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
AppendMenu(hMenu, MF_STRING, MENU_ID_EXIT, szExit);
@@ -230,11 +235,11 @@
WndClass.hCursor = NULL;
WndClass.hbrBackground = NULL;
WndClass.lpszMenuName = NULL;
- WndClass.lpszClassName = L"kbswitch";
+ WndClass.lpszClassName = _T("kbswitch");
if (!RegisterClass(&WndClass)) return 0;
- hwnd = CreateWindow(L"kbswitch", L"kbswitch", 0, 0, 0, 1, 1,
HWND_DESKTOP, NULL, hInstance, NULL);
+ hwnd = CreateWindow(_T("kbswitch"), _T("kbswitch"), 0, 0, 0, 1,
1, HWND_DESKTOP, NULL, hInstance, NULL);
while(GetMessage(&msg,NULL,0,0))
{
Modified: trunk/reactos/base/applications/kbswitch/kbswitch.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/kbswitch…
==============================================================================
--- trunk/reactos/base/applications/kbswitch/kbswitch.h [iso-8859-1] (original)
+++ trunk/reactos/base/applications/kbswitch/kbswitch.h [iso-8859-1] Tue Apr 22 14:01:56
2008
@@ -1,3 +1,4 @@
+#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <tchar.h>