Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <stdlib.h>
- #include <string.h>
- #include <tchar.h>
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- int WINAPI WinMain(HINSTANCE Instance, HINSTANCE PrevInstance, LPSTR CmdLine, int CmdShow) {
- TCHAR winClsName[] = _T("MyWinCls");
- TCHAR Title[] = _T("Current Kb Layout");
- WNDCLASSEX wcex;
- wcex.cbSize = sizeof(WNDCLASSEX);
- wcex.style = CS_HREDRAW | CS_VREDRAW;
- wcex.lpfnWndProc = WndProc;
- wcex.cbClsExtra = 0;
- wcex.cbWndExtra = 0;
- wcex.hInstance = Instance;
- wcex.hIcon = LoadIcon(Instance, MAKEINTRESOURCE(IDI_APPLICATION));
- wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
- wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
- wcex.lpszMenuName = NULL;
- wcex.lpszClassName = winClsName;
- wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
- if (!RegisterClassEx(&wcex)) {
- MessageBox(NULL, _T("Call to RegisterClassEx failed!"), Title, NULL);
- return 1;
- }
- HWND wnd = CreateWindow(winClsName, Title, WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, 300, 100, NULL, NULL, Instance, NULL);
- ShowWindow(wnd, CmdShow);
- UpdateWindow(wnd);
- MSG msg;
- while (GetMessage(&msg, NULL, 0, 0)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return (int)msg.wParam;
- }
- LRESULT CALLBACK WndProc(HWND wnd, UINT message, WPARAM wparam, LPARAM lparam) {
- switch (message) {
- case WM_PAINT: {
- PAINTSTRUCT ps;
- HDC hdc = BeginPaint(wnd, &ps);
- TCHAR lang[] = _T("OTHER");
- switch (LOWORD(GetKeyboardLayout(GetWindowThreadProcessId(wnd, NULL)))) {
- case 1033:
- wsprintf(lang, _T("%s"), _T("EN"));
- break;
- case 1049:
- wsprintf(lang, _T("%s"), _T("RU"));
- break;
- }
- TextOut(hdc, 5, 5, lang, _tcslen(lang));
- EndPaint(wnd, &ps);
- break;
- }
- case WM_INPUTLANGCHANGE:
- InvalidateRect(wnd, NULL, TRUE);
- UpdateWindow(wnd);
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(wnd, message, wparam, lparam);
- break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment