ReactOS 0.4.16-dev-1210-gbc03c01
kbswitch.c File Reference
#include "kbswitch.h"
#include <shlobj.h>
#include <shlwapi_undoc.h>
#include <imm.h>
#include <imm32_undoc.h>
#include <wine/debug.h>
Include dependency graph for kbswitch.c:

Go to the source code of this file.

Classes

struct  tagSPECIAL_ID
 
struct  tagLOAD_ICON
 

Macros

#define WM_NOTIFYICONMSG   (WM_USER + 248)
 
#define TIMER_ID_LANG_CHANGED_DELAYED   0x10000
 
#define TIMER_LANG_CHANGED_DELAY   200
 
#define MAX_SPECIAL_IDS   256
 
#define IHOOK_SET   1
 

Typedefs

typedef struct tagSPECIAL_ID SPECIAL_ID
 
typedef struct tagSPECIAL_IDPSPECIAL_ID
 
typedef struct tagLOAD_ICON LOAD_ICON
 
typedef struct tagLOAD_ICONPLOAD_ICON
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (internat)
 
ULONG NTAPI vDbgPrintExWithPrefix (IN PCCH Prefix, IN ULONG ComponentId, IN ULONG Level, IN PCCH Format, IN va_list ap)
 
static VOID LoadSpecialIds (VOID)
 
static VOID GetKLIDFromHKL (HKL hKL, LPTSTR szKLID, SIZE_T KLIDLength)
 
static HKL GetActiveKL (VOID)
 
static VOID UpdateLayoutList (HKL hKL OPTIONAL)
 
static HKL GetHKLFromLayoutNum (INT nLayoutNum)
 
static VOID GetKLIDFromLayoutNum (INT nLayoutNum, LPTSTR szKLID, SIZE_T KLIDLength)
 
static BOOL GetSystemLibraryPath (LPTSTR szPath, SIZE_T cchPath, LPCTSTR FileName)
 
static BOOL GetLayoutName (INT nLayoutNum, LPTSTR szName, SIZE_T NameLength)
 
static BOOL GetImeFile (LPTSTR szImeFile, SIZE_T cchImeFile, LPCTSTR szKLID)
 
static BOOL CALLBACK EnumResNameProc (HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LPARAM lParam)
 
static HICON FakeExtractIcon (LPCTSTR szIconPath, INT cxIcon, INT cyIcon)
 
static HBITMAP BitmapFromIcon (HICON hIcon)
 
static HICON CreateTrayIcon (LPTSTR szKLID, LPCTSTR szImeFile OPTIONAL)
 
static VOID AddTrayIcon (HWND hwnd)
 
static VOID DeleteTrayIcon (HWND hwnd)
 
static VOID UpdateTrayIcon (HWND hwnd, LPTSTR szKLID, LPTSTR szName)
 
static BOOL CALLBACK EnumWindowsProc (HWND hwnd, LPARAM lParam)
 
static VOID ActivateLayout (HWND hwnd, ULONG uLayoutNum, HWND hwndTarget OPTIONAL, BOOL bNoActivate)
 
static HMENU BuildLeftPopupMenu (VOID)
 
BOOL SetHooks (VOID)
 
VOID DeleteHooks (VOID)
 
static UINT GetLayoutNum (HKL hKL)
 
ULONG GetNextLayout (VOID)
 
UINT UpdateLanguageDisplay (HWND hwnd, HKL hKL)
 
HWND GetTargetWindow (HWND hwndFore OPTIONAL)
 
UINT UpdateLanguageDisplayCurrent (HWND hwnd, HWND hwndFore)
 
static BOOL RememberLastActive (HWND hwnd, HWND hwndFore)
 
static INT KbSwitch_OnCreate (HWND hwnd)
 
static void KbSwitch_OnDestroy (HWND hwnd)
 
static void KbSwitch_OnTimer (HWND hwnd, UINT_PTR nTimerID)
 
static void KbSwitch_OnNotifyIconMsg (HWND hwnd, UINT uMouseMsg)
 
static void KbSwitch_OnCommand (HWND hwnd, UINT nID)
 
static LRESULT KbSwitch_OnLangChanged (HWND hwnd, HWND hwndTarget OPTIONAL, HKL hKL OPTIONAL)
 
static LRESULT KbSwitch_OnWindowActivate (HWND hwnd, HWND hwndTarget OPTIONAL, LPARAM lParam OPTIONAL)
 
static void KbSwitch_OnSettingChange (HWND hwnd, WPARAM wParam, LPARAM lParam)
 
static LRESULT KbSwitch_OnDefault (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
LRESULT CALLBACK WndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
INT WINAPI _tWinMain (HINSTANCE hInstance, HINSTANCE hPrevInst, LPTSTR lpCmdLine, INT nCmdShow)
 

Variables

FN_KbSwitchSetHooks KbSwitchSetHooks = NULL
 
HINSTANCE g_hInst = NULL
 
HMODULE g_hHookDLL = NULL
 
INT g_nCurrentLayoutNum = 1
 
HICON g_hTrayIcon = NULL
 
HWND g_hwndLastActive = NULL
 
INT g_cKLs = 0
 
HKL g_ahKLs [64]
 
HMENU g_hPopupMenu = NULL
 
UINT g_uTaskbarRestartMsg = 0
 
UINT g_uShellHookMessage = 0
 
SPECIAL_ID g_SpecialIds [MAX_SPECIAL_IDS]
 
INT g_cSpecialIds = 0
 

Macro Definition Documentation

◆ IHOOK_SET

#define IHOOK_SET   1

◆ MAX_SPECIAL_IDS

#define MAX_SPECIAL_IDS   256

Definition at line 74 of file kbswitch.c.

◆ TIMER_ID_LANG_CHANGED_DELAYED

#define TIMER_ID_LANG_CHANGED_DELAYED   0x10000

Definition at line 34 of file kbswitch.c.

◆ TIMER_LANG_CHANGED_DELAY

#define TIMER_LANG_CHANGED_DELAY   200

Definition at line 35 of file kbswitch.c.

◆ WM_NOTIFYICONMSG

#define WM_NOTIFYICONMSG   (WM_USER + 248)

Definition at line 32 of file kbswitch.c.

Typedef Documentation

◆ LOAD_ICON

◆ PLOAD_ICON

◆ PSPECIAL_ID

◆ SPECIAL_ID

Function Documentation

◆ _tWinMain()

INT WINAPI _tWinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInst,
LPTSTR  lpCmdLine,
INT  nCmdShow 
)

Definition at line 900 of file kbswitch.c.

901{
903 MSG msg;
905 HWND hwnd;
906
907 switch (GetUserDefaultUILanguage())
908 {
910 TRACE("LAYOUT_RTL\n");
912 break;
913 default:
914 break;
915 }
916
918 if (!hMutex)
919 {
920 ERR("!hMutex\n");
921 return 1;
922 }
923
925 {
926 ERR("Another instance is already running\n");
928 return 1;
929 }
930
932
933 ZeroMemory(&WndClass, sizeof(WndClass));
934 WndClass.lpfnWndProc = WndProc;
935 WndClass.hInstance = hInstance;
936 WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
937 WndClass.lpszClassName = szKbSwitcherName;
938 if (!RegisterClass(&WndClass))
939 {
941 return 1;
942 }
943
947 {
948 ERR("RegisterShellHookWindow failed\n");
951 return 1;
952 }
953
954 while (GetMessage(&msg, NULL, 0, 0))
955 {
958 }
959
961 return 0;
962}
#define msg(x)
Definition: auth_time.c:54
#define ERR(fmt,...)
Definition: precomp.h:57
WCHAR WndClass[]
Definition: capicon.c:23
HINSTANCE hInstance
Definition: charmap.c:19
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
LANGID WINAPI GetUserDefaultUILanguage(void)
Definition: locale.c:1375
UINT g_uShellHookMessage
Definition: kbswitch.c:48
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: kbswitch.c:859
HINSTANCE g_hInst
Definition: kbswitch.c:39
const TCHAR szKbSwitcherName[]
Definition: kbswitch.h:25
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
HANDLE hMutex
Definition: mutex.c:11
#define L(x)
Definition: ntvdm.h:50
#define MAKELANGID(p, s)
Definition: nls.h:15
#define LANG_HEBREW
Definition: nls.h:67
#define SUBLANG_DEFAULT
Definition: nls.h:168
#define TRACE(s)
Definition: solgame.cpp:4
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
BOOL WINAPI SetProcessDefaultLayout(DWORD dwDefaultLayout)
Definition: window.c:1689
#define ZeroMemory
Definition: winbase.h:1753
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CreateMutex
Definition: winbase.h:3797
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
#define LAYOUT_RTL
Definition: wingdi.h:1371
BOOL WINAPI TranslateMessage(_In_ const MSG *)
BOOL WINAPI RegisterShellHookWindow(_In_ HWND)
#define IDC_ARROW
Definition: winuser.h:695
#define CreateWindow
Definition: winuser.h:5839
#define HWND_DESKTOP
Definition: winuser.h:1220
#define GetMessage
Definition: winuser.h:5875
#define RegisterWindowMessage
Definition: winuser.h:5925
#define LoadCursor
Definition: winuser.h:5897
#define RegisterClass
Definition: winuser.h:5921
#define DispatchMessage
Definition: winuser.h:5850
BOOL WINAPI DestroyWindow(_In_ HWND)

◆ ActivateLayout()

static VOID ActivateLayout ( HWND  hwnd,
ULONG  uLayoutNum,
HWND hwndTarget  OPTIONAL,
BOOL  bNoActivate 
)
static

Definition at line 501 of file kbswitch.c.

502{
503 HKL hKl;
504 TCHAR szKLID[CCH_LAYOUT_ID + 1], szLangName[MAX_PATH];
506
507 /* The layout number starts from one. Zero is invalid */
508 if (uLayoutNum == 0 || uLayoutNum > 0xFF) /* Invalid */
509 return;
510
511 GetKLIDFromLayoutNum(uLayoutNum, szKLID, _countof(szKLID));
512 LangID = (LANGID)_tcstoul(szKLID, NULL, 16);
513
514 /* Switch to the new keyboard layout */
515 GetLocaleInfo(LangID, LOCALE_SLANGUAGE, szLangName, _countof(szLangName));
516 UpdateTrayIcon(hwnd, szKLID, szLangName);
517
518 if (hwndTarget && !bNoActivate)
519 SetForegroundWindow(hwndTarget);
520
521 hKl = LoadKeyboardLayout(szKLID, KLF_ACTIVATE);
522 if (hKl)
524
525 /* Post WM_INPUTLANGCHANGEREQUEST */
526 if (hwndTarget)
527 {
528 PostMessage(hwndTarget, WM_INPUTLANGCHANGEREQUEST,
529 INPUTLANGCHANGE_SYSCHARSET, (LPARAM)hKl);
530 }
531 else
532 {
534 }
535
536 g_nCurrentLayoutNum = uLayoutNum;
537}
#define MAX_PATH
Definition: compat.h:34
#define _tcstoul
Definition: tchar.h:595
static BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
Definition: kbswitch.c:494
static VOID UpdateTrayIcon(HWND hwnd, LPTSTR szKLID, LPTSTR szName)
Definition: kbswitch.c:475
static VOID GetKLIDFromLayoutNum(INT nLayoutNum, LPTSTR szKLID, SIZE_T KLIDLength)
Definition: kbswitch.c:203
INT g_nCurrentLayoutNum
Definition: kbswitch.c:41
#define CCH_LAYOUT_ID
Definition: kbswitch.h:17
USHORT LANGID
Definition: mui.h:9
UINT_PTR HKL
Definition: msctf.idl:125
#define _countof(array)
Definition: sndvol32.h:70
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_writes_opt_ NumCharacters PUSHORT _Inout_ PUSHORT _In_ UCHAR _In_opt_ USHORT LangID
Definition: wdfusb.h:1083
LONG_PTR LPARAM
Definition: windef.h:208
#define GetLocaleInfo
Definition: winnls.h:1243
#define LOCALE_SLANGUAGE
Definition: winnls.h:27
#define KLF_SETFORPROCESS
Definition: winuser.h:117
#define KLF_ACTIVATE
Definition: winuser.h:111
BOOL WINAPI SetForegroundWindow(_In_ HWND)
#define LoadKeyboardLayout
Definition: winuser.h:5901
BOOL WINAPI EnumWindows(_In_ WNDENUMPROC lpEnumFunc, _In_ LPARAM lParam)
#define PostMessage
Definition: winuser.h:5917
HKL WINAPI ActivateKeyboardLayout(_In_ HKL, _In_ UINT)
char TCHAR
Definition: xmlstorage.h:189

Referenced by KbSwitch_OnCommand(), and KbSwitch_OnCreate().

◆ AddTrayIcon()

static VOID AddTrayIcon ( HWND  hwnd)
static

Definition at line 441 of file kbswitch.c.

442{
443 NOTIFYICONDATA tnid = { sizeof(tnid), hwnd, 1, NIF_ICON | NIF_MESSAGE | NIF_TIP };
444 TCHAR szKLID[CCH_LAYOUT_ID + 1], szName[MAX_PATH], szImeFile[80];
445
448 GetImeFile(szImeFile, _countof(szImeFile), szKLID);
449
451 tnid.hIcon = CreateTrayIcon(szKLID, szImeFile);
453
455
456 if (g_hTrayIcon)
458 g_hTrayIcon = tnid.hIcon;
459}
static BOOL GetLayoutName(INT nLayoutNum, LPTSTR szName, SIZE_T NameLength)
Definition: kbswitch.c:220
static HICON CreateTrayIcon(LPTSTR szKLID, LPCTSTR szImeFile OPTIONAL)
Definition: kbswitch.c:344
static BOOL GetImeFile(LPTSTR szImeFile, SIZE_T cchImeFile, LPCTSTR szKLID)
Definition: kbswitch.c:256
HICON g_hTrayIcon
Definition: kbswitch.c:42
#define WM_NOTIFYICONMSG
Definition: kbswitch.c:32
static const WCHAR szName[]
Definition: powrprof.c:45
#define NIF_ICON
Definition: shellapi.h:106
#define NIF_MESSAGE
Definition: shellapi.h:105
#define NIM_ADD
Definition: shellapi.h:94
#define Shell_NotifyIcon
Definition: shellapi.h:730
#define NIF_TIP
Definition: shellapi.h:107
#define StringCchCopy
Definition: strsafe.h:139
UINT uCallbackMessage
Definition: shellapi.h:231
CHAR szTip[128]
Definition: shellapi.h:237
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2390

Referenced by KbSwitch_OnCreate(), and KbSwitch_OnDefault().

◆ BitmapFromIcon()

static HBITMAP BitmapFromIcon ( HICON  hIcon)
static

Definition at line 322 of file kbswitch.c.

323{
324 HDC hdcScreen = GetDC(NULL);
325 HDC hdc = CreateCompatibleDC(hdcScreen);
328 HBITMAP hbm = CreateCompatibleBitmap(hdcScreen, cxIcon, cyIcon);
329 HGDIOBJ hbmOld;
330
331 if (hbm != NULL)
332 {
333 hbmOld = SelectObject(hdc, hbm);
334 DrawIconEx(hdc, 0, 0, hIcon, cxIcon, cyIcon, 0, GetSysColorBrush(COLOR_MENU), DI_NORMAL);
335 SelectObject(hdc, hbmOld);
336 }
337
338 DeleteDC(hdc);
339 ReleaseDC(NULL, hdcScreen);
340 return hbm;
341}
HDC hdc
Definition: main.c:9
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:88
HICON hIcon
Definition: msconfig.c:44
_In_ HBITMAP hbm
Definition: ntgdi.h:2776
int32_t INT
Definition: typedefs.h:58
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
#define DI_NORMAL
Definition: wingdi.h:72
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
BOOL WINAPI DeleteDC(_In_ HDC)
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define COLOR_MENU
Definition: winuser.h:928
HBRUSH WINAPI GetSysColorBrush(_In_ int)
#define SM_CYSMICON
Definition: winuser.h:1024
#define SM_CXSMICON
Definition: winuser.h:1023
BOOL WINAPI DrawIconEx(_In_ HDC, _In_ int, _In_ int, _In_ HICON, _In_ int, _In_ int, _In_ UINT, _In_opt_ HBRUSH, _In_ UINT)
Definition: cursoricon.c:2365
HDC WINAPI GetDC(_In_opt_ HWND)
int WINAPI GetSystemMetrics(_In_ int)

Referenced by BuildLeftPopupMenu(), and FileTypesDlg_OnItemChanging().

◆ BuildLeftPopupMenu()

static HMENU BuildLeftPopupMenu ( VOID  )
static

Definition at line 540 of file kbswitch.c.

541{
542 HMENU hMenu = CreatePopupMenu();
543 TCHAR szName[MAX_PATH], szKLID[CCH_LAYOUT_ID + 1], szImeFile[80];
544 HICON hIcon;
545 MENUITEMINFO mii = { sizeof(mii) };
546 INT iKL;
547
548 for (iKL = 0; iKL < g_cKLs; ++iKL)
549 {
550 GetKLIDFromHKL(g_ahKLs[iKL], szKLID, _countof(szKLID));
551 GetImeFile(szImeFile, _countof(szImeFile), szKLID);
552
553 if (!GetLayoutName(iKL + 1, szName, _countof(szName)))
554 continue;
555
556 mii.fMask = MIIM_ID | MIIM_STRING;
557 mii.wID = iKL + 1;
558 mii.dwTypeData = szName;
559
560 hIcon = CreateTrayIcon(szKLID, szImeFile);
561 if (hIcon)
562 {
563 mii.hbmpItem = BitmapFromIcon(hIcon);
564 if (mii.hbmpItem)
565 mii.fMask |= MIIM_BITMAP;
566 }
567
568 InsertMenuItem(hMenu, -1, TRUE, &mii);
570 }
571
573
574 return hMenu;
575}
#define TRUE
Definition: types.h:120
static HBITMAP BitmapFromIcon(HICON hIcon)
Definition: kbswitch.c:322
static VOID GetKLIDFromHKL(HKL hKL, LPTSTR szKLID, SIZE_T KLIDLength)
Definition: kbswitch.c:132
HKL g_ahKLs[64]
Definition: kbswitch.c:45
INT g_cKLs
Definition: kbswitch.c:44
static HICON
Definition: imagelist.c:80
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:63
LPSTR dwTypeData
Definition: winuser.h:3327
HMENU WINAPI CreatePopupMenu(void)
Definition: menu.c:838
#define MIIM_STRING
Definition: winuser.h:738
#define MIIM_ID
Definition: winuser.h:733
#define InsertMenuItem
Definition: winuser.h:5889
#define MF_CHECKED
Definition: winuser.h:132
DWORD WINAPI CheckMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
#define MIIM_BITMAP
Definition: winuser.h:739

Referenced by KbSwitch_OnNotifyIconMsg().

◆ CreateTrayIcon()

static HICON CreateTrayIcon ( LPTSTR  szKLID,
LPCTSTR szImeFile  OPTIONAL 
)
static

Definition at line 344 of file kbswitch.c.

345{
347 TCHAR szBuf[4];
348 HDC hdcScreen, hdc;
349 HBITMAP hbmColor, hbmMono, hBmpOld;
350 HFONT hFont, hFontOld;
351 LOGFONT lf;
352 RECT rect;
354 HICON hIcon;
358
359 if (szImeFile && szImeFile[0])
360 {
361 if (GetSystemLibraryPath(szPath, _countof(szPath), szImeFile))
362 return FakeExtractIcon(szPath, cxIcon, cyIcon);
363 }
364
365 /* Getting "EN", "FR", etc. from English, French, ... */
366 LangID = LANGIDFROMLCID(_tcstoul(szKLID, NULL, 16));
369 szBuf,
370 _countof(szBuf)) == 0)
371 {
372 szBuf[0] = szBuf[1] = _T('?');
373 }
374 szBuf[2] = 0; /* Truncate the identifier to two characters: "ENG" --> "EN" etc. */
375
376 /* Create hdc, hbmColor and hbmMono */
377 hdcScreen = GetDC(NULL);
378 hdc = CreateCompatibleDC(hdcScreen);
379 hbmColor = CreateCompatibleBitmap(hdcScreen, cxIcon, cyIcon);
380 ReleaseDC(NULL, hdcScreen);
381 hbmMono = CreateBitmap(cxIcon, cyIcon, 1, 1, NULL);
382
383 /* Checking NULL */
384 if (!hdc || !hbmColor || !hbmMono)
385 {
386 if (hbmMono)
387 DeleteObject(hbmMono);
388 if (hbmColor)
389 DeleteObject(hbmColor);
390 if (hdc)
391 DeleteDC(hdc);
392 return NULL;
393 }
394
395 /* Create a font */
396 hFont = NULL;
397 if (SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, 0))
398 {
399 /* Override the current size with something manageable */
400 lf.lfHeight = -11;
401 lf.lfWidth = 0;
403 }
404 if (!hFont)
406
407 SetRect(&rect, 0, 0, cxIcon, cyIcon);
408
409 /* Draw hbmColor */
410 hBmpOld = SelectObject(hdc, hbmColor);
412 FillRect(hdc, &rect, (HBRUSH)GetStockObject(DC_BRUSH));
413 hFontOld = SelectObject(hdc, hFont);
417 SelectObject(hdc, hFontOld);
418
419 /* Fill hbmMono with black */
420 SelectObject(hdc, hbmMono);
421 PatBlt(hdc, 0, 0, cxIcon, cyIcon, BLACKNESS);
422 SelectObject(hdc, hBmpOld);
423
424 /* Create an icon from hbmColor and hbmMono */
427 IconInfo.hbmColor = hbmColor;
428 IconInfo.hbmMask = hbmMono;
430
431 /* Clean up */
433 DeleteObject(hbmMono);
434 DeleteObject(hbmColor);
435 DeleteDC(hdc);
436
437 return hIcon;
438}
HFONT hFont
Definition: main.c:53
pKey DeleteObject()
_Out_opt_ PICONINFO IconInfo
Definition: ntuser.h:2299
static HICON FakeExtractIcon(LPCTSTR szIconPath, INT cxIcon, INT cyIcon)
Definition: kbswitch.c:310
static BOOL GetSystemLibraryPath(LPTSTR szPath, SIZE_T cchPath, LPCTSTR FileName)
Definition: kbswitch.c:209
LPCWSTR szPath
Definition: env.c:37
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define LANGIDFROMLCID(l)
Definition: nls.h:18
& rect
Definition: startmenu.cpp:1413
LONG lfHeight
Definition: dimm.idl:42
LONG lfWidth
Definition: dimm.idl:43
DWORD yHotspot
Definition: winuser.h:3201
BOOL fIcon
Definition: winuser.h:3199
DWORD xHotspot
Definition: winuser.h:3200
HBITMAP hbmColor
Definition: winuser.h:3203
HBITMAP hbmMask
Definition: winuser.h:3202
#define _T(x)
Definition: vfdio.h:22
COLORREF WINAPI SetDCBrushColor(_In_ HDC hdc, _In_ COLORREF crColor)
Definition: dc.c:905
#define BLACKNESS
Definition: wingdi.h:323
HGDIOBJ WINAPI GetStockObject(_In_ int)
HBITMAP WINAPI CreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBitsPerPel, _In_opt_ const VOID *pvBits)
#define DEFAULT_GUI_FONT
Definition: wingdi.h:909
#define TRANSPARENT
Definition: wingdi.h:950
BOOL WINAPI PatBlt(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD)
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
int WINAPI SetBkMode(_In_ HDC, _In_ int)
Definition: dc.c:1056
COLORREF WINAPI SetTextColor(_In_ HDC, _In_ COLORREF)
Definition: text.c:917
#define CreateFontIndirect
Definition: wingdi.h:4444
#define LOCALE_NOUSEROVERRIDE
Definition: winnls.h:19
#define LOCALE_SABBREVLANGNAME
Definition: winnls.h:30
DWORD WINAPI GetSysColor(_In_ int)
HICON WINAPI CreateIconIndirect(_In_ PICONINFO)
Definition: cursoricon.c:2943
#define DT_CENTER
Definition: winuser.h:527
#define COLOR_HIGHLIGHT
Definition: winuser.h:937
#define DT_SINGLELINE
Definition: winuser.h:540
#define SPI_GETICONTITLELOGFONT
Definition: winuser.h:1391
#define DrawText
Definition: winuser.h:5856
#define COLOR_HIGHLIGHTTEXT
Definition: winuser.h:938
#define DT_VCENTER
Definition: winuser.h:543
#define SystemParametersInfo
Definition: winuser.h:5943
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)

Referenced by AddTrayIcon(), BuildLeftPopupMenu(), and UpdateTrayIcon().

◆ DeleteHooks()

VOID DeleteHooks ( VOID  )

Definition at line 600 of file kbswitch.c.

601{
603 {
606 }
607
608 if (g_hHookDLL)
609 {
612 }
613
614 TRACE("DeleteHooks OK\n");
615}
#define FreeLibrary(x)
Definition: compat.h:748
HMODULE g_hHookDLL
Definition: kbswitch.c:40
FN_KbSwitchSetHooks KbSwitchSetHooks
Definition: kbswitch.c:37

Referenced by KbSwitch_OnDestroy().

◆ DeleteTrayIcon()

static VOID DeleteTrayIcon ( HWND  hwnd)
static

Definition at line 462 of file kbswitch.c.

463{
464 NOTIFYICONDATA tnid = { sizeof(tnid), hwnd, 1 };
466
467 if (g_hTrayIcon)
468 {
471 }
472}
#define NIM_DELETE
Definition: shellapi.h:96

Referenced by KbSwitch_OnDestroy().

◆ EnumResNameProc()

static BOOL CALLBACK EnumResNameProc ( HMODULE  hModule,
LPCTSTR  lpszType,
LPTSTR  lpszName,
LPARAM  lParam 
)
static

Definition at line 295 of file kbswitch.c.

300{
301 PLOAD_ICON pLoadIcon = (PLOAD_ICON)lParam;
302 pLoadIcon->hIcon = (HICON)LoadImage(hModule, lpszName, IMAGE_ICON,
303 pLoadIcon->cxIcon, pLoadIcon->cyIcon,
305 if (pLoadIcon->hIcon)
306 return FALSE; /* Stop enumeration */
307 return TRUE;
308}
LPARAM lParam
Definition: combotst.c:139
HMODULE hModule
Definition: animate.c:44
struct tagLOAD_ICON * PLOAD_ICON
HICON hIcon
Definition: kbswitch.c:291
#define IMAGE_ICON
Definition: winuser.h:212
#define LoadImage
Definition: winuser.h:5900
#define LR_DEFAULTCOLOR
Definition: winuser.h:1098

Referenced by FakeExtractIcon().

◆ EnumWindowsProc()

static BOOL CALLBACK EnumWindowsProc ( HWND  hwnd,
LPARAM  lParam 
)
static

Definition at line 494 of file kbswitch.c.

495{
496 PostMessage(hwnd, WM_INPUTLANGCHANGEREQUEST, INPUTLANGCHANGE_SYSCHARSET, lParam);
497 return TRUE;
498}

Referenced by ActivateLayout().

◆ FakeExtractIcon()

static HICON FakeExtractIcon ( LPCTSTR  szIconPath,
INT  cxIcon,
INT  cyIcon 
)
static

Definition at line 310 of file kbswitch.c.

311{
312 LOAD_ICON LoadIcon = { cxIcon, cyIcon, NULL };
313 HMODULE hImeDLL = LoadLibraryEx(szIconPath, NULL, LOAD_LIBRARY_AS_DATAFILE);
314 if (hImeDLL)
315 {
317 FreeLibrary(hImeDLL);
318 }
319 return LoadIcon.hIcon;
320}
static BOOL CALLBACK EnumResNameProc(HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LPARAM lParam)
Definition: kbswitch.c:295
#define RT_GROUP_ICON
Definition: pedump.c:375
#define LoadLibraryEx
Definition: winbase.h:3904
#define LOAD_LIBRARY_AS_DATAFILE
Definition: winbase.h:375
#define EnumResourceNames
Definition: winbase.h:3813
#define LoadIcon
Definition: winuser.h:5898

Referenced by CreateTrayIcon().

◆ GetActiveKL()

static HKL GetActiveKL ( VOID  )
static

Definition at line 160 of file kbswitch.c.

161{
162 /* FIXME: Get correct console window's HKL when console window */
164 DWORD dwTID = GetWindowThreadProcessId(hwndTarget, NULL);
165 return GetKeyboardLayout(dwTID);
166}
unsigned long DWORD
Definition: ntddk_ex.h:95
HWND g_hwndLastActive
Definition: kbswitch.c:43
DWORD WINAPI GetWindowThreadProcessId(HWND hWnd, PDWORD lpdwProcessId)
HKL WINAPI GetKeyboardLayout(_In_ DWORD)
HWND WINAPI GetForegroundWindow(void)
Definition: ntwrapper.h:392

Referenced by GetHKLFromLayoutNum(), KbSwitch_OnTimer(), and UpdateLayoutList().

◆ GetHKLFromLayoutNum()

static HKL GetHKLFromLayoutNum ( INT  nLayoutNum)
static

Definition at line 194 of file kbswitch.c.

195{
196 if (0 <= (nLayoutNum - 1) && (nLayoutNum - 1) < g_cKLs)
197 return g_ahKLs[nLayoutNum - 1];
198 else
199 return GetActiveKL();
200}
static HKL GetActiveKL(VOID)
Definition: kbswitch.c:160

Referenced by GetKLIDFromLayoutNum().

◆ GetImeFile()

static BOOL GetImeFile ( LPTSTR  szImeFile,
SIZE_T  cchImeFile,
LPCTSTR  szKLID 
)
static

Definition at line 256 of file kbswitch.c.

257{
258 HKEY hKey;
260 TCHAR szBuf[MAX_PATH];
261
262 szImeFile[0] = UNICODE_NULL;
263
264 if (_tcslen(szKLID) != CCH_LAYOUT_ID)
265 return FALSE; /* Invalid LCID */
266
267 if (szKLID[0] != TEXT('E') && szKLID[0] != TEXT('e'))
268 return FALSE; /* Not an IME HKL */
269
270 StringCchPrintf(szBuf, _countof(szBuf),
271 _T("SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\%s"), szKLID);
272
274 return FALSE;
275
276 dwBufLen = cchImeFile * sizeof(TCHAR);
277 if (RegQueryValueEx(hKey, _T("IME File"), NULL, NULL,
278 (LPBYTE)szImeFile, &dwBufLen) != ERROR_SUCCESS)
279 {
280 szImeFile[0] = UNICODE_NULL;
281 }
282
284
285 return (szImeFile[0] != UNICODE_NULL);
286}
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
FxAutoRegKey hKey
#define TEXT(s)
Definition: k32.h:28
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define UNICODE_NULL
#define StringCchPrintf
Definition: strsafe.h:517
unsigned char * LPBYTE
Definition: typedefs.h:53
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_ DWORD _In_ DWORD dwBufLen
Definition: wincrypt.h:4246
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define RegOpenKeyEx
Definition: winreg.h:520
#define RegQueryValueEx
Definition: winreg.h:524
#define _tcslen
Definition: xmlstorage.h:198

Referenced by AddTrayIcon(), BuildLeftPopupMenu(), and UpdateTrayIcon().

◆ GetKLIDFromHKL()

static VOID GetKLIDFromHKL ( HKL  hKL,
LPTSTR  szKLID,
SIZE_T  KLIDLength 
)
static

Definition at line 132 of file kbswitch.c.

133{
134 szKLID[0] = 0;
135
136 if (IS_IME_HKL(hKL))
137 {
138 StringCchPrintf(szKLID, KLIDLength, _T("%08lx"), (DWORD)(DWORD_PTR)hKL);
139 return;
140 }
141
142 if (IS_SPECIAL_HKL(hKL))
143 {
144 INT i;
145 for (i = 0; i < g_cSpecialIds; ++i)
146 {
147 if (g_SpecialIds[i].hKL == hKL)
148 {
149 StringCchCopy(szKLID, KLIDLength, g_SpecialIds[i].szKLID);
150 return;
151 }
152 }
153 }
154 else
155 {
156 StringCchPrintf(szKLID, KLIDLength, _T("%08lx"), LOWORD(hKL));
157 }
158}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define IS_SPECIAL_HKL(hKL)
Definition: imm32_undoc.h:22
#define IS_IME_HKL(hKL)
Definition: imm32_undoc.h:21
INT g_cSpecialIds
Definition: kbswitch.c:77
SPECIAL_ID g_SpecialIds[MAX_SPECIAL_IDS]
Definition: kbswitch.c:76
#define LOWORD(l)
Definition: pedump.c:82
uint32_t DWORD_PTR
Definition: typedefs.h:65

Referenced by BuildLeftPopupMenu(), GetKLIDFromLayoutNum(), and UpdateLanguageDisplay().

◆ GetKLIDFromLayoutNum()

static VOID GetKLIDFromLayoutNum ( INT  nLayoutNum,
LPTSTR  szKLID,
SIZE_T  KLIDLength 
)
static

Definition at line 203 of file kbswitch.c.

204{
205 GetKLIDFromHKL(GetHKLFromLayoutNum(nLayoutNum), szKLID, KLIDLength);
206}
static HKL GetHKLFromLayoutNum(INT nLayoutNum)
Definition: kbswitch.c:194

Referenced by ActivateLayout(), AddTrayIcon(), and GetLayoutName().

◆ GetLayoutName()

static BOOL GetLayoutName ( INT  nLayoutNum,
LPTSTR  szName,
SIZE_T  NameLength 
)
static

Definition at line 220 of file kbswitch.c.

221{
222 HKEY hKey;
223 HRESULT hr;
225 TCHAR szBuf[MAX_PATH], szKLID[CCH_LAYOUT_ID + 1];
226
227 GetKLIDFromLayoutNum(nLayoutNum, szKLID, _countof(szKLID));
228
229 StringCchPrintf(szBuf, _countof(szBuf),
230 _T("SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\%s"), szKLID);
231
233 return FALSE;
234
235 /* Use "Layout Display Name" value as an entry name if possible */
236 hr = SHLoadRegUIString(hKey, _T("Layout Display Name"), szName, NameLength);
237 if (SUCCEEDED(hr))
238 {
240 return TRUE;
241 }
242
243 /* Otherwise, use "Layout Text" value as an entry name */
244 dwBufLen = NameLength * sizeof(TCHAR);
245 if (RegQueryValueEx(hKey, _T("Layout Text"), NULL, NULL,
247 {
249 return TRUE;
250 }
251
253 return FALSE;
254}
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define KEY_READ
Definition: nt_native.h:1023
HRESULT hr
Definition: shlfolder.c:183
#define SHLoadRegUIString

Referenced by AddTrayIcon(), and BuildLeftPopupMenu().

◆ GetLayoutNum()

static UINT GetLayoutNum ( HKL  hKL)
static

Definition at line 617 of file kbswitch.c.

618{
619 INT iKL;
620
621 for (iKL = 0; iKL < g_cKLs; ++iKL)
622 {
623 if (g_ahKLs[iKL] == hKL)
624 return iKL + 1;
625 }
626
627 return 0;
628}

Referenced by UpdateLanguageDisplay().

◆ GetNextLayout()

ULONG GetNextLayout ( VOID  )

Definition at line 631 of file kbswitch.c.

632{
633 return (g_nCurrentLayoutNum % g_cKLs) + 1;
634}

◆ GetSystemLibraryPath()

static BOOL GetSystemLibraryPath ( LPTSTR  szPath,
SIZE_T  cchPath,
LPCTSTR  FileName 
)
static

Definition at line 209 of file kbswitch.c.

210{
211 if (!GetSystemDirectory(szPath, cchPath))
212 return FALSE;
213
214 StringCchCat(szPath, cchPath, TEXT("\\"));
215 StringCchCat(szPath, cchPath, FileName);
216 return TRUE;
217}
#define StringCchCat
Definition: strsafe.h:317
#define GetSystemDirectory
Definition: winbase.h:3883

Referenced by CreateTrayIcon(), and LayoutList_ReadLayout().

◆ GetTargetWindow()

HWND GetTargetWindow ( HWND hwndFore  OPTIONAL)

Definition at line 652 of file kbswitch.c.

653{
654 HWND hwndTarget = (hwndFore ? hwndFore : GetForegroundWindow());
655 if (IsWndClassName(hwndTarget, szKbSwitcherName))
656 hwndTarget = g_hwndLastActive;
657 return hwndTarget;
658}
static BOOL IsWndClassName(_In_opt_ HWND hwndTarget, PCTSTR pszName)
Definition: kbswitch.h:28

Referenced by UpdateLanguageDisplayCurrent().

◆ KbSwitch_OnCommand()

static void KbSwitch_OnCommand ( HWND  hwnd,
UINT  nID 
)
static

Definition at line 772 of file kbswitch.c.

773{
774 switch (nID)
775 {
776 case ID_EXIT:
777 PostMessage(hwnd, WM_CLOSE, 0, 0);
778 break;
779
780 case ID_PREFERENCES:
781 {
783 TEXT("control.exe"), TEXT("input.dll"),
785 if (ret <= 32)
786 MessageBox(hwnd, _T("Can't start input.dll"), NULL, MB_ICONERROR);
787 break;
788 }
789
790 default:
791 {
792 if (1 <= nID && nID <= 1000)
793 {
795 {
797 }
799 }
800 break;
801 }
802 }
803}
#define ID_EXIT
Definition: resource.h:10
#define ID_PREFERENCES
Definition: resource.h:11
static VOID ActivateLayout(HWND hwnd, ULONG uLayoutNum, HWND hwndTarget OPTIONAL, BOOL bNoActivate)
Definition: kbswitch.c:501
#define ShellExecute
Definition: shellapi.h:732
int32_t INT_PTR
Definition: typedefs.h:64
int ret
#define SW_SHOWNORMAL
Definition: winuser.h:781
BOOL WINAPI IsWindow(_In_opt_ HWND)
#define WM_CLOSE
Definition: winuser.h:1640
#define MB_ICONERROR
Definition: winuser.h:798
#define MessageBox
Definition: winuser.h:5907

Referenced by WndProc().

◆ KbSwitch_OnCreate()

static INT KbSwitch_OnCreate ( HWND  hwnd)
static

Definition at line 689 of file kbswitch.c.

690{
691 if (!SetHooks())
692 {
693 MessageBox(NULL, TEXT("SetHooks failed."), NULL, MB_ICONERROR);
694 return -1; /* Failed */
695 }
696
698
701
704
705 return 0; /* Success */
706}
static VOID LoadSpecialIds(VOID)
Definition: kbswitch.c:79
static VOID UpdateLayoutList(HKL hKL OPTIONAL)
Definition: kbswitch.c:168
BOOL SetHooks(VOID)
Definition: kbswitch.c:578
static VOID AddTrayIcon(HWND hwnd)
Definition: kbswitch.c:441
UINT g_uTaskbarRestartMsg
Definition: kbswitch.c:47

Referenced by WndProc().

◆ KbSwitch_OnDefault()

static LRESULT KbSwitch_OnDefault ( HWND  hwnd,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 836 of file kbswitch.c.

837{
838 if (uMsg == g_uTaskbarRestartMsg)
839 {
842 return 0;
843 }
844
845 if (uMsg == g_uShellHookMessage)
846 {
847 TRACE("g_uShellHookMessage: wParam:%p, lParam:%p\n", wParam, lParam);
848 if (wParam == HSHELL_LANGUAGE)
850 else if (wParam == HSHELL_WINDOWACTIVATED || wParam == HSHELL_RUDEAPPACTIVATED)
852 return 0;
853 }
854
855 return DefWindowProc(hwnd, uMsg, wParam, lParam);
856}
WPARAM wParam
Definition: combotst.c:138
#define WM_WINDOW_ACTIVATE
Definition: kbswitch.h:21
#define WM_LANG_CHANGED
Definition: kbswitch.h:20
#define DefWindowProc
Definition: ros2win.h:31
#define HSHELL_RUDEAPPACTIVATED
Definition: winuser.h:1292

Referenced by WndProc().

◆ KbSwitch_OnDestroy()

static void KbSwitch_OnDestroy ( HWND  hwnd)
static

Definition at line 710 of file kbswitch.c.

711{
713 DeleteHooks();
714 if (g_hPopupMenu)
718}
HMENU g_hPopupMenu
Definition: kbswitch.c:46
#define TIMER_ID_LANG_CHANGED_DELAYED
Definition: kbswitch.c:34
VOID DeleteHooks(VOID)
Definition: kbswitch.c:600
static VOID DeleteTrayIcon(HWND hwnd)
Definition: kbswitch.c:462
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
BOOL WINAPI DestroyMenu(_In_ HMENU)
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)

Referenced by WndProc().

◆ KbSwitch_OnLangChanged()

static LRESULT KbSwitch_OnLangChanged ( HWND  hwnd,
HWND hwndTarget  OPTIONAL,
HKL hKL  OPTIONAL 
)
static

Definition at line 807 of file kbswitch.c.

808{
809 TRACE("WM_LANG_CHANGED: hwndTarget:%p, hKL:%p\n", hwndTarget, hKL);
810 /* Delayed action */
813 return 0;
814}
#define TIMER_LANG_CHANGED_DELAY
Definition: kbswitch.c:35
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)

Referenced by WndProc().

◆ KbSwitch_OnNotifyIconMsg()

static void KbSwitch_OnNotifyIconMsg ( HWND  hwnd,
UINT  uMouseMsg 
)
static

Definition at line 735 of file kbswitch.c.

736{
737 if (uMouseMsg != WM_LBUTTONUP && uMouseMsg != WM_RBUTTONUP)
738 return;
739
741
742 POINT pt;
744
746
747 INT nID;
748 if (uMouseMsg == WM_LBUTTONUP)
749 {
750 /* Rebuild the left popup menu on every click to take care of keyboard layout changes */
751 HMENU hLeftPopupMenu = BuildLeftPopupMenu();
752 nID = TrackPopupMenu(hLeftPopupMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hwnd, NULL);
753 DestroyMenu(hLeftPopupMenu);
754 }
755 else /* WM_RBUTTONUP */
756 {
757 if (!g_hPopupMenu)
759
760 HMENU hSubMenu = GetSubMenu(g_hPopupMenu, 0);
761 nID = TrackPopupMenu(hSubMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hwnd, NULL);
762 }
763
764 PostMessage(hwnd, WM_NULL, 0, 0);
765
766 if (nID)
767 PostMessage(hwnd, WM_COMMAND, nID, 0);
768}
#define IDR_POPUP
Definition: resource.h:7
#define pt(x, y)
Definition: drawing.c:79
static HMENU BuildLeftPopupMenu(VOID)
Definition: kbswitch.c:540
#define MAKEINTRESOURCE(i)
Definition: ntverrsrc.c:25
#define WM_COMMAND
Definition: winuser.h:1759
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:3032
#define WM_RBUTTONUP
Definition: winuser.h:1799
HMENU WINAPI GetSubMenu(_In_ HMENU, _In_ int)
#define WM_NULL
Definition: winuser.h:1626
#define LoadMenu
Definition: winuser.h:5902
#define WM_LBUTTONUP
Definition: winuser.h:1796
BOOL WINAPI TrackPopupMenu(_In_ HMENU, _In_ UINT, _In_ int, _In_ int, _Reserved_ int, _In_ HWND, _Reserved_ LPCRECT)
#define TPM_RETURNCMD
Definition: winuser.h:2406

Referenced by WndProc().

◆ KbSwitch_OnSettingChange()

static void KbSwitch_OnSettingChange ( HWND  hwnd,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 829 of file kbswitch.c.

830{
831 if (wParam == SPI_SETNONCLIENTMETRICS)
833}

Referenced by WndProc().

◆ KbSwitch_OnTimer()

static void KbSwitch_OnTimer ( HWND  hwnd,
UINT_PTR  nTimerID 
)
static

Definition at line 722 of file kbswitch.c.

723{
724 if (nTimerID == TIMER_ID_LANG_CHANGED_DELAYED)
725 {
726 KillTimer(hwnd, nTimerID);
727 HKL hKL = GetActiveKL();
728 UpdateLayoutList(hKL);
730 }
731}
UINT UpdateLanguageDisplay(HWND hwnd, HKL hKL)
Definition: kbswitch.c:637

Referenced by WndProc().

◆ KbSwitch_OnWindowActivate()

static LRESULT KbSwitch_OnWindowActivate ( HWND  hwnd,
HWND hwndTarget  OPTIONAL,
LPARAM lParam  OPTIONAL 
)
static

Definition at line 818 of file kbswitch.c.

819{
820 TRACE("WM_WINDOW_ACTIVATE: hwndTarget:%p, lParam:%p\n", hwndTarget, lParam);
821 HWND hwndFore = hwndTarget ? hwndTarget : GetForegroundWindow();
822 if (RememberLastActive(hwnd, hwndFore))
823 return UpdateLanguageDisplayCurrent(hwnd, hwndFore);
824 return 0;
825}
static BOOL RememberLastActive(HWND hwnd, HWND hwndFore)
Definition: kbswitch.c:670
UINT UpdateLanguageDisplayCurrent(HWND hwnd, HWND hwndFore)
Definition: kbswitch.c:661

Referenced by WndProc().

◆ LoadSpecialIds()

static VOID LoadSpecialIds ( VOID  )
static

Definition at line 79 of file kbswitch.c.

80{
81 TCHAR szKLID[KL_NAMELENGTH], szLayoutId[16];
82 DWORD dwSize, dwIndex;
83 HKEY hKey, hLayoutKey;
84
85 g_cSpecialIds = 0;
86
88 TEXT("SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts"),
90 {
91 return;
92 }
93
94 for (dwIndex = 0; dwIndex < 1000; ++dwIndex)
95 {
96 dwSize = _countof(szKLID);
97 if (RegEnumKeyEx(hKey, dwIndex, szKLID, &dwSize, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
98 break;
99
100 if (RegOpenKeyEx(hKey, szKLID, 0, KEY_READ, &hLayoutKey) != ERROR_SUCCESS)
101 continue;
102
103 dwSize = sizeof(szLayoutId);
104 if (RegQueryValueEx(hLayoutKey, TEXT("Layout Id"), NULL, NULL,
105 (LPBYTE)szLayoutId, &dwSize) == ERROR_SUCCESS)
106 {
107 DWORD dwKLID = _tcstoul(szKLID, NULL, 16);
108 WORD wLangId = LOWORD(dwKLID), wLayoutId = LOWORD(_tcstoul(szLayoutId, NULL, 16));
109 HKL hKL = (HKL)(LONG_PTR)(SPECIAL_MASK | MAKELONG(wLangId, wLayoutId));
110
111 /* Add a special ID */
115 _countof(g_SpecialIds[g_cSpecialIds].szKLID), szKLID);
117 }
118
119 RegCloseKey(hLayoutKey);
120
122 {
123 ERR("g_SpecialIds is full!");
124 break;
125 }
126 }
127
129}
#define SPECIAL_MASK
Definition: debug.h:13
unsigned short WORD
Definition: ntddk_ex.h:93
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
DWORD dwLayoutId
Definition: kbswitch.c:69
#define MAKELONG(a, b)
Definition: typedefs.h:249
#define RegEnumKeyEx
Definition: winreg.h:510
#define KL_NAMELENGTH
Definition: winuser.h:122

Referenced by KbSwitch_OnCreate().

◆ RememberLastActive()

static BOOL RememberLastActive ( HWND  hwnd,
HWND  hwndFore 
)
static

Definition at line 670 of file kbswitch.c.

671{
672 hwndFore = GetAncestor(hwndFore, GA_ROOT);
673
674 if (!IsWindowVisible(hwndFore))
675 return FALSE;
676
677 if (IsWndClassName(hwndFore, szKbSwitcherName) ||
678 IsWndClassName(hwndFore, TEXT("Shell_TrayWnd")))
679 {
680 return FALSE; /* Special window */
681 }
682
683 g_hwndLastActive = hwndFore;
684 return TRUE;
685}
#define GA_ROOT
Definition: winuser.h:2865
BOOL WINAPI IsWindowVisible(_In_ HWND)
HWND WINAPI GetAncestor(_In_ HWND, _In_ UINT)
Definition: window.c:929

Referenced by KbSwitch_OnWindowActivate().

◆ SetHooks()

BOOL SetHooks ( VOID  )

Definition at line 578 of file kbswitch.c.

579{
580 g_hHookDLL = LoadLibrary(_T("kbsdll.dll"));
581 if (!g_hHookDLL)
582 {
583 return FALSE;
584 }
585
586#define IHOOK_SET 1
588
590 {
591 ERR("SetHooks failed\n");
592 return FALSE;
593 }
594
595 TRACE("SetHooks OK\n");
596 return TRUE;
597}
#define GetProcAddress(x, y)
Definition: compat.h:753
#define IHOOK_SET
BOOL(APIENTRY * FN_KbSwitchSetHooks)(BOOL bDoHook)
Definition: kbswitch.h:23
#define LoadLibrary
Definition: winbase.h:3903
#define MAKEINTRESOURCEA(i)
Definition: winuser.h:581

Referenced by KbSwitch_OnCreate().

◆ UpdateLanguageDisplay()

UINT UpdateLanguageDisplay ( HWND  hwnd,
HKL  hKL 
)

Definition at line 637 of file kbswitch.c.

638{
639 TCHAR szKLID[MAX_PATH], szLangName[MAX_PATH];
641
642 GetKLIDFromHKL(hKL, szKLID, _countof(szKLID));
643 LangID = (LANGID)_tcstoul(szKLID, NULL, 16);
644 GetLocaleInfo(LangID, LOCALE_SLANGUAGE, szLangName, _countof(szLangName));
645 UpdateTrayIcon(hwnd, szKLID, szLangName);
647
648 return 0;
649}
static UINT GetLayoutNum(HKL hKL)
Definition: kbswitch.c:617

Referenced by KbSwitch_OnTimer(), and UpdateLanguageDisplayCurrent().

◆ UpdateLanguageDisplayCurrent()

UINT UpdateLanguageDisplayCurrent ( HWND  hwnd,
HWND  hwndFore 
)

Definition at line 661 of file kbswitch.c.

662{
663 DWORD dwThreadID = GetWindowThreadProcessId(GetTargetWindow(hwndFore), NULL);
664 HKL hKL = GetKeyboardLayout(dwThreadID);
666
667 return 0;
668}
HWND GetTargetWindow(HWND hwndFore OPTIONAL)
Definition: kbswitch.c:652

Referenced by KbSwitch_OnWindowActivate().

◆ UpdateLayoutList()

static VOID UpdateLayoutList ( HKL hKL  OPTIONAL)
static

Definition at line 168 of file kbswitch.c.

169{
170 INT iKL;
171
172 if (!hKL)
173 hKL = GetActiveKL();
174
176
178 for (iKL = 0; iKL < g_cKLs; ++iKL)
179 {
180 if (g_ahKLs[iKL] == hKL)
181 {
182 g_nCurrentLayoutNum = iKL + 1;
183 break;
184 }
185 }
186
188 {
190 g_ahKLs[g_cKLs++] = hKL;
191 }
192}
UINT WINAPI GetKeyboardLayoutList(_In_ int nBuff, _Out_writes_to_opt_(nBuff, return) HKL FAR *lpList)

Referenced by KbSwitch_OnCreate(), KbSwitch_OnDefault(), KbSwitch_OnNotifyIconMsg(), and KbSwitch_OnTimer().

◆ UpdateTrayIcon()

static VOID UpdateTrayIcon ( HWND  hwnd,
LPTSTR  szKLID,
LPTSTR  szName 
)
static

Definition at line 475 of file kbswitch.c.

476{
477 NOTIFYICONDATA tnid = { sizeof(tnid), hwnd, 1, NIF_ICON | NIF_MESSAGE | NIF_TIP };
478 TCHAR szImeFile[80];
479
480 GetImeFile(szImeFile, _countof(szImeFile), szKLID);
481
483 tnid.hIcon = CreateTrayIcon(szKLID, szImeFile);
485
487
488 if (g_hTrayIcon)
490 g_hTrayIcon = tnid.hIcon;
491}
#define NIM_MODIFY
Definition: shellapi.h:95

Referenced by ActivateLayout(), AddJobW(), StartDocPrinterW(), and UpdateLanguageDisplay().

◆ vDbgPrintExWithPrefix()

ULONG NTAPI vDbgPrintExWithPrefix ( IN PCCH  Prefix,
IN ULONG  ComponentId,
IN ULONG  Level,
IN PCCH  Format,
IN va_list  ap 
)

Definition at line 52 of file kbswitch.c.

57{
58 CHAR Buffer[512];
59 SIZE_T PrefixLength = strlen(Prefix);
60 strncpy(Buffer, Prefix, PrefixLength);
61 _vsnprintf(Buffer + PrefixLength, _countof(Buffer) - PrefixLength, Format, ap);
62 Buffer[_countof(Buffer) - 1] = ANSI_NULL; /* Avoid buffer overrun */
64 return 0;
65}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
Definition: bufpool.h:45
void WINAPI SHIM_OBJ_NAME() OutputDebugStringA(LPCSTR lpOutputString)
Definition: ignoredbgout.c:18
#define ANSI_NULL
strncpy
Definition: string.h:335
ULONG_PTR SIZE_T
Definition: typedefs.h:80
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36
_In_ __drv_aliasesMem PSTRING Prefix
Definition: rtlfuncs.h:1647
#define _vsnprintf
Definition: xmlstorage.h:202
char CHAR
Definition: xmlstorage.h:175

Referenced by StorPortDebugPrint().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( internat  )

◆ WndProc()

LRESULT CALLBACK WndProc ( HWND  hwnd,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 859 of file kbswitch.c.

860{
861 switch (uMsg)
862 {
863 case WM_CREATE:
864 return KbSwitch_OnCreate(hwnd);
865
866 case WM_TIMER:
868 break;
869
870 case WM_LANG_CHANGED: /* Comes from kbsdll.dll and this module */
872
873 case WM_WINDOW_ACTIVATE: /* Comes from kbsdll.dll and this module */
875
876 case WM_NOTIFYICONMSG:
878 break;
879
880 case WM_COMMAND:
882 break;
883
884 case WM_SETTINGCHANGE:
886 break;
887
888 case WM_DESTROY:
890 break;
891
892 default:
893 return KbSwitch_OnDefault(hwnd, uMsg, wParam, lParam);
894 }
895
896 return 0;
897}
static void KbSwitch_OnCommand(HWND hwnd, UINT nID)
Definition: kbswitch.c:772
static LRESULT KbSwitch_OnWindowActivate(HWND hwnd, HWND hwndTarget OPTIONAL, LPARAM lParam OPTIONAL)
Definition: kbswitch.c:818
static LRESULT KbSwitch_OnDefault(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: kbswitch.c:836
static void KbSwitch_OnSettingChange(HWND hwnd, WPARAM wParam, LPARAM lParam)
Definition: kbswitch.c:829
static LRESULT KbSwitch_OnLangChanged(HWND hwnd, HWND hwndTarget OPTIONAL, HKL hKL OPTIONAL)
Definition: kbswitch.c:807
static void KbSwitch_OnNotifyIconMsg(HWND hwnd, UINT uMouseMsg)
Definition: kbswitch.c:735
static void KbSwitch_OnTimer(HWND hwnd, UINT_PTR nTimerID)
Definition: kbswitch.c:722
static INT KbSwitch_OnCreate(HWND hwnd)
Definition: kbswitch.c:689
static void KbSwitch_OnDestroy(HWND hwnd)
Definition: kbswitch.c:710
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
unsigned int UINT
Definition: ndis.h:50
#define WM_CREATE
Definition: winuser.h:1627
#define WM_SETTINGCHANGE
Definition: winuser.h:1648
#define WM_TIMER
Definition: winuser.h:1761
#define WM_DESTROY
Definition: winuser.h:1628

Referenced by _tWinMain().

Variable Documentation

◆ g_ahKLs

HKL g_ahKLs[64]

Definition at line 45 of file kbswitch.c.

Referenced by BuildLeftPopupMenu(), GetHKLFromLayoutNum(), GetLayoutNum(), and UpdateLayoutList().

◆ g_cKLs

INT g_cKLs = 0

◆ g_cSpecialIds

INT g_cSpecialIds = 0

Definition at line 77 of file kbswitch.c.

Referenced by GetKLIDFromHKL(), and LoadSpecialIds().

◆ g_hHookDLL

HMODULE g_hHookDLL = NULL

Definition at line 40 of file kbswitch.c.

Referenced by DeleteHooks(), and SetHooks().

◆ g_hInst

◆ g_hPopupMenu

HMENU g_hPopupMenu = NULL

Definition at line 46 of file kbswitch.c.

Referenced by KbSwitch_OnDestroy(), and KbSwitch_OnNotifyIconMsg().

◆ g_hTrayIcon

HICON g_hTrayIcon = NULL

Definition at line 42 of file kbswitch.c.

Referenced by AddTrayIcon(), DeleteTrayIcon(), and UpdateTrayIcon().

◆ g_hwndLastActive

HWND g_hwndLastActive = NULL

Definition at line 43 of file kbswitch.c.

Referenced by GetActiveKL(), GetTargetWindow(), KbSwitch_OnCommand(), and RememberLastActive().

◆ g_nCurrentLayoutNum

◆ g_SpecialIds

SPECIAL_ID g_SpecialIds[MAX_SPECIAL_IDS]

Definition at line 76 of file kbswitch.c.

Referenced by GetKLIDFromHKL(), and LoadSpecialIds().

◆ g_uShellHookMessage

UINT g_uShellHookMessage = 0

Definition at line 48 of file kbswitch.c.

Referenced by _tWinMain(), and KbSwitch_OnDefault().

◆ g_uTaskbarRestartMsg

UINT g_uTaskbarRestartMsg = 0

Definition at line 47 of file kbswitch.c.

Referenced by KbSwitch_OnCreate(), and KbSwitch_OnDefault().

◆ KbSwitchSetHooks

FN_KbSwitchSetHooks KbSwitchSetHooks = NULL

Definition at line 37 of file kbswitch.c.

Referenced by DeleteHooks(), and SetHooks().