mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
KBM - Set treat warnings as errors, and clean up the dllmain.cpp file (#3203)
* Add test proj, refactor proj with filters, and move single remap function to a separate header * Moved all methods to header files * remove more unused commented code * Undo test project addition * Treat warnings as errors
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "Helpers.h"
|
||||
#include <sstream>
|
||||
#include "../common/shared_constants.h"
|
||||
#include <shlwapi.h>
|
||||
|
||||
using namespace winrt::Windows::Foundation;
|
||||
|
||||
@@ -163,4 +164,63 @@ namespace KeyboardManagerHelper
|
||||
return L"Unexpected error";
|
||||
}
|
||||
}
|
||||
|
||||
// Function to set the value of a key event based on the arguments
|
||||
void SetKeyEvent(LPINPUT keyEventArray, int index, DWORD inputType, WORD keyCode, DWORD flags, ULONG_PTR extraInfo)
|
||||
{
|
||||
keyEventArray[index].type = inputType;
|
||||
keyEventArray[index].ki.wVk = keyCode;
|
||||
keyEventArray[index].ki.dwFlags = flags;
|
||||
if (IsExtendedKey(keyCode))
|
||||
{
|
||||
keyEventArray[index].ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
|
||||
}
|
||||
keyEventArray[index].ki.dwExtraInfo = extraInfo;
|
||||
}
|
||||
|
||||
// Function to return the window in focus
|
||||
HWND GetFocusWindowHandle()
|
||||
{
|
||||
// Using GetGUIThreadInfo for getting the process of the window in focus. GetForegroundWindow has issues with UWP apps as it returns the Application Frame Host as its linked process
|
||||
GUITHREADINFO guiThreadInfo;
|
||||
guiThreadInfo.cbSize = sizeof(GUITHREADINFO);
|
||||
GetGUIThreadInfo(0, &guiThreadInfo);
|
||||
|
||||
// If no window in focus, use the active window
|
||||
if (guiThreadInfo.hwndFocus == nullptr)
|
||||
{
|
||||
return guiThreadInfo.hwndActive;
|
||||
}
|
||||
return guiThreadInfo.hwndFocus;
|
||||
}
|
||||
|
||||
// Function to return the executable name of the application in focus
|
||||
std::wstring GetCurrentApplication(bool keepPath)
|
||||
{
|
||||
HWND current_window_handle = GetFocusWindowHandle();
|
||||
DWORD process_id;
|
||||
DWORD nSize = MAX_PATH;
|
||||
WCHAR buffer[MAX_PATH] = { 0 };
|
||||
|
||||
// Get process ID of the focus window
|
||||
DWORD thread_id = GetWindowThreadProcessId(current_window_handle, &process_id);
|
||||
HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, process_id);
|
||||
|
||||
// Get full path of the executable
|
||||
bool res = QueryFullProcessImageName(hProc, 0, buffer, &nSize);
|
||||
std::wstring process_name;
|
||||
CloseHandle(hProc);
|
||||
|
||||
process_name = buffer;
|
||||
if (res)
|
||||
{
|
||||
PathStripPath(buffer);
|
||||
|
||||
if (!keepPath)
|
||||
{
|
||||
process_name = buffer;
|
||||
}
|
||||
}
|
||||
return process_name;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user