Guest User

Untitled

a guest
Jun 2nd, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.98 KB | None | 0 0
  1. #include <windows.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <tchar.h>
  5.  
  6. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  7.  
  8. int WINAPI WinMain(HINSTANCE Instance, HINSTANCE PrevInstance, LPSTR CmdLine, int CmdShow) {
  9.     TCHAR winClsName[] = _T("MyWinCls");
  10.     TCHAR Title[] = _T("Current Kb Layout");
  11.  
  12.     WNDCLASSEX wcex;
  13.  
  14.     wcex.cbSize = sizeof(WNDCLASSEX);
  15.     wcex.style = CS_HREDRAW | CS_VREDRAW;
  16.     wcex.lpfnWndProc = WndProc;
  17.     wcex.cbClsExtra = 0;
  18.     wcex.cbWndExtra = 0;
  19.     wcex.hInstance = Instance;
  20.     wcex.hIcon = LoadIcon(Instance, MAKEINTRESOURCE(IDI_APPLICATION));
  21.     wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  22.     wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  23.     wcex.lpszMenuName = NULL;
  24.     wcex.lpszClassName = winClsName;
  25.     wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
  26.  
  27.     if (!RegisterClassEx(&wcex)) {
  28.         MessageBox(NULL, _T("Call to RegisterClassEx failed!"), Title, NULL);
  29.         return 1;
  30.     }
  31.  
  32.     HWND wnd = CreateWindow(winClsName, Title, WS_OVERLAPPEDWINDOW,
  33.         CW_USEDEFAULT, CW_USEDEFAULT, 300, 100, NULL, NULL, Instance, NULL);
  34.  
  35.     ShowWindow(wnd, CmdShow);
  36.     UpdateWindow(wnd);
  37.  
  38.     MSG msg;
  39.     while (GetMessage(&msg, NULL, 0, 0)) {
  40.         TranslateMessage(&msg);
  41.         DispatchMessage(&msg);
  42.     }
  43.  
  44.     return (int)msg.wParam;
  45. }
  46.  
  47. LRESULT CALLBACK WndProc(HWND wnd, UINT message, WPARAM wparam, LPARAM lparam) {
  48.     switch (message) {
  49.     case WM_PAINT: {
  50.         PAINTSTRUCT ps;
  51.         HDC hdc = BeginPaint(wnd, &ps);
  52.         TCHAR lang[] = _T("OTHER");
  53.         switch (LOWORD(GetKeyboardLayout(GetWindowThreadProcessId(wnd, NULL)))) {
  54.         case 1033:
  55.             wsprintf(lang, _T("%s"), _T("EN"));
  56.             break;
  57.         case 1049:
  58.             wsprintf(lang, _T("%s"), _T("RU"));
  59.             break;
  60.         }
  61.         TextOut(hdc, 5, 5, lang, _tcslen(lang));
  62.         EndPaint(wnd, &ps);
  63.         break;
  64.     }
  65.     case WM_INPUTLANGCHANGE:
  66.         InvalidateRect(wnd, NULL, TRUE);
  67.         UpdateWindow(wnd);
  68.         break;
  69.     case WM_DESTROY:
  70.         PostQuitMessage(0);
  71.         break;
  72.     default:
  73.         return DefWindowProc(wnd, message, wparam, lparam);
  74.         break;
  75.     }
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment