Author: cfinck Date: Thu Apr 24 12:57:48 2008 New Revision: 33130
URL: http://svn.reactos.org/svn/reactos?rev=33130&view=rev Log: kbswitch: - Revert some changes from r33106: * Set the size of szTempLCID back to CCH_LAYOUT_ID + 1, a layout ID mustn't be longer than this. As we pass the correct size to the Registry functions as well, there can be no buffer overflow. MAX_PATH was probably used here, because input.dll had a bug as well, so that it saved the layout ID with the wrong length. * Use wsprintf over _stprintf * Pass the correct value to dwBufLen (in bytes, not in TCHAR's!) - Add back SystemParametersInfo, so that the system gets to know about the keyboard layout change. EnumWindows is still used for setting the new keyboard layout to all existing Windows. - Don't show a different menu for left and right clicks, that's not how most popup menus work under Windows. Instead append all menu items from the menu template to the popup menu. - Call SetForegroundWindow before and post a WM_NULL message after calling TrackPopupMenu, so that the popup menu will be closed, when the user clicks somewhere else - Fix indentation
input.dll: - Fix some incorrect lengths passed to other functions - Get rid of some unneeded variables - Always use the 32-bit Registry functions over the old 16-bit deprecated ones - Fix some other stuff here and there
Modified: trunk/reactos/base/applications/kbswitch/kbswitch.c trunk/reactos/base/applications/kbswitch/lang/de-DE.rc trunk/reactos/base/applications/kbswitch/lang/en-US.rc trunk/reactos/base/applications/kbswitch/lang/ru-RU.rc trunk/reactos/base/applications/kbswitch/resource.h trunk/reactos/dll/cpl/input/add.c trunk/reactos/dll/cpl/input/input.h trunk/reactos/dll/cpl/input/settings.c
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] Thu Apr 24 12:57:48 2008 @@ -11,7 +11,7 @@ #define WM_NOTIFYICONMSG (WM_USER + 248)
HINSTANCE hInst; -HWND hwnd; +HANDLE hProcessHeap;
static VOID AddTrayIcon(HWND hwnd, HICON hIcon) @@ -46,15 +46,17 @@ GetLayoutID(LPTSTR szLayoutNum, LPTSTR szLCID) { DWORD dwBufLen; + DWORD dwRes; HKEY hKey; - TCHAR szTempLCID[MAX_PATH]; + TCHAR szTempLCID[CCH_LAYOUT_ID + 1];
// Get the Layout ID if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\Preload"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) { - dwBufLen = MAX_PATH; - - if (RegQueryValueEx(hKey, szLayoutNum, NULL, NULL, (LPBYTE)szTempLCID, &dwBufLen) != ERROR_SUCCESS) + dwBufLen = sizeof(szTempLCID); + dwRes = RegQueryValueEx(hKey, szLayoutNum, NULL, NULL, (LPBYTE)szTempLCID, &dwBufLen); + + if (dwRes != ERROR_SUCCESS) { RegCloseKey(hKey); return FALSE; @@ -66,7 +68,7 @@ // Look for a substitude of this layout if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\Substitutes"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) { - dwBufLen = MAX_PATH; + dwBufLen = sizeof(szTempLCID);
if (RegQueryValueEx(hKey, szTempLCID, NULL, NULL, (LPBYTE)szLCID, &dwBufLen) != ERROR_SUCCESS) { @@ -96,11 +98,11 @@ if(!GetLayoutID(szLayoutNum, szLCID)) return FALSE;
- _stprintf(szBuf, _T("SYSTEM\CurrentControlSet\Control\Keyboard Layouts\%s"), szLCID); + wsprintf(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; + dwBufLen = MAX_PATH * sizeof(TCHAR);
if(RegQueryValueEx(hKey, _T("Layout Text"), NULL, NULL, (LPBYTE)szName, &dwBufLen) != ERROR_SUCCESS) { @@ -133,20 +135,25 @@
// Switch to the new keyboard layout hKl = LoadKeyboardLayout(szLCID, KLF_ACTIVATE); - EnumWindows(EnumWindowsProc, (LPARAM) hKl); + SystemParametersInfo(SPI_SETDEFAULTINPUTLANG, 0, &hKl, SPIF_SENDWININICHANGE); + EnumWindows(EnumWindowsProc, (LPARAM) hKl); }
static HMENU BuildPopupMenu() { HMENU hMenu; + HMENU hMenuTemplate; HKEY hKey; DWORD dwIndex, dwSize; + LPTSTR pszMenuItem; + MENUITEMINFO mii; TCHAR szLayoutNum[CCH_ULONG_DEC + 1]; TCHAR szName[MAX_PATH];
hMenu = CreatePopupMenu();
+ // Add the keyboard layouts to the popup menu if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\Preload"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) { for(dwIndex = 0; ; dwIndex++) @@ -164,17 +171,38 @@ RegCloseKey(hKey); }
+ // Add the menu items from the popup menu template + hMenuTemplate = GetSubMenu(LoadMenu(hInst, MAKEINTRESOURCE(IDR_POPUP)), 0); + dwIndex = 0; + + mii.cbSize = sizeof(mii); + mii.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID; + mii.dwTypeData = NULL; + + while(GetMenuItemInfo(hMenuTemplate, dwIndex, TRUE, &mii)) + { + if(mii.cch > 0) + { + mii.cch++; + pszMenuItem = (LPTSTR)HeapAlloc(hProcessHeap, 0, mii.cch * sizeof(TCHAR)); + + mii.dwTypeData = pszMenuItem; + GetMenuItemInfo(hMenuTemplate, dwIndex, TRUE, &mii); + + AppendMenu(hMenu, mii.fType, mii.wID, mii.dwTypeData); + + HeapFree(hProcessHeap, 0, pszMenuItem); + mii.dwTypeData = NULL; + } + else + { + AppendMenu(hMenu, mii.fType, 0, NULL); + } + + dwIndex++; + } + return hMenu; -} - -static VOID -ShowRightPopupMenu(HWND hwnd, POINT pt) -{ - HMENU hMenu; - - hMenu = GetSubMenu(LoadMenu(hInst, MAKEINTRESOURCE(IDR_POPUP)), 0); - TrackPopupMenu(hMenu, 0, pt.x, pt.y, 0, hwnd, NULL); - DestroyMenu(hMenu); }
LRESULT CALLBACK @@ -192,54 +220,47 @@ case WM_NOTIFYICONMSG: switch (lParam) { - case WM_LBUTTONDBLCLK: case WM_LBUTTONDOWN: + case WM_RBUTTONDOWN: { POINT pt;
GetCursorPos(&pt); + SetForegroundWindow(hwnd); TrackPopupMenu(hPopupMenu, 0, pt.x, pt.y, 0, hwnd, NULL); + PostMessage(hwnd, WM_NULL, 0, 0); + break; } - break; - case WM_RBUTTONDOWN: - { - POINT pt; - - GetCursorPos(&pt); - ShowRightPopupMenu(hwnd, pt); - } - break; } break;
case WM_COMMAND: - switch (LOWORD(wParam)) - { - case ID_EXIT: - SendMessage(hwnd, WM_CLOSE, 0, 0); - break; - - case ID_PROFERENCES: - { - SHELLEXECUTEINFO shInputDll; - - memset(&shInputDll, 0x0, sizeof(SHELLEXECUTEINFO)); + switch (LOWORD(wParam)) + { + case ID_EXIT: + SendMessage(hwnd, WM_CLOSE, 0, 0); + break; + + case ID_PREFERENCES: + { + SHELLEXECUTEINFO shInputDll = {0}; + shInputDll.cbSize = sizeof(shInputDll); shInputDll.hwnd = hwnd; shInputDll.lpVerb = _T("open"); shInputDll.lpFile = _T("RunDll32.exe"); shInputDll.lpParameters = _T("shell32.dll,Control_RunDLL input.dll"); - if (ShellExecuteEx(&shInputDll) == 0) - { + + if (!ShellExecuteEx(&shInputDll)) MessageBox(hwnd, _T("Can't start input.dll"), NULL, MB_OK | MB_ICONERROR); - } - } - break; - - default: - ActivateLayout(LOWORD(wParam)); - break; - } + + break; + } + + default: + ActivateLayout(LOWORD(wParam)); + break; + } break;
case WM_DESTROY: @@ -253,12 +274,13 @@ }
INT WINAPI -wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPTSTR lpCmdLine, INT nCmdShow) +_tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPTSTR lpCmdLine, INT nCmdShow) { WNDCLASS WndClass = {0}; MSG msg;
hInst = hInstance; + hProcessHeap = GetProcessHeap();
WndClass.style = 0; WndClass.lpfnWndProc = (WNDPROC)WndProc; @@ -271,9 +293,10 @@ WndClass.lpszMenuName = NULL; WndClass.lpszClassName = _T("kbswitch");
- if (!RegisterClass(&WndClass)) return 0; - - hwnd = CreateWindow(_T("kbswitch"), _T("kbswitch"), 0, 0, 0, 1, 1, HWND_DESKTOP, NULL, hInstance, NULL); + if (!RegisterClass(&WndClass)) + return 1; + + CreateWindow(_T("kbswitch"), NULL, 0, 0, 0, 1, 1, HWND_DESKTOP, NULL, hInstance, NULL);
while(GetMessage(&msg,NULL,0,0)) {
Modified: trunk/reactos/base/applications/kbswitch/lang/de-DE.rc URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/kbswitch/... ============================================================================== --- trunk/reactos/base/applications/kbswitch/lang/de-DE.rc [iso-8859-1] (original) +++ trunk/reactos/base/applications/kbswitch/lang/de-DE.rc [iso-8859-1] Thu Apr 24 12:57:48 2008 @@ -4,8 +4,8 @@ BEGIN POPUP "popup" BEGIN - MENUITEM "&Preferences...", ID_PROFERENCES MENUITEM SEPARATOR - MENUITEM "&Beenden", ID_EXIT + MENUITEM "&Einstellungen...", ID_PREFERENCES + MENUITEM "&Beenden", ID_EXIT END END
Modified: trunk/reactos/base/applications/kbswitch/lang/en-US.rc URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/kbswitch/... ============================================================================== --- trunk/reactos/base/applications/kbswitch/lang/en-US.rc [iso-8859-1] (original) +++ trunk/reactos/base/applications/kbswitch/lang/en-US.rc [iso-8859-1] Thu Apr 24 12:57:48 2008 @@ -4,8 +4,8 @@ BEGIN POPUP "popup" BEGIN - MENUITEM "&Preferences...", ID_PROFERENCES MENUITEM SEPARATOR + MENUITEM "&Preferences...", ID_PREFERENCES MENUITEM "&Exit", ID_EXIT END END
Modified: trunk/reactos/base/applications/kbswitch/lang/ru-RU.rc URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/kbswitch/... ============================================================================== --- trunk/reactos/base/applications/kbswitch/lang/ru-RU.rc [iso-8859-1] (original) +++ trunk/reactos/base/applications/kbswitch/lang/ru-RU.rc [iso-8859-1] Thu Apr 24 12:57:48 2008 @@ -4,8 +4,8 @@ BEGIN POPUP "popup" BEGIN - MENUITEM "&Ïàðàìåòðû...", ID_PROFERENCES MENUITEM SEPARATOR + MENUITEM "&Ïàðàìåòðû...", ID_PREFERENCES MENUITEM "&Âûõîä", ID_EXIT END END
Modified: trunk/reactos/base/applications/kbswitch/resource.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/kbswitch/... ============================================================================== --- trunk/reactos/base/applications/kbswitch/resource.h [iso-8859-1] (original) +++ trunk/reactos/base/applications/kbswitch/resource.h [iso-8859-1] Thu Apr 24 12:57:48 2008 @@ -6,4 +6,4 @@
/* Menu items */ #define ID_EXIT 10001 -#define ID_PROFERENCES 10002 +#define ID_PREFERENCES 10002
Modified: trunk/reactos/dll/cpl/input/add.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/input/add.c?rev=331... ============================================================================== --- trunk/reactos/dll/cpl/input/add.c [iso-8859-1] (original) +++ trunk/reactos/dll/cpl/input/add.c [iso-8859-1] Thu Apr 24 12:57:48 2008 @@ -18,16 +18,16 @@ static VOID SelectLayoutByLang(VOID) { - TCHAR Layout[MAX_PATH], Lang[MAX_PATH], LangID[MAX_PATH]; + TCHAR Layout[MAX_PATH], Lang[MAX_PATH], LangID[CCH_LAYOUT_ID + 1]; INT iIndex; LCID Lcid;
iIndex = SendMessage(hLangList, CB_GETCURSEL, 0, 0); Lcid = SendMessage(hLangList, CB_GETITEMDATA, iIndex, 0);
- GetLocaleInfo(MAKELCID(Lcid, SORT_DEFAULT), LOCALE_ILANGUAGE, (WORD*)Lang, sizeof(Lang)); - - _stprintf(LangID, _T("0000%s"), Lang); + GetLocaleInfo(MAKELCID(Lcid, SORT_DEFAULT), LOCALE_ILANGUAGE, Lang, sizeof(Lang) / sizeof(TCHAR)); + + wsprintf(LangID, _T("0000%s"), Lang);
if (GetLayoutName(LangID, Layout)) { @@ -39,7 +39,7 @@ static VOID AddNewLayout(HWND hwndDlg) { - TCHAR NewLayout[3]; + TCHAR NewLayout[CCH_ULONG_DEC + 1]; INT iLayout; HKEY hKey; DWORD cValues; @@ -48,11 +48,11 @@ iLayout = SendMessage(hLayoutList, CB_GETCURSEL, 0, 0); if (iLayout == CB_ERR) return;
- if (RegOpenKey(HKEY_CURRENT_USER, _T("Keyboard Layout\Preload"), &hKey) == ERROR_SUCCESS) + if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\Preload"), 0, KEY_QUERY_VALUE | KEY_SET_VALUE, &hKey) == ERROR_SUCCESS) { if (RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, &cValues, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) { - _stprintf(NewLayout, _T("%d"), cValues + 1); + _ultot(cValues + 1, NewLayout, 10);
pts = (PTSTR) SendMessage(hLayoutList, CB_GETITEMDATA, iLayout, 0);
@@ -61,7 +61,7 @@ 0, REG_SZ, (LPBYTE)pts, - (DWORD)(_tcslen(pts)*sizeof(PTSTR))) == ERROR_SUCCESS) + (DWORD)((CCH_LAYOUT_ID + 1) * sizeof(TCHAR))) == ERROR_SUCCESS) { UpdateLayoutsList(); } @@ -73,47 +73,48 @@ CreateKeyboardLayoutList(VOID) { HKEY hKey, hSubKey; - PTSTR pstrBuf; - TCHAR szBuf[CCH_LAYOUT_ID + 1], KeyName[MAX_PATH]; - LONG Ret; + PTSTR pstrLayoutID; + TCHAR szLayoutID[CCH_LAYOUT_ID + 1], KeyName[MAX_PATH]; DWORD dwIndex = 0; - - if (RegOpenKey(HKEY_LOCAL_MACHINE, _T("System\CurrentControlSet\Control\Keyboard Layouts"), &hKey) == ERROR_SUCCESS) - { - Ret = RegEnumKey(hKey, dwIndex, szBuf, sizeof(szBuf) / sizeof(TCHAR)); - - while (Ret == ERROR_SUCCESS) - { - _stprintf(KeyName, _T("System\CurrentControlSet\Control\Keyboard Layouts\%s"), szBuf); - - if (RegOpenKey(HKEY_LOCAL_MACHINE, KeyName, &hSubKey) == ERROR_SUCCESS) + DWORD dwSize; + + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("System\CurrentControlSet\Control\Keyboard Layouts"), 0, KEY_ENUMERATE_SUB_KEYS, &hKey) == ERROR_SUCCESS) + { + dwSize = sizeof(szLayoutID) / sizeof(TCHAR); + + while (RegEnumKeyEx(hKey, dwIndex, szLayoutID, &dwSize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) + { + wsprintf(KeyName, _T("System\CurrentControlSet\Control\Keyboard Layouts\%s"), szLayoutID); + + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, KeyName, 0, KEY_QUERY_VALUE, &hSubKey) == ERROR_SUCCESS) { - DWORD Length = MAX_PATH; - - if (RegQueryValueEx(hSubKey, _T("Layout Text"), NULL, NULL, (LPBYTE)KeyName, &Length) == ERROR_SUCCESS) + DWORD dwKeyNameSize = sizeof(KeyName); + + if (RegQueryValueEx(hSubKey, _T("Layout Text"), NULL, NULL, (LPBYTE)KeyName, &dwKeyNameSize) == ERROR_SUCCESS) { INT iIndex = (INT) SendMessage(hLayoutList, CB_ADDSTRING, 0, (LPARAM)KeyName);
- pstrBuf = (PTSTR)HeapAlloc(hProcessHeap, 0, (CCH_LAYOUT_ID + 1) * sizeof(TCHAR)); - _tcscpy(pstrBuf, szBuf); - SendMessage(hLayoutList, CB_SETITEMDATA, iIndex, (LPARAM)pstrBuf); + pstrLayoutID = (PTSTR)HeapAlloc(hProcessHeap, 0, sizeof(szLayoutID)); + lstrcpy(pstrLayoutID, szLayoutID); + SendMessage(hLayoutList, CB_SETITEMDATA, iIndex, (LPARAM)pstrLayoutID);
// FIXME! - if (_tcscmp(szBuf, _T("00000409")) == 0) + if (_tcscmp(szLayoutID, _T("00000409")) == 0) { SendMessage(hLayoutList, CB_SETCURSEL, (WPARAM)iIndex, (LPARAM)0); }
dwIndex++; - Ret = RegEnumKey(hKey, dwIndex, szBuf, sizeof(szBuf) / sizeof(TCHAR)); - } + } + + RegCloseKey(hSubKey); }
- RegCloseKey(hSubKey); - } - } - - RegCloseKey(hKey); + dwSize = sizeof(szLayoutID) / sizeof(TCHAR); + } + + RegCloseKey(hKey); + } }
/* Language enumerate procedure */
Modified: trunk/reactos/dll/cpl/input/input.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/input/input.h?rev=3... ============================================================================== --- trunk/reactos/dll/cpl/input/input.h [iso-8859-1] (original) +++ trunk/reactos/dll/cpl/input/input.h [iso-8859-1] Thu Apr 24 12:57:48 2008 @@ -26,6 +26,9 @@
// Character Count of a layout ID like "00000409" #define CCH_LAYOUT_ID 8 + +// Maximum Character Count of a ULONG in decimal +#define CCH_ULONG_DEC 10
/* input.c */ VOID
Modified: trunk/reactos/dll/cpl/input/settings.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/input/settings.c?re... ============================================================================== --- trunk/reactos/dll/cpl/input/settings.c [iso-8859-1] (original) +++ trunk/reactos/dll/cpl/input/settings.c [iso-8859-1] Thu Apr 24 12:57:48 2008 @@ -12,8 +12,6 @@ #include "resource.h" #include "input.h"
-#define BUFSIZE 256 - static HWND MainDlgWnd;
typedef struct @@ -21,9 +19,8 @@ LANGID LangId; TCHAR LangName[MAX_PATH]; TCHAR LayoutName[MAX_PATH]; - TCHAR ValName[MAX_PATH]; + TCHAR ValName[CCH_ULONG_DEC + 1]; TCHAR IndName[MAX_PATH]; - TCHAR SubName[MAX_PATH]; } LAYOUT_ITEM, *LPLAYOUT_ITEM;
BOOL @@ -31,14 +28,15 @@ { HKEY hKey; DWORD dwBufLen; - TCHAR szBuf[BUFSIZE]; - - _stprintf(szBuf, _T("SYSTEM\CurrentControlSet\Control\Keyboard Layouts\%s"),lcid); + TCHAR szBuf[MAX_PATH]; + + wsprintf(szBuf, _T("SYSTEM\CurrentControlSet\Control\Keyboard Layouts\%s"), lcid);
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, (LPCTSTR)szBuf, 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) { - dwBufLen = BUFSIZE; - if (RegQueryValueEx(hKey,_T("Layout Text"),NULL,NULL,(LPBYTE)name,&dwBufLen) == ERROR_SUCCESS) + dwBufLen = sizeof(szBuf); + + if (RegQueryValueEx(hKey, _T("Layout Text"), NULL, NULL, (LPBYTE)name, &dwBufLen) == ERROR_SUCCESS) { RegCloseKey(hKey); return TRUE; @@ -78,90 +76,71 @@ (VOID) ListView_InsertColumn(hList, 2, &column); }
-static BOOL +static VOID InitLangList(HWND hWnd) { HKEY hKey, hSubKey; - TCHAR szBuf[MAX_PATH], szPreload[MAX_PATH], szSub[MAX_PATH]; + TCHAR szBuf[MAX_PATH], szPreload[CCH_LAYOUT_ID + 1], szSub[CCH_LAYOUT_ID + 1]; LAYOUT_ITEM lItem; - LONG Ret; DWORD dwIndex = 0, dwType, dwSize; - LV_ITEM item; + LV_ITEM item = {0}; HWND hList = GetDlgItem(hWnd, IDC_KEYLAYOUT_LIST); INT i; - + + item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE; + if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\Preload"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) { - dwSize = MAX_PATH; - Ret = RegEnumValue(hKey, dwIndex, szBuf, &dwSize, NULL, &dwType, NULL, NULL); - if (Ret == ERROR_SUCCESS) - { - while (Ret == ERROR_SUCCESS) - { - _tcscpy(lItem.ValName, szBuf); - - dwSize = MAX_PATH; - RegQueryValueEx(hKey, szBuf, NULL, NULL, (LPBYTE)szPreload, &dwSize); - - lItem.LangId = _tcstoul(szPreload, NULL, 16); - - GetLocaleInfo(lItem.LangId, LOCALE_SISO639LANGNAME, (LPTSTR) szBuf, sizeof(szBuf)); - _tcscpy(lItem.IndName, _tcsupr(szBuf)); - - GetLocaleInfo(lItem.LangId, LOCALE_SLANGUAGE, (LPTSTR)szBuf, sizeof(szBuf)); - _tcscpy(lItem.LangName, szBuf); - - if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\Substitutes"), - 0, KEY_QUERY_VALUE, &hSubKey) == ERROR_SUCCESS) + dwSize = sizeof(lItem.ValName); + + while (RegEnumValue(hKey, dwIndex, lItem.ValName, &dwSize, NULL, &dwType, NULL, NULL) == ERROR_SUCCESS) + { + dwSize = sizeof(szPreload); + RegQueryValueEx(hKey, lItem.ValName, NULL, NULL, (LPBYTE)szPreload, &dwSize); + + lItem.LangId = (LANGID)_tcstoul(szPreload, NULL, 16); + + GetLocaleInfo(lItem.LangId, LOCALE_SISO639LANGNAME, (LPTSTR)szBuf, sizeof(szBuf) / sizeof(TCHAR)); + lstrcpy(lItem.IndName, _tcsupr(szBuf)); + + GetLocaleInfo(lItem.LangId, LOCALE_SLANGUAGE, (LPTSTR)szBuf, sizeof(szBuf) / sizeof(TCHAR)); + lstrcpy(lItem.LangName, szBuf); + + // Does this keyboard layout have a substitute? + // Then add the substitute instead of the Layout ID + if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\Substitutes"), + 0, KEY_QUERY_VALUE, &hSubKey) == ERROR_SUCCESS) + { + dwSize = sizeof(szSub); + + if (RegQueryValueEx(hSubKey, szPreload, NULL, NULL, (LPBYTE)szSub, &dwSize) == ERROR_SUCCESS) { - dwSize = MAX_PATH; - if (RegQueryValueEx(hSubKey, szPreload, NULL, NULL, (LPBYTE)szSub, &dwSize) == ERROR_SUCCESS) - { - _tcscpy(lItem.SubName, szPreload); - if (GetLayoutName(szSub, szBuf)) - { - _tcscpy(lItem.LayoutName, szBuf); - } - } - else - { - _tcscpy(lItem.SubName, _T("")); - } + lstrcpy(szPreload, szSub); }
- if (_tcslen(lItem.SubName) < 2) - { - if (GetLayoutName(szPreload, szBuf)) - { - _tcscpy(lItem.LayoutName, szBuf); - } - } - - ZeroMemory(&item, sizeof(LV_ITEM)); - item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE; - item.pszText = lItem.IndName; - item.lParam = (LPARAM)&lItem; - item.iItem = (INT) dwIndex; - i = ListView_InsertItem(hList, &item); - - ListView_SetItemText(hList, i, 1, lItem.LangName); - ListView_SetItemText(hList, i, 2, lItem.LayoutName); - - dwIndex++; - Ret = RegEnumValue(hKey, dwIndex, szBuf, &dwSize, NULL, &dwType, NULL, NULL); RegCloseKey(hSubKey); - - if (_tcscmp(lItem.ValName, _T("1")) == 0) - { - (VOID) ListView_SetHotItem(hList, i); - } - } - } - } - - RegCloseKey(hKey); - return TRUE; + } + + GetLayoutName(szPreload, lItem.LayoutName); + + item.pszText = lItem.IndName; + item.iItem = (INT) dwIndex; + i = ListView_InsertItem(hList, &item); + + ListView_SetItemText(hList, i, 1, lItem.LangName); + ListView_SetItemText(hList, i, 2, lItem.LayoutName); + + dwIndex++; + + if (lstrcmp(lItem.ValName, _T("1")) == 0) + { + (VOID) ListView_SetHotItem(hList, i); + } + } + + RegCloseKey(hKey); + } }
VOID