Author: dchapyshev
Date: Sun Apr 20 05:41:34 2008
New Revision: 33053
URL:
http://svn.reactos.org/svn/reactos?rev=33053&view=rev
Log:
- Add application for keyboard layouts switching (not finished)
Added:
trunk/reactos/base/applications/kbswitch/
trunk/reactos/base/applications/kbswitch/kbswitch.c (with props)
trunk/reactos/base/applications/kbswitch/kbswitch.h (with props)
trunk/reactos/base/applications/kbswitch/kbswitch.rbuild (with props)
trunk/reactos/base/applications/kbswitch/kbswitch.rc (with props)
trunk/reactos/base/applications/kbswitch/res/
trunk/reactos/base/applications/kbswitch/res/kbswitch.ico (with props)
trunk/reactos/base/applications/kbswitch/resource.h (with props)
Modified:
trunk/reactos/base/applications/applications.rbuild
Modified: trunk/reactos/base/applications/applications.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/applicat…
==============================================================================
--- trunk/reactos/base/applications/applications.rbuild [iso-8859-1] (original)
+++ trunk/reactos/base/applications/applications.rbuild [iso-8859-1] Sun Apr 20 05:41:34
2008
@@ -24,6 +24,9 @@
</directory>
<directory name="hh">
<xi:include href="hh/hh.rbuild" />
+ </directory>
+ <directory name="kbswitch">
+ <xi:include href="kbswitch/kbswitch.rbuild" />
</directory>
<directory name="logoff">
<xi:include href="logoff/logoff.rbuild" />
Added: 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 (added)
+++ trunk/reactos/base/applications/kbswitch/kbswitch.c [iso-8859-1] Sun Apr 20 05:41:34
2008
@@ -1,0 +1,187 @@
+#include <kbswitch.h>
+
+#define WM_NOTIFYICONMSG (WM_USER + 248)
+#define BUFSIZE 256
+
+HINSTANCE hInst;
+HWND hwnd;
+
+static VOID
+AddTrayIcon(HWND hwnd, HICON hIcon)
+{
+ NOTIFYICONDATA tnid;
+
+ tnid.cbSize = sizeof(NOTIFYICONDATA);
+ tnid.hWnd = hwnd;
+ tnid.uID = 1;
+ tnid.uFlags = NIF_ICON | NIF_MESSAGE;
+ tnid.uCallbackMessage = WM_NOTIFYICONMSG;
+ tnid.hIcon = hIcon;
+
+ Shell_NotifyIcon(NIM_ADD, &tnid);
+
+ if (hIcon) DestroyIcon(hIcon);
+}
+
+static VOID
+DelTrayIcon(HWND hwnd)
+{
+ NOTIFYICONDATA tnid;
+
+ tnid.cbSize = sizeof(NOTIFYICONDATA);
+ tnid.hWnd = hwnd;
+ tnid.uID = 1;
+
+ Shell_NotifyIcon(NIM_DELETE, &tnid);
+}
+
+static BOOL
+GetLayoutName(LPCTSTR lcid, LPTSTR name)
+{
+ HKEY hKey;
+ DWORD dwBufLen;
+ TCHAR szBuf[BUFSIZE];
+
+ _stprintf(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)
+ {
+ RegCloseKey(hKey);
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+static VOID
+ActivateLayout(INT LayoutID)
+{
+ TCHAR szLayoutID[MAX_PATH], szNewLayout[MAX_PATH];
+ HKEY hKey;
+ DWORD dwBufLen;
+
+ _stprintf(szLayoutID, _T("%d"), LayoutID);
+
+ if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Preload"), 0,
KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
+ {
+ dwBufLen = MAX_PATH;
+ if (RegQueryValueEx(hKey, szLayoutID, NULL, NULL, (LPBYTE)szNewLayout, &dwBufLen)
== ERROR_SUCCESS)
+ {
+ MessageBox(0, szNewLayout, _T(""), MB_OK);
+ RegCloseKey(hKey);
+ }
+ }
+}
+
+static VOID
+ShowPopupMenu(HWND hwnd, POINT pt)
+{
+ HMENU hMenu;
+ HKEY hKey;
+ DWORD dwIndex = 0, dwSize, dwType;
+ LONG Ret;
+ TCHAR szBuf[MAX_PATH], szPreload[MAX_PATH], szName[MAX_PATH];
+
+ hMenu = CreatePopupMenu();
+
+ 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)
+ {
+ dwSize = MAX_PATH;
+ RegQueryValueEx(hKey, szBuf, NULL, NULL, (LPBYTE)szPreload, &dwSize);
+
+ GetLayoutName(szPreload, szName);
+ AppendMenu(hMenu, MF_STRING, _ttoi(szBuf), szName);
+
+ dwIndex++;
+
+ dwSize = MAX_PATH;
+ Ret = RegEnumValue(hKey, dwIndex, szBuf, &dwSize, NULL, &dwType, NULL,
NULL);
+ }
+ }
+ }
+
+ TrackPopupMenu(hMenu, 0, pt.x, pt.y, 0, hwnd, NULL);
+ DestroyMenu(hMenu);
+ RegCloseKey(hKey);
+}
+
+LRESULT CALLBACK
+WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
+{
+ POINT pt;
+
+ switch (Message)
+ {
+ case WM_CREATE:
+ AddTrayIcon(hwnd, LoadIcon(hInst, MAKEINTRESOURCE(IDI_MAIN)));
+ break;
+
+ case WM_NOTIFYICONMSG:
+ switch (lParam)
+ {
+ case WM_LBUTTONDBLCLK:
+ case WM_LBUTTONDOWN:
+ case WM_RBUTTONDOWN:
+ {
+ GetCursorPos(&pt);
+ ShowPopupMenu(hwnd, pt);
+ }
+ break;
+ }
+ break;
+
+ case WM_COMMAND:
+ ActivateLayout(LOWORD(wParam));
+ break;
+
+ case WM_DESTROY:
+ DelTrayIcon(hwnd);
+ PostQuitMessage(0);
+ break;
+ }
+
+ return DefWindowProc(hwnd, Message, wParam, lParam);
+}
+
+INT WINAPI
+wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPTSTR lpCmdLine, INT nCmdShow)
+{
+ WNDCLASS WndClass = {0};
+ MSG msg;
+
+ hInst = hInstance;
+
+ WndClass.style = 0;
+ WndClass.lpfnWndProc = (WNDPROC)WndProc;
+ WndClass.cbClsExtra = 0;
+ WndClass.cbWndExtra = 0;
+ WndClass.hInstance = hInstance;
+ WndClass.hIcon = NULL;
+ WndClass.hCursor = NULL;
+ WndClass.hbrBackground = NULL;
+ WndClass.lpszMenuName = NULL;
+ WndClass.lpszClassName = L"kbswitch";
+
+ if (!RegisterClass(&WndClass)) return 0;
+
+ hwnd = CreateWindow(L"kbswitch", L"kbswitch", 0, 0, 0, 1, 1,
HWND_DESKTOP, NULL, hInstance, NULL);
+
+ while(GetMessage(&msg,NULL,0,0))
+ {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+
+ return 0;
+}
Propchange: trunk/reactos/base/applications/kbswitch/kbswitch.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: 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 (added)
+++ trunk/reactos/base/applications/kbswitch/kbswitch.h [iso-8859-1] Sun Apr 20 05:41:34
2008
@@ -1,0 +1,6 @@
+#include <windows.h>
+#include <tchar.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "resource.h"
Propchange: trunk/reactos/base/applications/kbswitch/kbswitch.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/reactos/base/applications/kbswitch/kbswitch.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/kbswitch…
==============================================================================
--- trunk/reactos/base/applications/kbswitch/kbswitch.rbuild (added)
+++ trunk/reactos/base/applications/kbswitch/kbswitch.rbuild [iso-8859-1] Sun Apr 20
05:41:34 2008
@@ -1,0 +1,20 @@
+<?xml version="1.0"?>
+<group
xmlns:xi="http://www.w3.org/2001/XInclude">
+ <module name="kbswitch" type="win32gui"
installbase="system32" installname="kbswitch.exe"
unicode="yes">
+ <include base="kbswitch">.</include>
+ <define name="_WIN32_IE">0x600</define>
+ <define name="WINVER">0x500</define>
+ <define name="_WIN32_WINNT">0x501</define>
+ <library>kernel32</library>
+ <library>advapi32</library>
+ <library>ntdll</library>
+ <library>user32</library>
+ <library>gdi32</library>
+ <library>shell32</library>
+ <library>comctl32</library>
+ <library>msimg32</library>
+ <library>shlwapi</library>
+ <file>kbswitch.c</file>
+ <file>kbswitch.rc</file>
+ </module>
+</group>
Propchange: trunk/reactos/base/applications/kbswitch/kbswitch.rbuild
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/reactos/base/applications/kbswitch/kbswitch.rc
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/kbswitch…
==============================================================================
--- trunk/reactos/base/applications/kbswitch/kbswitch.rc (added)
+++ trunk/reactos/base/applications/kbswitch/kbswitch.rc [iso-8859-1] Sun Apr 20 05:41:34
2008
@@ -1,0 +1,6 @@
+#include "resource.h"
+#include <windows.h>
+
+LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
+
+IDI_MAIN ICON "res/kbswitch.ico"
Propchange: trunk/reactos/base/applications/kbswitch/kbswitch.rc
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/reactos/base/applications/kbswitch/res/kbswitch.ico
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/kbswitch…
==============================================================================
Binary file - no diff available.
Propchange: trunk/reactos/base/applications/kbswitch/res/kbswitch.ico
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: 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 (added)
+++ trunk/reactos/base/applications/kbswitch/resource.h [iso-8859-1] Sun Apr 20 05:41:34
2008
@@ -1,0 +1,2 @@
+/* Icons */
+#define IDI_MAIN 100
Propchange: trunk/reactos/base/applications/kbswitch/resource.h
------------------------------------------------------------------------------
svn:eol-style = native