Fixed some warnings and added code to close active windows on disable (#2915)

This commit is contained in:
Arjun Balgovind 2020-05-12 15:58:11 -07:00 committed by GitHub
parent a1e1d663c3
commit ce96e34d25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 21 deletions

View File

@ -56,7 +56,7 @@ namespace KeyboardManagerConstants
inline const long RemapTableArrowColIndex = 1;
inline const long RemapTableNewColIndex = 2;
inline const long RemapTableRemoveColIndex = 3;
inline const long RemapTableDropDownWidth = 110;
inline const DWORD RemapTableDropDownWidth = 110;
// Shortcut table constants
inline const long ShortcutTableColCount = 4;
@ -65,14 +65,14 @@ namespace KeyboardManagerConstants
inline const long ShortcutTableArrowColIndex = 1;
inline const long ShortcutTableNewColIndex = 2;
inline const long ShortcutTableRemoveColIndex = 3;
inline const long ShortcutTableDropDownWidth = 110;
inline const long ShortcutTableDropDownSpacing = 10;
inline const DWORD ShortcutTableDropDownWidth = 110;
inline const DWORD ShortcutTableDropDownSpacing = 10;
// Drop down height used for both Edit Keyboard and Edit Shortcuts
inline const long TableDropDownHeight = 200;
inline const long TableArrowColWidth = 20;
inline const long TableRemoveColWidth = 20;
inline const long TableWarningColWidth = 20;
inline const DWORD TableDropDownHeight = 200;
inline const DWORD TableArrowColWidth = 20;
inline const DWORD TableRemoveColWidth = 20;
inline const DWORD TableWarningColWidth = 20;
// Shared style constants for both Remap Table and Shortcut Table
inline const double HeaderButtonWidth = 100;

View File

@ -279,6 +279,9 @@ public:
m_enabled = false;
// Log telemetry
Trace::EnableKeyboardManager(false);
// Close active windows
CloseActiveEditKeyboardWindow();
CloseActiveEditShortcutsWindow();
// Stop keyboard hook
stop_lowlevel_keyboard_hook();
}

View File

@ -147,12 +147,12 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan
windowClass.hInstance = hInst;
windowClass.lpszClassName = szWindowClass;
windowClass.hbrBackground = (HBRUSH)(COLOR_WINDOW);
windowClass.hIcon = (HICON) LoadImageW(
windowClass.hInstance,
MAKEINTRESOURCE(IDS_KEYBOARDMANAGER_ICON),
IMAGE_ICON,
48,
48,
windowClass.hIcon = (HICON)LoadImageW(
windowClass.hInstance,
MAKEINTRESOURCE(IDS_KEYBOARDMANAGER_ICON),
IMAGE_ICON,
48,
48,
LR_DEFAULTCOLOR);
if (RegisterClassEx(&windowClass) == NULL)
{
@ -175,7 +175,7 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan
HWND _hWndEditKeyboardWindow = CreateWindow(
szWindowClass,
L"Remap Keyboard",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MAXIMIZEBOX,
(desktopRect.right / 2) - (windowWidth / 2),
(desktopRect.bottom / 2) - (windowHeight / 2),
windowWidth,
@ -493,3 +493,13 @@ bool CheckEditKeyboardWindowActive()
return result;
}
// Function to close any active Edit Keyboard window
void CloseActiveEditKeyboardWindow()
{
std::unique_lock<std::mutex> hwndLock(editKeyboardWindowMutex);
if (hwndEditKeyboardNativeWindow != nullptr)
{
PostMessage(hwndEditKeyboardNativeWindow, WM_CLOSE, 0, 0);
}
}

View File

@ -5,4 +5,7 @@
void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardManagerState);
// Function to check if there is already a window active if yes bring to foreground
bool CheckEditKeyboardWindowActive();
bool CheckEditKeyboardWindowActive();
// Function to close any active Edit Keyboard window
void CloseActiveEditKeyboardWindow();

View File

@ -61,10 +61,10 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa
windowClass.hbrBackground = (HBRUSH)(COLOR_WINDOW);
windowClass.hIcon = (HICON)LoadImageW(
windowClass.hInstance,
MAKEINTRESOURCE(IDS_KEYBOARDMANAGER_ICON),
IMAGE_ICON,
48,
48,
MAKEINTRESOURCE(IDS_KEYBOARDMANAGER_ICON),
IMAGE_ICON,
48,
48,
LR_DEFAULTCOLOR);
if (RegisterClassEx(&windowClass) == NULL)
{
@ -87,7 +87,7 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa
HWND _hWndEditShortcutsWindow = CreateWindow(
szWindowClass,
L"Remap Shortcuts",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MAXIMIZEBOX,
(desktopRect.right / 2) - (windowWidth / 2),
(desktopRect.bottom / 2) - (windowHeight / 2),
windowWidth,
@ -377,3 +377,13 @@ bool CheckEditShortcutsWindowActive()
return result;
}
// Function to close any active Edit Shortcuts window
void CloseActiveEditShortcutsWindow()
{
std::unique_lock<std::mutex> hwndLock(editShortcutsWindowMutex);
if (hwndEditShortcutsNativeWindow != nullptr)
{
PostMessage(hwndEditShortcutsNativeWindow, WM_CLOSE, 0, 0);
}
}

View File

@ -7,4 +7,7 @@
void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardManagerState);
// Function to check if there is already a window active if yes bring to foreground
bool CheckEditShortcutsWindowActive();
bool CheckEditShortcutsWindowActive();
// Function to close any active Edit Shortcuts window
void CloseActiveEditShortcutsWindow();