ReactOS  0.4.12-dev-18-gf469aca
kbsdll.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Keyboard Layout Switcher
3  * FILE: base/applications/kbswitch/kbsdll/kbsdll.c
4  * PROGRAMMER: Dmitry Chapyshev <dmitry@reactos.org>
5  *
6  */
7 
8 #include "../kbswitch.h"
9 
10 HHOOK hWinHook = NULL;
11 HHOOK hShellHook = NULL;
14 
15 static VOID
17 {
18  PostMessage(hKbSwitchWnd, Msg, wParam, lParam);
19 }
20 
23 {
24  int id = GlobalAddAtom(_T("KBSWITCH"));
25 
26  switch (code)
27  {
28  case HCBT_SETFOCUS:
29  {
30  if ((HWND)wParam != NULL)
31  {
32  if ((HWND)wParam != hKbSwitchWnd)
33  {
35  }
36  }
37  }
38  break;
39  }
40 
41  GlobalDeleteAtom(id);
42 
43  return CallNextHookEx(hWinHook, code, wParam, lParam);
44 }
45 
48 {
49  switch (code)
50  {
51  case HSHELL_LANGUAGE:
52  {
53  SendMessageToMainWnd(WM_LANG_CHANGED, wParam, lParam);
54  }
55  break;
56  }
57 
58  return CallNextHookEx(hShellHook, code, wParam, lParam);
59 }
60 
63 {
64  hWinHook = SetWindowsHookEx(WH_CBT, WinHookProc, hInstance, 0);
66 
67  if (!hWinHook || !hShellHook)
68  {
69  return FALSE;
70  }
71 
72  return TRUE;
73 }
74 
77 {
80 }
81 
83 DllMain(IN HINSTANCE hinstDLL,
86 {
87  switch (dwReason)
88  {
89  case DLL_PROCESS_ATTACH:
90  {
91  hInstance = hinstDLL;
92  hKbSwitchWnd = FindWindow(szKbSwitcherName, NULL);
93  if (!hKbSwitchWnd)
94  {
95  return FALSE;
96  }
97  }
98  break;
99  }
100 
101  return TRUE;
102 }
HWND hKbSwitchWnd
Definition: kbsdll.c:13
ATOM WINAPI GlobalDeleteAtom(ATOM nAtom)
Definition: atom.c:454
HINSTANCE hInstance
Definition: kbsdll.c:12
VOID WINAPI KbSwitchDeleteHooks(VOID)
Definition: kbsdll.c:76
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
#define FindWindow
Definition: winuser.h:5643
#define CALLBACK
Definition: compat.h:27
#define WH_SHELL
Definition: winuser.h:40
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
#define HCBT_SETFOCUS
Definition: winuser.h:64
#define GlobalAddAtom
Definition: winbase.h:3672
WPARAM wParam
Definition: combotst.c:138
static IN DWORD IN LPVOID lpvReserved
struct @1571 Msg[]
UINT_PTR WPARAM
Definition: windef.h:207
LRESULT CALLBACK WinHookProc(int code, WPARAM wParam, LPARAM lParam)
Definition: kbsdll.c:22
DWORD dwReason
Definition: misc.cpp:154
LONG_PTR LPARAM
Definition: windef.h:208
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DllMain(IN HINSTANCE hinstDLL, IN DWORD dwReason, IN LPVOID lpvReserved)
Definition: kbsdll.c:83
HHOOK hShellHook
Definition: kbsdll.c:11
#define WH_CBT
Definition: winuser.h:35
#define WM_LANG_CHANGED
Definition: kbswitch.h:23
#define PostMessage
Definition: winuser.h:5698
#define _T(x)
Definition: vfdio.h:22
unsigned int BOOL
Definition: ntddk_ex.h:94
#define WM_WINDOW_ACTIVATE
Definition: kbswitch.h:24
unsigned int UINT
Definition: ndis.h:50
#define SetWindowsHookEx
Definition: winuser.h:5722
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WINAPI
Definition: msvc.h:20
BOOL WINAPI UnhookWindowsHookEx(_In_ HHOOK)
TCHAR szKbSwitcherName[]
Definition: kbswitch.h:30
LRESULT WINAPI CallNextHookEx(_In_opt_ HHOOK, _In_ int, _In_ WPARAM, _In_ LPARAM)
HHOOK hWinHook
Definition: kbsdll.c:10
LRESULT CALLBACK ShellHookProc(int code, WPARAM wParam, LPARAM lParam)
Definition: kbsdll.c:47
static VOID SendMessageToMainWnd(UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: kbsdll.c:16
BOOL WINAPI KbSwitchSetHooks(VOID)
Definition: kbsdll.c:62
LONG_PTR LRESULT
Definition: windef.h:209
LPARAM lParam
Definition: combotst.c:139