ReactOS 0.4.16-dev-237-gd6eebaa
kbdlayout.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Keyboard layout testapp
5 * COPYRIGHT: Copyright 2007 Saveliy Tretiakov
6 */
7
8#define UNICODE
9#include<wchar.h>
10#include <windows.h>
11#include "resource.h"
12
13
14
16
17
20
21
22typedef struct {
24 WCHAR WndName[25];
25} WND_DATA;
26
28{
31 NULL,
33 (LPARAM)NULL);
34
35 return 0;
36}
37
39 HINSTANCE hPrevInstance,
40 LPSTR lpCmdLine,
41 int nCmdShow)
42{
44
45 ThreadProc(0);
46
47 return 0;
48}
49
51{
52 HKL *ret;
53 int n;
54
56 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(HKL)*n);
58 *list = ret;
59 return n;
60}
61
63{
65}
66
67void UpdateData(HWND hDlg)
68{
70 WCHAR buf2[512];
71
72 HWND hList;
73 HKL *klList, hKl;
74 int n, i,j;
75
77 swprintf(buf2, L"Active: %s (%x)", buf, GetKeyboardLayout(0));
79
80 hList = GetDlgItem(hDlg, IDC_LIST);
82
83 n = GetKlList(&klList);
84 hKl = GetKeyboardLayout(0);
85 for(i = 0; i < n; i++)
86 {
87 swprintf(buf, L"%x", klList[i] );
90 if(klList[i] == hKl) SendMessage(hList, LB_SETCURSEL, j, 0);
91 }
92
93 FreeKlList(klList);
94}
95
97{
98 WCHAR buf[255];
99 va_list argptr;
100 va_start(argptr, format);
101 _vsnwprintf(buf, sizeof(buf)-1, format, argptr);
102 MessageBox(0, buf, L"msg", 0);
103 va_end(argptr);
104}
105
107{
108 WCHAR buf[255];
109 va_list argptr;
110 va_start(argptr, Format);
111 _vsnwprintf(buf, sizeof(buf)-1, Format, argptr);
112 MessageBox(hWnd, buf, Caption, Flags);
113 va_end(argptr);
114}
115
117{
119
120 if(uMsg == WM_INPUTLANGCHANGE)
121 {
122 FormatMsg(L"%s: WM_INPUTLANGCHANGE lParam=%x wParam=%x\n", data->WndName, lParam, wParam);
124 //Pass message to defwindowproc
125 }
126 else if(uMsg == WM_INPUTLANGCHANGEREQUEST)
127 {
128 FormatMsg(L"%s: WM_INPUTLANGCHANGEREQUEST lParam=%x wParam=%x\n", data->WndName, lParam, wParam);
130 //Pass message to defwindowproc
131 }
132
133 return CallWindowProc(data->OrigProc, hwnd, uMsg, wParam, lParam);
134}
135
137{
140 wcsncpy(data->WndName, Name, 25);
142}
143
145{
146 DWORD ret = 0;
147
149 ret |= KLF_REORDER;
150
152 ret |= KLF_RESET;
153
155 ret |= KLF_SHIFTLOCK;
156
159
160 return ret;
161}
162
164{
165 DWORD ret = 0;
166
168 ret |= KLF_ACTIVATE;
169
172
174 ret |= KLF_REORDER;
175
178
181
184
185 return ret;
186}
187
189{
190 WCHAR Buf[255];
191 UINT ret;
192
193 GetWindowText(GetDlgItem(hDlg, IDC_DELAY), Buf, sizeof(Buf));
194
195 swscanf(Buf, L"%d", &ret);
196
197 return ret*1000;
198}
199
201{
202 int n;
203 HWND hList;
204 hList = GetDlgItem(hDlg, IDC_LIST);
205 if((n = SendMessage(hList, LB_GETCURSEL, 0, 0)) != LB_ERR)
206 return (HKL) SendMessage(hList, LB_GETITEMDATA, n, 0);
207 else return INVALID_HANDLE_VALUE;
208}
209
211{
213 return GetSelectedLayout(hDlg);
214 else if(IsDlgButtonChecked(hDlg, IDC_HKL_NEXT))
215 return (HKL)HKL_NEXT;
216
217 return (HKL)HKL_PREV;
218}
219
221 UINT Msg,
224{
225 HKL hKl;
226
227 switch (Msg)
228 {
229 case WM_INITDIALOG:
230 {
231 WCHAR Buf[255];
232 UpdateData(hDlg);
233 hMainDlg = hDlg;
234
235 SubclassWnd(GetDlgItem(hDlg, IDC_LIST), L"List");
236 SubclassWnd(GetDlgItem(hDlg, IDC_EDIT1), L"Edit1");
237 SubclassWnd(GetDlgItem(hDlg, IDC_KLID), L"Klid");
238 SubclassWnd(GetDlgItem(hDlg, ID_CANCEL), L"CancelB");
239 SubclassWnd(GetDlgItem(hDlg, IDC_ACTIVATE), L"ActivateB");
240 SubclassWnd(GetDlgItem(hDlg, IDC_REFRESH), L"RefreshB");
241 SubclassWnd(GetDlgItem(hDlg, IDC_UNLOAD), L"UnloadB");
242 SubclassWnd(GetDlgItem(hDlg, IDC_LOAD), L"LoadB");
243
245 SetWindowText(GetDlgItem(hDlg, IDC_KLID), L"00000419");
246
247 swprintf(Buf, L"Current thread id: %d", GetCurrentThreadId());
249
251
252 return 0;
253 } /* WM_INITDIALOG */
254
255 case WM_COMMAND:
256 {
257 switch(LOWORD(wParam))
258 {
259 case ID_CANCEL:
260 {
262 break;
263 }
264
265 case IDC_ACTIVATE:
266 {
267 if((hKl = GetActivateHandle(hDlg)) != INVALID_HANDLE_VALUE)
268 {
270 if(!(hKl = ActivateKeyboardLayout(hKl, GetActivateFlags(hDlg))))
271 FormatBox(hDlg, MB_ICONERROR, L"Error",
272 L"ActivateKeyboardLayout() failed. %d", GetLastError());
273 else UpdateData(hDlg);
274 //FormatBox(hDlg, 0, L"Activated", L"Prev - %x, err - %d.", hKl,
275 // GetLastError());
276 }
277 else MessageBox(hDlg, L"No item selected", L"Error", MB_ICONERROR);
278 break;
279 }
280
281 case IDC_UNLOAD:
282 {
283 if((hKl = GetSelectedLayout(hDlg)) != INVALID_HANDLE_VALUE)
284 {
286 if(!UnloadKeyboardLayout(hKl))
287 FormatBox(hDlg, MB_ICONERROR, L"Error",
288 L"UnloadKeyboardLayout() failed. %d",
289 GetLastError());
290 else UpdateData(hDlg);
291 }
292 else MessageBox(hDlg, L"No item selected", L"Error", MB_ICONERROR);
293 break;
294 }
295
296 case IDC_LOAD:
297 {
298 WCHAR buf[255];
299 GetWindowText(GetDlgItem(hDlg, IDC_KLID), buf, sizeof(buf));
302 FormatBox(hDlg, MB_ICONERROR, L"Error",
303 L"LoadKeyboardLayout() failed. %d",
304 GetLastError());
305 else UpdateData(hDlg);
306 break;
307 }
308
309 case IDC_REFRESH:
310 {
311 UpdateData(hDlg);
312 break;
313 }
314
315 case IDC_NEWTHREAD:
316 {
317 if(!CreateThread(NULL, 0, ThreadProc, NULL, 0, NULL))
318 {
319 FormatBox(hDlg, MB_ICONERROR, L"Error!",
320 L"Can not create thread (%d).", GetLastError());
321 }
322 }
323
324 case IDC_LIST:
325 {
327 {
328 WCHAR buf[25];
329 if((hKl = GetSelectedLayout(hDlg)) != NULL)
330 {
331 swprintf(buf, L"%x", hKl);
333 }
334 }
335 break;
336 }
337 }
338
339 return TRUE;
340 } /* WM_COMMAND */
341
342 case WM_INPUTLANGCHANGE:
343 {
344 FormatMsg(L"dlg WM_INPUTLANGCHANGE lParam=%x wParam=%x\n", lParam, wParam);
345 return FALSE;
346 }
347
348 case WM_INPUTLANGCHANGEREQUEST:
349 {
350 FormatMsg(L"dlg WM_INPUTLANGCHANGEREQUEST lParam=%x wParam=%x\n", lParam, wParam);
351 UpdateData(hDlg);
352 return FALSE;
353 }
354
355 case WM_CLOSE:
356 {
358 return TRUE;
359 } /* WM_CLOSE */
360
361 default:
362 return FALSE;
363 }
364}
365
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
HWND hWnd
Definition: settings.c:17
HINSTANCE hInstance
Definition: charmap.c:19
Definition: list.h:37
WPARAM wParam
Definition: combotst.c:138
struct @1640 Msg[]
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcessHeap()
Definition: compat.h:736
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define CALLBACK
Definition: compat.h:35
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137
#define swprintf
Definition: precomp.h:40
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLdouble n
Definition: glext.h:7729
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
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
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 GLint GLint j
Definition: glfuncs.h:250
_Check_return_ _CRTIMP int __cdecl swscanf(_In_z_ const wchar_t *_Src, _In_z_ _Scanf_format_string_ const wchar_t *_Format,...)
_CRTIMP int __cdecl _vsnwprintf(wchar_t *_Dest, size_t _Count, const wchar_t *_Format, va_list _Args)
HWND hList
Definition: livecd.c:10
#define IDC_LIST
Definition: resource.h:93
void FreeKlList(HKL *list)
Definition: kbdlayout.c:62
HINSTANCE hInst
Definition: kbdlayout.c:18
INT_PTR CALLBACK MainDialogProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: kbdlayout.c:220
int GetKlList(HKL **list)
Definition: kbdlayout.c:50
void SubclassWnd(HWND hWnd, WCHAR *Name)
Definition: kbdlayout.c:136
void UpdateData(HWND hDlg)
Definition: kbdlayout.c:67
LRESULT CALLBACK WndSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: kbdlayout.c:116
void FormatMsg(WCHAR *format,...)
Definition: kbdlayout.c:96
DWORD WINAPI ThreadProc(LPVOID lpParam)
Definition: kbdlayout.c:27
HKL GetSelectedLayout(HWND hDlg)
Definition: kbdlayout.c:200
void FormatBox(HWND hWnd, DWORD Flags, WCHAR *Caption, WCHAR *Format,...)
Definition: kbdlayout.c:106
DWORD GetLoadFlags(HWND hDlg)
Definition: kbdlayout.c:163
HWND hMainDlg
Definition: kbdlayout.c:19
DWORD GetActivateFlags(HWND hDlg)
Definition: kbdlayout.c:144
HKL GetActivateHandle(HWND hDlg)
Definition: kbdlayout.c:210
UINT GetDelayMilliseconds(HWND hDlg)
Definition: kbdlayout.c:188
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
Definition: kbdlayout.c:38
#define IDC_LOAD
Definition: resource.h:30
#define IDC_KLF_SHIFTLOCK
Definition: resource.h:17
#define IDC_CURTHREAD
Definition: resource.h:33
#define IDC_HANDLE
Definition: resource.h:32
#define IDL_KLF_REORDER
Definition: resource.h:24
#define IDC_KLID
Definition: resource.h:23
#define IDC_UNLOAD
Definition: resource.h:12
#define IDL_KLF_SUBSTITUTE_OK
Definition: resource.h:26
#define IDL_KLF_NOTELLSHELL
Definition: resource.h:22
#define IDC_KLF_RESET
Definition: resource.h:15
#define IDC_KLF_SETFORPROCESS
Definition: resource.h:16
#define IDC_DELAY
Definition: resource.h:11
#define IDC_ACTIVATE
Definition: resource.h:13
#define IDC_HKL_NEXT
Definition: resource.h:19
#define IDC_FROMEDIT
Definition: resource.h:29
#define IDC_FROMLIST
Definition: resource.h:18
#define IDC_ACTIVE
Definition: resource.h:9
#define IDL_KLF_REPLACELANG
Definition: resource.h:25
#define IDC_KLF_REORDER
Definition: resource.h:14
#define ID_CANCEL
Definition: resource.h:6
#define IDC_REFRESH
Definition: resource.h:31
#define IDD_MAINDIALOG
Definition: resource.h:5
#define IDC_EDIT1
Definition: resource.h:7
#define IDL_KLF_ACTIVATE
Definition: resource.h:21
#define IDL_KLF_SETFORPROCESS
Definition: resource.h:27
#define IDC_NEWTHREAD
Definition: resource.h:34
UINT_PTR HKL
Definition: msctf.idl:143
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#define LOWORD(l)
Definition: pedump.c:82
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
WNDPROC OrigProc
Definition: kbdlayout.c:23
Definition: format.c:58
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
#define GetWindowLongPtr
Definition: treelist.c:73
#define SetWindowLongPtr
Definition: treelist.c:70
#define GWLP_WNDPROC
Definition: treelist.c:66
#define GWLP_USERDATA
Definition: treelist.c:63
int32_t INT_PTR
Definition: typedefs.h:64
int32_t INT
Definition: typedefs.h:58
#define HIWORD(l)
Definition: typedefs.h:247
int ret
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define WINAPI
Definition: msvc.h:6
#define ERROR_CANCELLED
Definition: winerror.h:726
#define LB_ERR
Definition: winuser.h:2435
HKL WINAPI GetKeyboardLayout(_In_ DWORD)
#define WM_CLOSE
Definition: winuser.h:1624
#define LB_GETITEMDATA
Definition: winuser.h:2044
BOOL WINAPI UnloadKeyboardLayout(_In_ HKL)
#define KLF_SETFORPROCESS
Definition: winuser.h:117
#define KL_NAMELENGTH
Definition: winuser.h:122
#define CallWindowProc
Definition: winuser.h:5747
#define KLF_REPLACELANG
Definition: winuser.h:115
#define KLF_ACTIVATE
Definition: winuser.h:111
#define WM_COMMAND
Definition: winuser.h:1743
#define HKL_PREV
Definition: winuser.h:110
#define KLF_REORDER
Definition: winuser.h:114
#define LoadKeyboardLayout
Definition: winuser.h:5828
#define DialogBoxParam
Definition: winuser.h:5776
#define WM_INITDIALOG
Definition: winuser.h:1742
#define LB_ADDSTRING
Definition: winuser.h:2034
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define MB_ICONERROR
Definition: winuser.h:790
UINT WINAPI IsDlgButtonChecked(_In_ HWND, _In_ int)
#define LB_RESETCONTENT
Definition: winuser.h:2058
#define HKL_NEXT
Definition: winuser.h:109
UINT WINAPI GetKeyboardLayoutList(_In_ int nBuff, _Out_writes_to_opt_(nBuff, return) HKL FAR *lpList)
#define GetKeyboardLayoutName
Definition: winuser.h:5798
#define SendMessage
Definition: winuser.h:5855
#define KLF_SUBSTITUTE_OK
Definition: winuser.h:112
#define GetWindowText
Definition: winuser.h:5810
#define LB_SETITEMDATA
Definition: winuser.h:2068
#define LBN_SELCHANGE
Definition: winuser.h:2078
#define KLF_NOTELLSHELL
Definition: winuser.h:116
BOOL WINAPI CheckRadioButton(_In_ HWND, _In_ int, _In_ int, _In_ int)
#define MessageBox
Definition: winuser.h:5834
#define SetWindowText
Definition: winuser.h:5869
#define LB_SETCURSEL
Definition: winuser.h:2066
LRESULT(CALLBACK * WNDPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2909
HKL WINAPI ActivateKeyboardLayout(_In_ HKL, _In_ UINT)
#define LB_GETCURSEL
Definition: winuser.h:2042
#define MAKEINTRESOURCE
Definition: winuser.h:591
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
char * LPSTR
Definition: xmlstorage.h:182
__wchar_t WCHAR
Definition: xmlstorage.h:180