Advertisement
DeXPeriX

libdxlsw.c

Dec 13th, 2012
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.92 KB | None | 0 0
  1. /* libdxlsw - dx console Language Switcher library
  2.  * Copyright (C) 2012 Dmitry Hrabrov a.k.a. DeXPeriX
  3.  *
  4.  * This library is free software; you can redistribute it and/or
  5.  * modify it under the terms of the GNU Lesser General Public
  6.  * License as published by the Free Software Foundation; either
  7.  * version 2 of the License, or (at your option) any later version.
  8.  *
  9.  * This library is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.  * Lesser General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU Lesser General Public
  15.  * License along with this library; if not, write to the
  16.  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  17.  * Boston, MA 02111-1307, USA.
  18.  */
  19.  
  20. #include <windows.h>
  21.  
  22. #define MAX_LAYS 10
  23.  
  24. __declspec(dllexport)
  25. int dxGetLayout(long a){
  26.     unsigned int x;
  27.     HWND hwnd;
  28.     DWORD threadId;
  29.     HKL currentLayout;
  30.  
  31.     hwnd = GetForegroundWindow();
  32.     if( hwnd ){
  33.         threadId = GetWindowThreadProcessId(hwnd, NULL);
  34.         currentLayout = GetKeyboardLayout(threadId);
  35.         x = (unsigned int)currentLayout & 0x0000FFFF;
  36.         return x;
  37.     } else return -1;
  38. }
  39.  
  40.  
  41. __declspec(dllexport)
  42. int dxSetLayout(long toLocale){
  43.     unsigned int i, n, Lid;
  44.     HKL  lpList[MAX_LAYS];
  45.     HKL  currentLayout;
  46.     HWND hwnd;
  47.  
  48.     n = GetKeyboardLayoutList(0, NULL);
  49.     n = GetKeyboardLayoutList(n, lpList);
  50.  
  51.     for(i=0; i<n; i++){
  52.         Lid = ((unsigned int)lpList[i]) & 0x0000FFFF; /* bottom 16 bit */
  53.         if( Lid == toLocale ){
  54.             currentLayout = lpList[i];
  55.             hwnd = GetForegroundWindow();
  56.             if( hwnd ){
  57.                 PostMessage(hwnd,WM_INPUTLANGCHANGEREQUEST,0,(LPARAM)(currentLayout));
  58.                 return Lid;
  59.             }
  60.         }
  61.     }
  62.     return -1;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement