2014-12-05 21:43:00 +00:00
|
|
|
/*
|
2014-12-05 22:09:10 +00:00
|
|
|
* PROJECT: ReactOS On-Screen Keyboard
|
2014-12-05 21:43:00 +00:00
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2014-12-05 22:09:10 +00:00
|
|
|
* PURPOSE: On-screen keyboard.
|
2019-03-02 17:10:26 +00:00
|
|
|
* COPYRIGHT: Denis ROBERT
|
2020-05-04 10:06:22 +00:00
|
|
|
* Copyright 2019-2020 George Bișoc (george.bisoc@reactos.org)
|
2021-08-11 19:36:30 +00:00
|
|
|
* Baruch Rutman (peterooch at gmail dot com)
|
2014-12-05 21:43:00 +00:00
|
|
|
*/
|
|
|
|
|
2014-12-05 22:09:10 +00:00
|
|
|
/* INCLUDES *******************************************************************/
|
|
|
|
|
2019-07-16 15:35:30 +00:00
|
|
|
#include "precomp.h"
|
2014-12-05 21:43:00 +00:00
|
|
|
|
2014-12-05 22:09:10 +00:00
|
|
|
/* GLOBALS ********************************************************************/
|
|
|
|
|
2014-12-05 21:43:00 +00:00
|
|
|
OSK_GLOBALS Globals;
|
|
|
|
|
2019-11-18 20:24:45 +00:00
|
|
|
OSK_KEYLEDINDICATOR LedKey[] =
|
|
|
|
{
|
|
|
|
{VK_NUMLOCK, IDC_LED_NUM, 0x0145, FALSE},
|
|
|
|
{VK_CAPITAL, IDC_LED_CAPS, 0x013A, FALSE},
|
|
|
|
{VK_SCROLL, IDC_LED_SCROLL, 0x0146, FALSE}
|
|
|
|
};
|
|
|
|
|
2014-12-05 22:09:10 +00:00
|
|
|
/* FUNCTIONS ******************************************************************/
|
2014-12-05 21:43:00 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* OSK_SetImage
|
|
|
|
*
|
|
|
|
* Set an image on a button
|
|
|
|
*/
|
|
|
|
int OSK_SetImage(int IdDlgItem, int IdResource)
|
|
|
|
{
|
2014-12-05 22:09:10 +00:00
|
|
|
HICON hIcon;
|
|
|
|
HWND hWndItem;
|
2014-12-05 21:43:00 +00:00
|
|
|
|
2019-01-23 12:28:56 +00:00
|
|
|
hIcon = (HICON)LoadImageW(Globals.hInstance, MAKEINTRESOURCEW(IdResource),
|
|
|
|
IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
|
2015-09-03 09:33:58 +00:00
|
|
|
if (hIcon == NULL)
|
|
|
|
return FALSE;
|
2014-12-05 21:43:00 +00:00
|
|
|
|
2014-12-05 22:09:10 +00:00
|
|
|
hWndItem = GetDlgItem(Globals.hMainWnd, IdDlgItem);
|
2015-09-03 09:33:58 +00:00
|
|
|
if (hWndItem == NULL)
|
|
|
|
{
|
|
|
|
DestroyIcon(hIcon);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-12-05 21:43:00 +00:00
|
|
|
|
2019-01-23 12:28:56 +00:00
|
|
|
SendMessageW(hWndItem, BM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)hIcon);
|
2014-12-05 21:43:00 +00:00
|
|
|
|
2014-12-05 22:09:10 +00:00
|
|
|
/* The system automatically deletes these resources when the process that created them terminates (MSDN) */
|
2014-12-05 21:43:00 +00:00
|
|
|
|
2014-12-05 22:09:10 +00:00
|
|
|
return TRUE;
|
2014-12-05 21:43:00 +00:00
|
|
|
}
|
|
|
|
|
2021-08-11 19:36:30 +00:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* OSK_SetText
|
|
|
|
*
|
|
|
|
* Update the text of a button according to the relevant language resource
|
|
|
|
*/
|
|
|
|
void OSK_SetText(int IdDlgItem, int IdResource)
|
|
|
|
{
|
|
|
|
WCHAR szText[MAX_PATH];
|
|
|
|
HWND hWndItem;
|
|
|
|
|
|
|
|
hWndItem = GetDlgItem(Globals.hMainWnd, IdDlgItem);
|
|
|
|
|
|
|
|
if (hWndItem == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
LoadStringW(Globals.hInstance, IdResource, szText, _countof(szText));
|
|
|
|
|
|
|
|
SetWindowTextW(hWndItem, szText);
|
|
|
|
}
|
2018-11-17 20:27:33 +00:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* OSK_WarningProc
|
|
|
|
*
|
|
|
|
* Function handler for the warning dialog box on startup
|
|
|
|
*/
|
|
|
|
INT_PTR CALLBACK OSK_WarningProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
UNREFERENCED_PARAMETER(lParam);
|
|
|
|
|
|
|
|
switch (Msg)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
{
|
|
|
|
switch (LOWORD(wParam))
|
|
|
|
{
|
|
|
|
case IDC_SHOWWARNINGCHECK:
|
|
|
|
{
|
|
|
|
Globals.bShowWarning = !IsDlgButtonChecked(hDlg, IDC_SHOWWARNINGCHECK);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IDOK:
|
|
|
|
case IDCANCEL:
|
|
|
|
{
|
|
|
|
EndDialog(hDlg, LOWORD(wParam));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-05-04 10:06:22 +00:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* OSK_WarningDlgThread
|
|
|
|
*
|
|
|
|
* Thread procedure routine for the warning dialog box
|
|
|
|
*/
|
|
|
|
DWORD WINAPI OSK_WarningDlgThread(LPVOID lpParameter)
|
|
|
|
{
|
|
|
|
HINSTANCE hInstance = (HINSTANCE)lpParameter;
|
|
|
|
|
|
|
|
DialogBoxW(hInstance, MAKEINTRESOURCEW(IDD_WARNINGDIALOG_OSK), Globals.hMainWnd, OSK_WarningProc);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-01-27 16:35:26 +00:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* OSK_About
|
|
|
|
*
|
|
|
|
* Initializes the "About" dialog box
|
|
|
|
*/
|
|
|
|
VOID OSK_About(VOID)
|
|
|
|
{
|
2021-08-11 19:36:30 +00:00
|
|
|
WCHAR szAuthors[MAX_PATH];
|
2019-01-27 16:35:26 +00:00
|
|
|
|
|
|
|
/* Load the strings into the "About" dialog */
|
2021-08-11 19:36:30 +00:00
|
|
|
LoadStringW(Globals.hInstance, IDS_AUTHORS, szAuthors, _countof(szAuthors));
|
2019-01-27 16:35:26 +00:00
|
|
|
|
2023-08-09 09:53:13 +00:00
|
|
|
/* Load the icon */
|
2019-01-27 16:35:26 +00:00
|
|
|
/* Finally, execute the "About" dialog by using the Shell routine */
|
2023-08-09 09:53:13 +00:00
|
|
|
ShellAboutW(Globals.hMainWnd, Globals.szTitle, szAuthors,
|
|
|
|
LoadImageW(Globals.hInstance, MAKEINTRESOURCEW(IDI_OSK), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED));
|
2019-01-27 16:35:26 +00:00
|
|
|
}
|
|
|
|
|
2021-08-11 19:36:30 +00:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* OSK_DestroyKeys
|
|
|
|
*
|
|
|
|
* Used in layout change or in shutdown
|
|
|
|
*/
|
|
|
|
VOID OSK_DestroyKeys(VOID)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
/* Hide before destroying child controls */
|
|
|
|
ShowWindow(Globals.hMainWnd, SW_HIDE);
|
|
|
|
|
|
|
|
for (i = 0; i < Globals.Keyboard->KeyCount; i++)
|
|
|
|
{
|
|
|
|
DestroyWindow(Globals.hKeys[i]);
|
|
|
|
}
|
|
|
|
for (i = 0; i < _countof(LedKey); i++)
|
|
|
|
{
|
|
|
|
DestroyWindow(GetDlgItem(Globals.hMainWnd, LedKey[i].DlgResource));
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, Globals.hKeys);
|
|
|
|
Globals.hKeys = NULL;
|
|
|
|
Globals.Keyboard = NULL;
|
|
|
|
}
|
2014-12-05 21:43:00 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
2021-08-11 19:36:30 +00:00
|
|
|
* OSK_SetKeys
|
2014-12-05 21:43:00 +00:00
|
|
|
*
|
2021-08-11 19:36:30 +00:00
|
|
|
* Create/Update button controls with the relevant keyboard values
|
2014-12-05 21:43:00 +00:00
|
|
|
*/
|
2021-08-11 19:36:30 +00:00
|
|
|
LRESULT OSK_SetKeys(int reason)
|
|
|
|
{
|
|
|
|
WCHAR wKey[2];
|
|
|
|
BYTE bKeyStates[256];
|
|
|
|
LPCWSTR szKey;
|
|
|
|
PKEY Keys;
|
|
|
|
UINT uVirtKey;
|
|
|
|
POINT LedPos;
|
|
|
|
SIZE LedSize;
|
|
|
|
int i, yPad;
|
|
|
|
|
|
|
|
/* Get key states before doing anything */
|
|
|
|
if (!GetKeyboardState(bKeyStates))
|
|
|
|
{
|
|
|
|
DPRINT("OSK_SetKeys(): GetKeyboardState() call failed.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (reason)
|
|
|
|
{
|
|
|
|
case SETKEYS_LANG:
|
|
|
|
{
|
|
|
|
/* Keyboard language/caps change, just update the button texts */
|
|
|
|
Keys = Globals.Keyboard->Keys;
|
|
|
|
for (i = 0; i < Globals.Keyboard->KeyCount; i++)
|
|
|
|
{
|
|
|
|
if (!Keys[i].translate)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
uVirtKey = MapVirtualKeyW(Keys[i].scancode & SCANCODE_MASK, MAPVK_VSC_TO_VK);
|
|
|
|
|
|
|
|
if (ToUnicode(uVirtKey, Keys[i].scancode & SCANCODE_MASK, bKeyStates, wKey, _countof(wKey), 0) >= 1)
|
|
|
|
{
|
|
|
|
szKey = wKey;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
szKey = Keys[i].name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only one & the button will try to underline the next character... */
|
|
|
|
if (wcsncmp(szKey, L"&", 1) == 0)
|
|
|
|
szKey = L"&&";
|
|
|
|
|
|
|
|
SetWindowTextW(Globals.hKeys[i], szKey);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case SETKEYS_LAYOUT:
|
|
|
|
{
|
|
|
|
/* Clear up current layout before applying a different one */
|
|
|
|
OSK_DestroyKeys();
|
|
|
|
}
|
|
|
|
/* Fallthrough */
|
|
|
|
case SETKEYS_INIT:
|
|
|
|
{
|
|
|
|
if (Globals.bIsEnhancedKeyboard)
|
|
|
|
{
|
|
|
|
Globals.Keyboard = &EnhancedKeyboard;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Globals.Keyboard = &StandardKeyboard;
|
|
|
|
}
|
|
|
|
|
|
|
|
Globals.hKeys = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HWND) * Globals.Keyboard->KeyCount);
|
|
|
|
|
|
|
|
if (!Globals.hKeys)
|
|
|
|
{
|
|
|
|
DPRINT("OSK_SetKeys(): Failed to allocate memory for button handles.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Keys = Globals.Keyboard->Keys;
|
|
|
|
|
|
|
|
/* Create key buttons */
|
|
|
|
for (i = 0; i < Globals.Keyboard->KeyCount; i++)
|
|
|
|
{
|
|
|
|
uVirtKey = MapVirtualKeyW(Keys[i].scancode & SCANCODE_MASK, MAPVK_VSC_TO_VK);
|
|
|
|
|
|
|
|
if (Keys[i].translate && ToUnicode(uVirtKey, Keys[i].scancode & SCANCODE_MASK, bKeyStates, wKey, _countof(wKey), 0) >= 1)
|
|
|
|
{
|
|
|
|
szKey = wKey;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
szKey = Keys[i].name;
|
|
|
|
}
|
|
|
|
|
|
|
|
Globals.hKeys[i] = CreateWindowW(WC_BUTTONW,
|
|
|
|
szKey,
|
|
|
|
WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | Keys[i].flags,
|
|
|
|
Keys[i].x,
|
|
|
|
Keys[i].y,
|
|
|
|
Keys[i].cx,
|
|
|
|
Keys[i].cy,
|
|
|
|
Globals.hMainWnd,
|
|
|
|
(HMENU)Keys[i].scancode,
|
|
|
|
Globals.hInstance,
|
|
|
|
NULL);
|
|
|
|
if (Globals.hFont)
|
|
|
|
SendMessageW(Globals.hKeys[i], WM_SETFONT, (WPARAM)Globals.hFont, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add additional padding for caption and menu */
|
|
|
|
yPad = GetSystemMetrics(SM_CYSIZE) + GetSystemMetrics(SM_CYMENU);
|
|
|
|
/* Size window according to layout */
|
|
|
|
SetWindowPos(Globals.hMainWnd,
|
|
|
|
(Globals.bAlwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST),
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
Globals.Keyboard->Size.cx,
|
|
|
|
Globals.Keyboard->Size.cy + yPad,
|
|
|
|
SWP_NOMOVE);
|
|
|
|
|
|
|
|
/* Create LEDs */
|
|
|
|
LedPos = Globals.Keyboard->LedStart;
|
|
|
|
LedSize = Globals.Keyboard->LedSize;
|
|
|
|
|
|
|
|
CreateWindowW(WC_STATICW, L"", WS_VISIBLE | WS_CHILD | SS_CENTER | SS_NOTIFY,
|
|
|
|
LedPos.x, LedPos.y, LedSize.cx, LedSize.cy, Globals.hMainWnd,
|
|
|
|
(HMENU)IDC_LED_NUM, Globals.hInstance, NULL);
|
|
|
|
|
|
|
|
LedPos.x += Globals.Keyboard->LedGap;
|
|
|
|
|
|
|
|
CreateWindowW(WC_STATICW, L"", WS_VISIBLE | WS_CHILD | SS_CENTER | SS_NOTIFY,
|
|
|
|
LedPos.x, LedPos.y, LedSize.cx, LedSize.cy, Globals.hMainWnd,
|
|
|
|
(HMENU)IDC_LED_CAPS, Globals.hInstance, NULL);
|
|
|
|
|
|
|
|
LedPos.x += Globals.Keyboard->LedGap;
|
|
|
|
|
|
|
|
CreateWindowW(WC_STATICW, L"", WS_VISIBLE | WS_CHILD | SS_CENTER | SS_NOTIFY,
|
|
|
|
LedPos.x, LedPos.y, LedSize.cx, LedSize.cy, Globals.hMainWnd,
|
|
|
|
(HMENU)IDC_LED_SCROLL, Globals.hInstance, NULL);
|
|
|
|
|
|
|
|
/* Set system keys text */
|
|
|
|
OSK_SetText(SCAN_CODE_110, IDS_ESCAPE);
|
|
|
|
OSK_SetText(SCAN_CODE_124, IDS_PRN);
|
|
|
|
OSK_SetText(SCAN_CODE_125, IDS_STOP);
|
|
|
|
OSK_SetText(SCAN_CODE_126, IDS_ATTN);
|
|
|
|
OSK_SetText(SCAN_CODE_90, IDS_NUMLOCKKEY);
|
|
|
|
OSK_SetText(SCAN_CODE_75, IDS_INSERT);
|
|
|
|
OSK_SetText(SCAN_CODE_76, IDS_DELETE);
|
|
|
|
OSK_SetText(SCAN_CODE_81, IDS_END);
|
|
|
|
OSK_SetText(SCAN_CODE_58, IDS_CTRL); /* Left ctrl */
|
|
|
|
OSK_SetText(SCAN_CODE_64, IDS_CTRL); /* Right ctrl */
|
|
|
|
OSK_SetText(SCAN_CODE_60, IDS_LEFTALT);
|
|
|
|
OSK_SetText(SCAN_CODE_62, IDS_RIGHTALT);
|
|
|
|
|
|
|
|
/* Set icon on visual buttons */
|
|
|
|
OSK_SetImage(SCAN_CODE_15, IDI_BACK);
|
|
|
|
OSK_SetImage(SCAN_CODE_16, IDI_TAB);
|
|
|
|
OSK_SetImage(SCAN_CODE_30, IDI_CAPS_LOCK);
|
|
|
|
OSK_SetImage(SCAN_CODE_43, IDI_RETURN);
|
|
|
|
OSK_SetImage(SCAN_CODE_44, IDI_SHIFT);
|
|
|
|
OSK_SetImage(SCAN_CODE_57, IDI_SHIFT);
|
|
|
|
OSK_SetImage(SCAN_CODE_127, IDI_REACTOS);
|
|
|
|
OSK_SetImage(SCAN_CODE_128, IDI_REACTOS);
|
|
|
|
OSK_SetImage(SCAN_CODE_129, IDI_MENU);
|
|
|
|
OSK_SetImage(SCAN_CODE_80, IDI_HOME);
|
|
|
|
OSK_SetImage(SCAN_CODE_85, IDI_PG_UP);
|
|
|
|
OSK_SetImage(SCAN_CODE_86, IDI_PG_DOWN);
|
|
|
|
OSK_SetImage(SCAN_CODE_79, IDI_LEFT);
|
|
|
|
OSK_SetImage(SCAN_CODE_83, IDI_TOP);
|
|
|
|
OSK_SetImage(SCAN_CODE_84, IDI_BOTTOM);
|
|
|
|
OSK_SetImage(SCAN_CODE_89, IDI_RIGHT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reason != SETKEYS_INIT)
|
|
|
|
{
|
|
|
|
ShowWindow(Globals.hMainWnd, SW_SHOW);
|
|
|
|
UpdateWindow(Globals.hMainWnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* OSK_Create
|
|
|
|
*
|
|
|
|
* Handling of WM_CREATE
|
|
|
|
*/
|
|
|
|
LRESULT OSK_Create(HWND hwnd)
|
2014-12-05 21:43:00 +00:00
|
|
|
{
|
2018-12-09 23:56:08 +00:00
|
|
|
HMONITOR monitor;
|
2014-12-05 22:09:10 +00:00
|
|
|
MONITORINFO info;
|
|
|
|
POINT Pt;
|
2019-03-02 17:10:26 +00:00
|
|
|
RECT rcWindow, rcDlgIntersect;
|
2021-08-11 19:36:30 +00:00
|
|
|
LOGFONTW lf = {0};
|
2014-12-05 22:09:10 +00:00
|
|
|
|
|
|
|
/* Save handle */
|
2021-08-11 19:36:30 +00:00
|
|
|
Globals.hMainWnd = hwnd;
|
2014-12-05 22:09:10 +00:00
|
|
|
|
2021-08-11 19:36:30 +00:00
|
|
|
/* Init Font */
|
|
|
|
lf.lfHeight = Globals.FontHeight;
|
|
|
|
StringCchCopyW(lf.lfFaceName, _countof(Globals.FontFaceName), Globals.FontFaceName);
|
|
|
|
Globals.hFont = CreateFontIndirectW(&lf);
|
|
|
|
|
|
|
|
if (OSK_SetKeys(SETKEYS_INIT) == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Check the checked menu item before displaying the window */
|
2019-02-10 15:04:16 +00:00
|
|
|
if (Globals.bIsEnhancedKeyboard)
|
|
|
|
{
|
|
|
|
/* Enhanced keyboard dialog chosen, set the respective menu item as checked */
|
2021-08-11 19:36:30 +00:00
|
|
|
CheckMenuItem(GetMenu(hwnd), IDM_ENHANCED_KB, MF_BYCOMMAND | MF_CHECKED);
|
|
|
|
CheckMenuItem(GetMenu(hwnd), IDM_STANDARD_KB, MF_BYCOMMAND | MF_UNCHECKED);
|
2019-02-10 15:04:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Standard keyboard dialog chosen, set the respective menu item as checked */
|
2021-08-11 19:36:30 +00:00
|
|
|
CheckMenuItem(GetMenu(hwnd), IDM_STANDARD_KB, MF_BYCOMMAND | MF_CHECKED);
|
|
|
|
CheckMenuItem(GetMenu(hwnd), IDM_ENHANCED_KB, MF_BYCOMMAND | MF_UNCHECKED);
|
2019-02-10 15:04:16 +00:00
|
|
|
}
|
2018-11-17 20:27:33 +00:00
|
|
|
|
2019-02-24 15:40:02 +00:00
|
|
|
/* Check if the "Click Sound" option was chosen before (and if so, then tick the menu item) */
|
|
|
|
if (Globals.bSoundClick)
|
|
|
|
{
|
2021-08-11 19:36:30 +00:00
|
|
|
CheckMenuItem(GetMenu(hwnd), IDM_CLICK_SOUND, MF_BYCOMMAND | MF_CHECKED);
|
2018-12-09 23:56:08 +00:00
|
|
|
}
|
2018-12-09 19:13:17 +00:00
|
|
|
|
2014-12-05 22:09:10 +00:00
|
|
|
/* Get screen info */
|
|
|
|
memset(&Pt, 0, sizeof(Pt));
|
2018-12-09 23:56:08 +00:00
|
|
|
monitor = MonitorFromPoint(Pt, MONITOR_DEFAULTTOPRIMARY);
|
2014-12-05 22:09:10 +00:00
|
|
|
info.cbSize = sizeof(info);
|
|
|
|
GetMonitorInfoW(monitor, &info);
|
2021-08-11 19:36:30 +00:00
|
|
|
GetWindowRect(hwnd, &rcWindow);
|
2019-03-02 17:10:26 +00:00
|
|
|
|
2019-05-01 08:33:13 +00:00
|
|
|
/*
|
2019-03-02 17:10:26 +00:00
|
|
|
If the coordination values are default then re-initialize using the specific formulas
|
|
|
|
to move the dialog at the bottom of the screen.
|
|
|
|
*/
|
|
|
|
if (Globals.PosX == CW_USEDEFAULT && Globals.PosY == CW_USEDEFAULT)
|
|
|
|
{
|
|
|
|
Globals.PosX = (info.rcMonitor.left + info.rcMonitor.right - (rcWindow.right - rcWindow.left)) / 2;
|
|
|
|
Globals.PosY = info.rcMonitor.bottom - (rcWindow.bottom - rcWindow.top);
|
|
|
|
}
|
|
|
|
|
2019-05-01 08:33:13 +00:00
|
|
|
/*
|
2019-03-02 17:10:26 +00:00
|
|
|
Calculate the intersection of two rectangle sources (dialog and work desktop area).
|
|
|
|
If such sources do not intersect, then the dialog is deemed as "off screen".
|
|
|
|
*/
|
|
|
|
if (IntersectRect(&rcDlgIntersect, &rcWindow, &info.rcWork) == 0)
|
|
|
|
{
|
|
|
|
Globals.PosX = (info.rcMonitor.left + info.rcMonitor.right - (rcWindow.right - rcWindow.left)) / 2;
|
|
|
|
Globals.PosY = info.rcMonitor.bottom - (rcWindow.bottom - rcWindow.top);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
There's still some intersection but we're not for sure if it is sufficient (the dialog could also be partially hidden).
|
|
|
|
Therefore, check the remaining intersection if it's enough.
|
|
|
|
*/
|
|
|
|
if (rcWindow.top < info.rcWork.top || rcWindow.left < info.rcWork.left || rcWindow.right > info.rcWork.right || rcWindow.bottom > info.rcWork.bottom)
|
|
|
|
{
|
|
|
|
Globals.PosX = (info.rcMonitor.left + info.rcMonitor.right - (rcWindow.right - rcWindow.left)) / 2;
|
|
|
|
Globals.PosY = info.rcMonitor.bottom - (rcWindow.bottom - rcWindow.top);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-15 13:59:06 +00:00
|
|
|
/*
|
|
|
|
Place the window (with respective placement coordinates) as topmost, above
|
|
|
|
every window which are not on top or are at the bottom of the Z order.
|
|
|
|
*/
|
|
|
|
if (Globals.bAlwaysOnTop)
|
|
|
|
{
|
2021-08-11 19:36:30 +00:00
|
|
|
CheckMenuItem(GetMenu(hwnd), IDM_ON_TOP, MF_BYCOMMAND | MF_CHECKED);
|
|
|
|
SetWindowPos(hwnd, HWND_TOPMOST, Globals.PosX, Globals.PosY, 0, 0, SWP_NOSIZE);
|
2019-07-15 13:59:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-11 19:36:30 +00:00
|
|
|
CheckMenuItem(GetMenu(hwnd), IDM_ON_TOP, MF_BYCOMMAND | MF_UNCHECKED);
|
|
|
|
SetWindowPos(hwnd, HWND_NOTOPMOST, Globals.PosX, Globals.PosY, 0, 0, SWP_NOSIZE);
|
2019-07-15 13:59:06 +00:00
|
|
|
}
|
2014-12-05 22:09:10 +00:00
|
|
|
|
|
|
|
/* Create a green brush for leds */
|
|
|
|
Globals.hBrushGreenLed = CreateSolidBrush(RGB(0, 255, 0));
|
|
|
|
|
2021-08-11 19:36:30 +00:00
|
|
|
/* Set a timer for periodic tasks */
|
|
|
|
Globals.iTimer = SetTimer(hwnd, 0, 100, NULL);
|
2014-12-05 22:09:10 +00:00
|
|
|
|
2021-08-11 19:36:30 +00:00
|
|
|
/* If the member of the struct (bShowWarning) is set then display the dialog box */
|
|
|
|
if (Globals.bShowWarning)
|
|
|
|
{
|
|
|
|
/* If for whatever reason the thread fails to be created then handle the dialog box in main thread... */
|
|
|
|
if (CreateThread(NULL, 0, OSK_WarningDlgThread, (PVOID)Globals.hInstance, 0, NULL) == NULL)
|
|
|
|
{
|
|
|
|
DialogBoxW(Globals.hInstance, MAKEINTRESOURCEW(IDD_WARNINGDIALOG_OSK), Globals.hMainWnd, OSK_WarningProc);
|
|
|
|
}
|
|
|
|
}
|
2014-12-05 21:43:00 +00:00
|
|
|
|
2021-08-11 19:36:30 +00:00
|
|
|
return 0;
|
2019-07-21 14:52:25 +00:00
|
|
|
}
|
|
|
|
|
2014-12-05 21:43:00 +00:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
2021-08-11 19:36:30 +00:00
|
|
|
* OSK_Close
|
2014-12-05 21:43:00 +00:00
|
|
|
*
|
|
|
|
* Handling of WM_CLOSE
|
|
|
|
*/
|
2021-08-11 19:36:30 +00:00
|
|
|
int OSK_Close(void)
|
2014-12-05 21:43:00 +00:00
|
|
|
{
|
2014-12-05 22:09:10 +00:00
|
|
|
KillTimer(Globals.hMainWnd, Globals.iTimer);
|
2014-12-05 21:43:00 +00:00
|
|
|
|
2014-12-05 22:09:10 +00:00
|
|
|
/* Release Ctrl, Shift, Alt keys */
|
|
|
|
OSK_ReleaseKey(SCAN_CODE_44); // Left shift
|
|
|
|
OSK_ReleaseKey(SCAN_CODE_57); // Right shift
|
|
|
|
OSK_ReleaseKey(SCAN_CODE_58); // Left ctrl
|
|
|
|
OSK_ReleaseKey(SCAN_CODE_60); // Left alt
|
|
|
|
OSK_ReleaseKey(SCAN_CODE_62); // Right alt
|
|
|
|
OSK_ReleaseKey(SCAN_CODE_64); // Right ctrl
|
2014-12-05 21:43:00 +00:00
|
|
|
|
2021-08-11 19:36:30 +00:00
|
|
|
/* Destroy child controls */
|
|
|
|
OSK_DestroyKeys();
|
|
|
|
|
2014-12-05 22:09:10 +00:00
|
|
|
/* delete GDI objects */
|
|
|
|
if (Globals.hBrushGreenLed) DeleteObject(Globals.hBrushGreenLed);
|
2021-08-11 19:36:30 +00:00
|
|
|
if (Globals.hFont) DeleteObject(Globals.hFont);
|
2014-12-05 21:43:00 +00:00
|
|
|
|
2019-12-11 23:25:55 +00:00
|
|
|
/* Save the application's settings on registry */
|
|
|
|
SaveSettings();
|
2018-11-17 20:27:33 +00:00
|
|
|
|
2014-12-05 22:09:10 +00:00
|
|
|
return TRUE;
|
2014-12-05 21:43:00 +00:00
|
|
|
}
|
|
|
|
|
2019-11-18 20:24:45 +00:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* OSK_RefreshLEDKeys
|
|
|
|
*
|
|
|
|
* Updates (invalidates) the LED icon resources then the respective
|
|
|
|
* keys (Caps Lock, Scroll Lock or Num Lock) are being held down
|
|
|
|
*/
|
|
|
|
VOID OSK_RefreshLEDKeys(VOID)
|
|
|
|
{
|
|
|
|
INT i;
|
|
|
|
BOOL bKeyIsPressed;
|
|
|
|
|
|
|
|
for (i = 0; i < _countof(LedKey); i++)
|
|
|
|
{
|
|
|
|
bKeyIsPressed = (GetAsyncKeyState(LedKey[i].vKey) & 0x8000) != 0;
|
|
|
|
if (LedKey[i].bWasKeyPressed != bKeyIsPressed)
|
|
|
|
{
|
|
|
|
LedKey[i].bWasKeyPressed = bKeyIsPressed;
|
|
|
|
InvalidateRect(GetDlgItem(Globals.hMainWnd, LedKey[i].DlgResource), NULL, FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-05 21:43:00 +00:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
2021-08-11 19:36:30 +00:00
|
|
|
* OSK_Timer
|
2014-12-05 21:43:00 +00:00
|
|
|
*
|
|
|
|
* Handling of WM_TIMER
|
|
|
|
*/
|
2021-08-11 19:36:30 +00:00
|
|
|
int OSK_Timer(void)
|
2014-12-05 21:43:00 +00:00
|
|
|
{
|
2014-12-05 22:09:10 +00:00
|
|
|
HWND hWndActiveWindow;
|
2021-08-11 19:36:30 +00:00
|
|
|
DWORD dwThread;
|
|
|
|
HKL hKeyboardLayout;
|
2014-12-05 21:43:00 +00:00
|
|
|
|
2014-12-05 22:09:10 +00:00
|
|
|
hWndActiveWindow = GetForegroundWindow();
|
|
|
|
if (hWndActiveWindow != NULL && hWndActiveWindow != Globals.hMainWnd)
|
|
|
|
{
|
2021-08-11 19:36:30 +00:00
|
|
|
/* Grab the current keyboard layout from the foreground window */
|
|
|
|
dwThread = GetWindowThreadProcessId(hWndActiveWindow, NULL);
|
|
|
|
hKeyboardLayout = GetKeyboardLayout(dwThread);
|
|
|
|
/* Activate the layout */
|
|
|
|
ActivateKeyboardLayout(hKeyboardLayout, 0);
|
2014-12-05 22:09:10 +00:00
|
|
|
}
|
2014-12-05 21:43:00 +00:00
|
|
|
|
2019-11-18 20:24:45 +00:00
|
|
|
/*
|
|
|
|
Update the LED key indicators accordingly to their state (if one
|
|
|
|
of the specific keys is held down).
|
|
|
|
*/
|
|
|
|
OSK_RefreshLEDKeys();
|
2021-08-11 19:36:30 +00:00
|
|
|
/* Update the buttons */
|
|
|
|
OSK_SetKeys(SETKEYS_LANG);
|
2014-12-05 21:43:00 +00:00
|
|
|
|
2014-12-05 22:09:10 +00:00
|
|
|
return TRUE;
|
2014-12-05 21:43:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
2021-08-11 19:36:30 +00:00
|
|
|
* OSK_ChooseFont
|
|
|
|
*
|
|
|
|
* Change the font of which the keys are being displayed
|
|
|
|
*/
|
|
|
|
VOID OSK_ChooseFont(VOID)
|
|
|
|
{
|
|
|
|
LOGFONTW lf = {0};
|
|
|
|
CHOOSEFONTW cf = {0};
|
|
|
|
HFONT hFont, hOldFont;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
StringCchCopyW(lf.lfFaceName, _countof(Globals.FontFaceName), Globals.FontFaceName);
|
|
|
|
lf.lfHeight = Globals.FontHeight;
|
|
|
|
|
|
|
|
cf.lStructSize = sizeof(cf);
|
|
|
|
cf.hwndOwner = Globals.hMainWnd;
|
|
|
|
cf.lpLogFont = &lf;
|
|
|
|
cf.Flags = CF_INITTOLOGFONTSTRUCT | CF_NOSTYLESEL;
|
|
|
|
|
|
|
|
if (!ChooseFontW(&cf))
|
|
|
|
return;
|
|
|
|
|
|
|
|
hFont = CreateFontIndirectW(&lf);
|
|
|
|
|
|
|
|
if (!hFont)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Set font information */
|
|
|
|
StringCchCopyW(Globals.FontFaceName, _countof(Globals.FontFaceName), lf.lfFaceName);
|
|
|
|
Globals.FontHeight = lf.lfHeight;
|
|
|
|
|
|
|
|
hOldFont = Globals.hFont;
|
|
|
|
Globals.hFont = hFont;
|
|
|
|
|
|
|
|
for (i = 0; i < Globals.Keyboard->KeyCount; i++)
|
|
|
|
SendMessageW(Globals.hKeys[i], WM_SETFONT, (WPARAM)Globals.hFont, TRUE);
|
|
|
|
|
|
|
|
DeleteObject(hOldFont);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* OSK_Command
|
2014-12-05 21:43:00 +00:00
|
|
|
*
|
2021-08-11 19:36:30 +00:00
|
|
|
* All handling of commands
|
2014-12-05 21:43:00 +00:00
|
|
|
*/
|
2021-08-11 19:36:30 +00:00
|
|
|
BOOL OSK_Command(WPARAM wCommand, HWND hWndControl)
|
2014-12-05 21:43:00 +00:00
|
|
|
{
|
2014-12-05 22:09:10 +00:00
|
|
|
WORD ScanCode;
|
|
|
|
INPUT Input;
|
|
|
|
BOOL bExtendedKey;
|
|
|
|
BOOL bKeyDown;
|
|
|
|
BOOL bKeyUp;
|
|
|
|
LONG WindowStyle;
|
2019-11-18 20:24:45 +00:00
|
|
|
INT i;
|
2014-12-05 22:09:10 +00:00
|
|
|
|
|
|
|
/* KeyDown and/or KeyUp ? */
|
2019-01-23 12:28:56 +00:00
|
|
|
WindowStyle = GetWindowLongW(hWndControl, GWL_STYLE);
|
2014-12-05 22:09:10 +00:00
|
|
|
if ((WindowStyle & BS_AUTOCHECKBOX) == BS_AUTOCHECKBOX)
|
2014-12-05 21:43:00 +00:00
|
|
|
{
|
2014-12-05 22:09:10 +00:00
|
|
|
/* 2-states key like Shift, Alt, Ctrl, ... */
|
2019-01-23 12:28:56 +00:00
|
|
|
if (SendMessageW(hWndControl, BM_GETCHECK, 0, 0) == BST_CHECKED)
|
2014-12-05 22:09:10 +00:00
|
|
|
{
|
|
|
|
bKeyDown = TRUE;
|
|
|
|
bKeyUp = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bKeyDown = FALSE;
|
|
|
|
bKeyUp = TRUE;
|
|
|
|
}
|
2014-12-05 21:43:00 +00:00
|
|
|
}
|
2014-12-05 22:09:10 +00:00
|
|
|
else
|
2014-12-05 21:43:00 +00:00
|
|
|
{
|
2014-12-05 22:09:10 +00:00
|
|
|
/* Other key */
|
|
|
|
bKeyDown = TRUE;
|
|
|
|
bKeyUp = TRUE;
|
2014-12-05 21:43:00 +00:00
|
|
|
}
|
2014-12-05 22:09:10 +00:00
|
|
|
|
2019-11-18 20:24:45 +00:00
|
|
|
/* Get the key from dialog control key command */
|
2014-12-05 22:09:10 +00:00
|
|
|
ScanCode = wCommand;
|
2019-11-18 20:24:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
The user could've pushed one of the key buttons of the dialog that
|
|
|
|
can trigger particular function toggling (Caps Lock, Num Lock or Scroll Lock). Update
|
|
|
|
(invalidate) the LED icon resources accordingly.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < _countof(LedKey); i++)
|
|
|
|
{
|
|
|
|
if (LedKey[i].wScanCode == ScanCode)
|
|
|
|
{
|
|
|
|
InvalidateRect(GetDlgItem(Globals.hMainWnd, LedKey[i].DlgResource), NULL, FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Extended key ? */
|
2014-12-05 22:09:10 +00:00
|
|
|
if (ScanCode & 0x0200)
|
|
|
|
bExtendedKey = TRUE;
|
2014-12-05 21:43:00 +00:00
|
|
|
else
|
2014-12-05 22:09:10 +00:00
|
|
|
bExtendedKey = FALSE;
|
2021-08-11 19:36:30 +00:00
|
|
|
ScanCode &= SCANCODE_MASK;
|
2014-12-05 22:09:10 +00:00
|
|
|
|
|
|
|
/* Press and release the key */
|
|
|
|
if (bKeyDown)
|
2014-12-05 21:43:00 +00:00
|
|
|
{
|
2014-12-05 22:09:10 +00:00
|
|
|
Input.type = INPUT_KEYBOARD;
|
|
|
|
Input.ki.wVk = 0;
|
|
|
|
Input.ki.wScan = ScanCode;
|
|
|
|
Input.ki.time = GetTickCount();
|
|
|
|
Input.ki.dwExtraInfo = GetMessageExtraInfo();
|
|
|
|
Input.ki.dwFlags = KEYEVENTF_SCANCODE;
|
|
|
|
if (bExtendedKey) Input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
|
|
|
|
SendInput(1, &Input, sizeof(Input));
|
2014-12-05 21:43:00 +00:00
|
|
|
}
|
|
|
|
|
2014-12-05 22:09:10 +00:00
|
|
|
if (bKeyUp)
|
|
|
|
{
|
|
|
|
Input.type = INPUT_KEYBOARD;
|
|
|
|
Input.ki.wVk = 0;
|
|
|
|
Input.ki.wScan = ScanCode;
|
|
|
|
Input.ki.time = GetTickCount();
|
|
|
|
Input.ki.dwExtraInfo = GetMessageExtraInfo();
|
|
|
|
Input.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
|
|
|
|
if (bExtendedKey) Input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
|
|
|
|
SendInput(1, &Input, sizeof(Input));
|
|
|
|
}
|
2014-12-05 21:43:00 +00:00
|
|
|
|
2019-02-24 15:40:02 +00:00
|
|
|
/* Play the sound during clicking event (only if "Use Click Sound" menu option is ticked) */
|
|
|
|
if (Globals.bSoundClick)
|
|
|
|
{
|
|
|
|
PlaySoundW(MAKEINTRESOURCEW(IDI_SOUNDCLICK), GetModuleHandle(NULL), SND_RESOURCE | SND_ASYNC);
|
|
|
|
}
|
|
|
|
|
2014-12-05 22:09:10 +00:00
|
|
|
return TRUE;
|
2014-12-05 21:43:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* OSK_ReleaseKey
|
|
|
|
*
|
|
|
|
* Release the key of ID wCommand
|
|
|
|
*/
|
|
|
|
BOOL OSK_ReleaseKey(WORD ScanCode)
|
|
|
|
{
|
2014-12-05 22:09:10 +00:00
|
|
|
INPUT Input;
|
|
|
|
BOOL bExtendedKey;
|
|
|
|
LONG WindowStyle;
|
|
|
|
HWND hWndControl;
|
|
|
|
|
|
|
|
/* Is it a 2-states key ? */
|
|
|
|
hWndControl = GetDlgItem(Globals.hMainWnd, ScanCode);
|
2019-01-23 12:28:56 +00:00
|
|
|
WindowStyle = GetWindowLongW(hWndControl, GWL_STYLE);
|
2014-12-05 22:09:10 +00:00
|
|
|
if ((WindowStyle & BS_AUTOCHECKBOX) != BS_AUTOCHECKBOX) return FALSE;
|
|
|
|
|
|
|
|
/* Is the key down ? */
|
2019-01-23 12:28:56 +00:00
|
|
|
if (SendMessageW(hWndControl, BM_GETCHECK, 0, 0) != BST_CHECKED) return TRUE;
|
2014-12-05 22:09:10 +00:00
|
|
|
|
|
|
|
/* Extended key ? */
|
|
|
|
if (ScanCode & 0x0200)
|
|
|
|
bExtendedKey = TRUE;
|
|
|
|
else
|
|
|
|
bExtendedKey = FALSE;
|
2021-08-11 19:36:30 +00:00
|
|
|
ScanCode &= SCANCODE_MASK;
|
2014-12-05 22:09:10 +00:00
|
|
|
|
|
|
|
/* Release the key */
|
|
|
|
Input.type = INPUT_KEYBOARD;
|
|
|
|
Input.ki.wVk = 0;
|
|
|
|
Input.ki.wScan = ScanCode;
|
|
|
|
Input.ki.time = GetTickCount();
|
|
|
|
Input.ki.dwExtraInfo = GetMessageExtraInfo();
|
|
|
|
Input.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
|
|
|
|
if (bExtendedKey) Input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
|
|
|
|
SendInput(1, &Input, sizeof(Input));
|
|
|
|
|
|
|
|
return TRUE;
|
2014-12-05 21:43:00 +00:00
|
|
|
}
|
|
|
|
|
2019-04-22 13:01:18 +00:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
2021-08-11 19:36:30 +00:00
|
|
|
* OSK_Paint
|
2019-04-22 13:01:18 +00:00
|
|
|
*
|
2021-08-11 19:36:30 +00:00
|
|
|
* Handles WM_PAINT messages
|
2019-04-22 13:01:18 +00:00
|
|
|
*/
|
2021-08-11 19:36:30 +00:00
|
|
|
LRESULT OSK_Paint(HWND hwnd)
|
2019-04-22 13:01:18 +00:00
|
|
|
{
|
2021-08-11 19:36:30 +00:00
|
|
|
PAINTSTRUCT ps;
|
|
|
|
RECT rcText;
|
|
|
|
HFONT hOldFont = NULL;
|
|
|
|
WCHAR szTemp[MAX_PATH];
|
2019-04-22 13:01:18 +00:00
|
|
|
|
2021-08-11 19:36:30 +00:00
|
|
|
HDC hdc = BeginPaint(hwnd, &ps);
|
2019-04-22 13:01:18 +00:00
|
|
|
|
2021-08-11 19:36:30 +00:00
|
|
|
if (Globals.hFont)
|
|
|
|
hOldFont = SelectObject(hdc, Globals.hFont);
|
2019-04-22 13:01:18 +00:00
|
|
|
|
2021-08-11 19:36:30 +00:00
|
|
|
rcText.left = Globals.Keyboard->LedTextStart.x;
|
|
|
|
rcText.top = Globals.Keyboard->LedTextStart.y;
|
|
|
|
rcText.right = rcText.left + Globals.Keyboard->LedTextSize.cx;
|
|
|
|
rcText.bottom = rcText.top + Globals.Keyboard->LedTextSize.cy;
|
2019-05-01 08:33:13 +00:00
|
|
|
|
2021-08-11 19:36:30 +00:00
|
|
|
LoadStringW(Globals.hInstance, IDS_NUMLOCK, szTemp, _countof(szTemp));
|
|
|
|
DrawTextW(hdc, szTemp, -1, &rcText, DT_NOCLIP);
|
2019-05-01 08:33:13 +00:00
|
|
|
|
2021-08-11 19:36:30 +00:00
|
|
|
OffsetRect(&rcText, Globals.Keyboard->LedTextOffset, 0);
|
|
|
|
|
|
|
|
LoadStringW(Globals.hInstance, IDS_CAPSLOCK, szTemp, _countof(szTemp));
|
|
|
|
DrawTextW(hdc, szTemp, -1, &rcText, DT_NOCLIP);
|
2019-04-22 13:01:18 +00:00
|
|
|
|
2021-08-11 19:36:30 +00:00
|
|
|
OffsetRect(&rcText, Globals.Keyboard->LedTextOffset, 0);
|
|
|
|
|
|
|
|
LoadStringW(Globals.hInstance, IDS_SCROLLLOCK, szTemp, _countof(szTemp));
|
|
|
|
DrawTextW(hdc, szTemp, -1, &rcText, DT_NOCLIP);
|
2019-05-01 08:33:13 +00:00
|
|
|
|
2021-08-11 19:36:30 +00:00
|
|
|
if (hOldFont)
|
|
|
|
SelectObject(hdc, hOldFont);
|
2019-04-22 13:01:18 +00:00
|
|
|
|
2021-08-11 19:36:30 +00:00
|
|
|
EndPaint(hwnd, &ps);
|
2019-04-22 13:01:18 +00:00
|
|
|
|
2021-08-11 19:36:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-12-05 21:43:00 +00:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
2021-08-11 19:36:30 +00:00
|
|
|
* OSK_WndProc
|
2014-12-05 21:43:00 +00:00
|
|
|
*/
|
2021-08-11 19:36:30 +00:00
|
|
|
LRESULT APIENTRY OSK_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
2014-12-05 21:43:00 +00:00
|
|
|
{
|
2014-12-05 22:09:10 +00:00
|
|
|
switch (msg)
|
2014-12-05 21:43:00 +00:00
|
|
|
{
|
2021-08-11 19:36:30 +00:00
|
|
|
case WM_CREATE:
|
|
|
|
return OSK_Create(hwnd);
|
2014-12-05 22:09:10 +00:00
|
|
|
|
2021-08-11 19:36:30 +00:00
|
|
|
case WM_PAINT:
|
|
|
|
return OSK_Paint(hwnd);
|
2014-12-05 22:09:10 +00:00
|
|
|
|
2021-08-11 19:36:30 +00:00
|
|
|
case WM_TIMER:
|
|
|
|
return OSK_Timer();
|
2019-04-22 13:01:18 +00:00
|
|
|
|
2014-12-05 22:09:10 +00:00
|
|
|
case WM_CTLCOLORSTATIC:
|
2021-08-11 19:36:30 +00:00
|
|
|
if ((HWND)lParam == GetDlgItem(hwnd, IDC_LED_NUM))
|
2014-12-05 22:09:10 +00:00
|
|
|
{
|
|
|
|
if (GetKeyState(VK_NUMLOCK) & 0x0001)
|
2021-08-11 19:36:30 +00:00
|
|
|
return (LRESULT)Globals.hBrushGreenLed;
|
2014-12-05 22:09:10 +00:00
|
|
|
else
|
2021-08-11 19:36:30 +00:00
|
|
|
return (LRESULT)GetStockObject(BLACK_BRUSH);
|
2014-12-05 22:09:10 +00:00
|
|
|
}
|
2021-08-11 19:36:30 +00:00
|
|
|
if ((HWND)lParam == GetDlgItem(hwnd, IDC_LED_CAPS))
|
2014-12-05 22:09:10 +00:00
|
|
|
{
|
|
|
|
if (GetKeyState(VK_CAPITAL) & 0x0001)
|
2021-08-11 19:36:30 +00:00
|
|
|
return (LRESULT)Globals.hBrushGreenLed;
|
2014-12-05 22:09:10 +00:00
|
|
|
else
|
2021-08-11 19:36:30 +00:00
|
|
|
return (LRESULT)GetStockObject(BLACK_BRUSH);
|
2014-12-05 22:09:10 +00:00
|
|
|
}
|
2021-08-11 19:36:30 +00:00
|
|
|
if ((HWND)lParam == GetDlgItem(hwnd, IDC_LED_SCROLL))
|
2014-12-05 22:09:10 +00:00
|
|
|
{
|
|
|
|
if (GetKeyState(VK_SCROLL) & 0x0001)
|
2021-08-11 19:36:30 +00:00
|
|
|
return (LRESULT)Globals.hBrushGreenLed;
|
2014-12-05 22:09:10 +00:00
|
|
|
else
|
2021-08-11 19:36:30 +00:00
|
|
|
return (LRESULT)GetStockObject(BLACK_BRUSH);
|
2014-12-05 22:09:10 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
2019-01-27 16:35:26 +00:00
|
|
|
switch (LOWORD(wParam))
|
|
|
|
{
|
|
|
|
case IDM_EXIT:
|
|
|
|
{
|
2021-08-11 19:36:30 +00:00
|
|
|
PostMessageW(hwnd, WM_CLOSE, 0, 0);
|
2019-01-27 16:35:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-02-10 15:04:16 +00:00
|
|
|
case IDM_ENHANCED_KB:
|
|
|
|
{
|
|
|
|
if (!Globals.bIsEnhancedKeyboard)
|
|
|
|
{
|
2019-05-01 08:33:13 +00:00
|
|
|
/*
|
2019-02-10 15:04:16 +00:00
|
|
|
The user attempted to switch to enhanced keyboard dialog type.
|
|
|
|
Set the member value as TRUE, destroy the dialog and save the data configuration into the registry.
|
|
|
|
*/
|
|
|
|
Globals.bIsEnhancedKeyboard = TRUE;
|
2019-12-11 23:25:55 +00:00
|
|
|
SaveSettings();
|
2019-02-10 15:04:16 +00:00
|
|
|
|
|
|
|
/* Change the condition of enhanced keyboard item menu to checked */
|
2021-08-11 19:36:30 +00:00
|
|
|
CheckMenuItem(GetMenu(hwnd), IDM_ENHANCED_KB, MF_BYCOMMAND | MF_CHECKED);
|
|
|
|
CheckMenuItem(GetMenu(hwnd), IDM_STANDARD_KB, MF_BYCOMMAND | MF_UNCHECKED);
|
2019-02-10 15:04:16 +00:00
|
|
|
|
2021-08-11 19:36:30 +00:00
|
|
|
/* Finally, update the key layout */
|
|
|
|
LoadSettings();
|
|
|
|
OSK_SetKeys(SETKEYS_LAYOUT);
|
2019-02-10 15:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IDM_STANDARD_KB:
|
|
|
|
{
|
|
|
|
if (Globals.bIsEnhancedKeyboard)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
The user attempted to switch to standard keyboard dialog type.
|
|
|
|
Set the member value as FALSE, destroy the dialog and save the data configuration into the registry.
|
|
|
|
*/
|
|
|
|
Globals.bIsEnhancedKeyboard = FALSE;
|
2019-12-11 23:25:55 +00:00
|
|
|
SaveSettings();
|
2019-02-10 15:04:16 +00:00
|
|
|
|
|
|
|
/* Change the condition of standard keyboard item menu to checked */
|
2021-08-11 19:36:30 +00:00
|
|
|
CheckMenuItem(GetMenu(hwnd), IDM_ENHANCED_KB, MF_BYCOMMAND | MF_UNCHECKED);
|
|
|
|
CheckMenuItem(GetMenu(hwnd), IDM_STANDARD_KB, MF_BYCOMMAND | MF_CHECKED);
|
2019-07-21 14:52:25 +00:00
|
|
|
|
2021-08-11 19:36:30 +00:00
|
|
|
/* Finally, update the key layout */
|
|
|
|
LoadSettings();
|
|
|
|
OSK_SetKeys(SETKEYS_LAYOUT);
|
2019-02-10 15:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-02-24 15:40:02 +00:00
|
|
|
case IDM_CLICK_SOUND:
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
This case is triggered when the user attempts to click on the menu item. Before doing anything,
|
|
|
|
we must check the condition state of such menu item so that we can tick/untick the menu item accordingly.
|
|
|
|
*/
|
|
|
|
if (!Globals.bSoundClick)
|
|
|
|
{
|
|
|
|
Globals.bSoundClick = TRUE;
|
2021-08-11 19:36:30 +00:00
|
|
|
CheckMenuItem(GetMenu(hwnd), IDM_CLICK_SOUND, MF_BYCOMMAND | MF_CHECKED);
|
2019-02-24 15:40:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Globals.bSoundClick = FALSE;
|
2021-08-11 19:36:30 +00:00
|
|
|
CheckMenuItem(GetMenu(hwnd), IDM_CLICK_SOUND, MF_BYCOMMAND | MF_UNCHECKED);
|
2019-02-24 15:40:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-07-15 13:59:06 +00:00
|
|
|
case IDM_ON_TOP:
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Check the condition state before disabling/enabling the menu
|
|
|
|
item and change the topmost order.
|
|
|
|
*/
|
|
|
|
if (!Globals.bAlwaysOnTop)
|
|
|
|
{
|
|
|
|
Globals.bAlwaysOnTop = TRUE;
|
2021-08-11 19:36:30 +00:00
|
|
|
CheckMenuItem(GetMenu(hwnd), IDM_ON_TOP, MF_BYCOMMAND | MF_CHECKED);
|
|
|
|
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
|
2019-07-15 13:59:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Globals.bAlwaysOnTop = FALSE;
|
2021-08-11 19:36:30 +00:00
|
|
|
CheckMenuItem(GetMenu(hwnd), IDM_ON_TOP, MF_BYCOMMAND | MF_UNCHECKED);
|
|
|
|
SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
|
2019-07-15 13:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-08-11 19:36:30 +00:00
|
|
|
case IDM_FONT:
|
|
|
|
{
|
|
|
|
OSK_ChooseFont();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-01-27 16:35:26 +00:00
|
|
|
case IDM_ABOUT:
|
|
|
|
{
|
|
|
|
OSK_About();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2021-08-11 19:36:30 +00:00
|
|
|
OSK_Command(wParam, (HWND)lParam);
|
2019-01-27 16:35:26 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-08-11 19:36:30 +00:00
|
|
|
return 0;
|
2014-12-05 22:09:10 +00:00
|
|
|
|
2019-04-22 13:01:18 +00:00
|
|
|
case WM_THEMECHANGED:
|
|
|
|
/* Redraw the dialog (and its control buttons) using the new theme */
|
2021-08-11 19:36:30 +00:00
|
|
|
InvalidateRect(hwnd, NULL, FALSE);
|
|
|
|
return 0;
|
2019-04-22 13:01:18 +00:00
|
|
|
|
2014-12-05 22:09:10 +00:00
|
|
|
case WM_CLOSE:
|
2021-08-11 19:36:30 +00:00
|
|
|
OSK_Close();
|
|
|
|
PostQuitMessage(0);
|
|
|
|
return 0;
|
2014-12-05 21:43:00 +00:00
|
|
|
}
|
2021-08-11 19:36:30 +00:00
|
|
|
return DefWindowProcW(hwnd, msg, wParam, lParam);
|
2014-12-05 21:43:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* WinMain
|
|
|
|
*/
|
2019-01-23 12:28:56 +00:00
|
|
|
int WINAPI wWinMain(HINSTANCE hInstance,
|
|
|
|
HINSTANCE prev,
|
|
|
|
LPWSTR cmdline,
|
|
|
|
int show)
|
2014-12-05 21:43:00 +00:00
|
|
|
{
|
2019-03-24 08:40:43 +00:00
|
|
|
DWORD dwError;
|
2021-08-11 19:36:30 +00:00
|
|
|
HANDLE hMutex;
|
2019-03-28 15:09:16 +00:00
|
|
|
INITCOMMONCONTROLSEX iccex;
|
2021-08-11 19:36:30 +00:00
|
|
|
WNDCLASSEXW wc = {0};
|
|
|
|
MSG msg;
|
|
|
|
HWND hwnd;
|
2014-12-05 21:43:00 +00:00
|
|
|
|
2014-12-05 22:09:10 +00:00
|
|
|
UNREFERENCED_PARAMETER(prev);
|
|
|
|
UNREFERENCED_PARAMETER(cmdline);
|
|
|
|
UNREFERENCED_PARAMETER(show);
|
2014-12-05 21:43:00 +00:00
|
|
|
|
2019-03-24 08:40:43 +00:00
|
|
|
/*
|
|
|
|
Obtain a mutex for the program. This will ensure that
|
|
|
|
the program is launched only once.
|
|
|
|
*/
|
|
|
|
hMutex = CreateMutexW(NULL, FALSE, L"OSKRunning");
|
|
|
|
|
|
|
|
if (hMutex)
|
|
|
|
{
|
|
|
|
/* Check if there's already a mutex for the program */
|
|
|
|
dwError = GetLastError();
|
|
|
|
|
|
|
|
if (dwError == ERROR_ALREADY_EXISTS)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
A mutex with the object name has been created previously.
|
|
|
|
Therefore, another instance is already running.
|
|
|
|
*/
|
|
|
|
DPRINT("wWinMain(): Failed to create a mutex! The program instance is already running.\n");
|
|
|
|
CloseHandle(hMutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-28 15:09:16 +00:00
|
|
|
/* Load the common controls */
|
|
|
|
iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
|
|
|
|
iccex.dwICC = ICC_STANDARD_CLASSES | ICC_WIN95_CLASSES;
|
|
|
|
InitCommonControlsEx(&iccex);
|
|
|
|
|
2014-12-05 22:09:10 +00:00
|
|
|
ZeroMemory(&Globals, sizeof(Globals));
|
|
|
|
Globals.hInstance = hInstance;
|
2014-12-05 21:43:00 +00:00
|
|
|
|
2019-12-11 23:25:55 +00:00
|
|
|
/* Load the application's settings from the registry */
|
|
|
|
LoadSettings();
|
2019-02-10 15:04:16 +00:00
|
|
|
|
2021-08-11 19:36:30 +00:00
|
|
|
/* Define the window class */
|
|
|
|
wc.cbSize = sizeof(wc);
|
|
|
|
wc.hInstance = Globals.hInstance;
|
|
|
|
wc.lpfnWndProc = OSK_WndProc;
|
|
|
|
wc.lpszMenuName = MAKEINTRESOURCEW(IDR_OSK_MENU);
|
|
|
|
wc.lpszClassName = OSK_CLASS;
|
|
|
|
wc.style = CS_HREDRAW | CS_VREDRAW;
|
|
|
|
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
|
|
|
|
/* Set the application's icon */
|
|
|
|
wc.hIcon = LoadImageW(Globals.hInstance, MAKEINTRESOURCEW(IDI_OSK), IMAGE_ICON, 0, 0, LR_SHARED | LR_DEFAULTSIZE);
|
|
|
|
wc.hIconSm = CopyImage(wc.hIcon, IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_COPYFROMRESOURCE);
|
|
|
|
|
|
|
|
if (!RegisterClassExW(&wc))
|
|
|
|
goto quit;
|
|
|
|
|
|
|
|
/* Load window title */
|
|
|
|
LoadStringW(Globals.hInstance, IDS_OSK, Globals.szTitle, _countof(Globals.szTitle));
|
|
|
|
|
|
|
|
hwnd = CreateWindowExW(WS_EX_TOPMOST | WS_EX_APPWINDOW | WS_EX_NOACTIVATE,
|
|
|
|
OSK_CLASS,
|
|
|
|
Globals.szTitle,
|
|
|
|
WS_SYSMENU | WS_MINIMIZEBOX,
|
|
|
|
CW_USEDEFAULT,
|
|
|
|
CW_USEDEFAULT,
|
|
|
|
CW_USEDEFAULT,
|
|
|
|
CW_USEDEFAULT,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
Globals.hInstance,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (!hwnd)
|
|
|
|
goto quit;
|
|
|
|
|
|
|
|
ShowWindow(hwnd, SW_SHOW);
|
|
|
|
UpdateWindow(hwnd);
|
|
|
|
|
|
|
|
while (GetMessageW(&msg, NULL, 0, 0))
|
2019-02-10 15:04:16 +00:00
|
|
|
{
|
2021-08-11 19:36:30 +00:00
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessageW(&msg);
|
2019-02-10 15:04:16 +00:00
|
|
|
}
|
|
|
|
|
2021-08-11 19:36:30 +00:00
|
|
|
quit:
|
2019-03-24 08:40:43 +00:00
|
|
|
/* Delete the mutex */
|
|
|
|
if (hMutex)
|
2014-12-05 22:09:10 +00:00
|
|
|
{
|
|
|
|
CloseHandle(hMutex);
|
|
|
|
}
|
2014-12-05 21:43:00 +00:00
|
|
|
|
2014-12-05 22:09:10 +00:00
|
|
|
return 0;
|
2014-12-05 21:43:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|