Add ExternalHelpers project and move all externally acquired dependencies there

This commit is contained in:
Kamil Trzciński 2022-11-20 15:12:12 +01:00
parent b06ac16fba
commit e376b9dcc8
24 changed files with 457 additions and 574 deletions

View file

@ -20,7 +20,7 @@ namespace PowerControl.Helpers
{
try
{
processId = (int?)Helpers.TopLevelWindow.GetTopLevelProcessId();
processId = (int?)GetTopLevelProcessId();
if (processId is null)
return false;
@ -81,11 +81,17 @@ namespace PowerControl.Helpers
}
}
[DllImport("kernel32.dll", EntryPoint = "GetModuleHandleW", SetLastError = true)]
public static extern IntPtr GetModuleHandle(string moduleName);
public static uint EnableFlag(uint flag, bool status)
{
var current = SetFlags(~flag, status ? flag : 0);
UpdateSettings();
return current;
}
[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Ansi)]
static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)] string lpFileName);
public static void UpdateSettings()
{
PostMessage(WM_RTSS_UPDATESETTINGS, IntPtr.Zero, IntPtr.Zero);
}
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
@ -118,6 +124,21 @@ namespace PowerControl.Helpers
[DllImport("C:\\Program Files (x86)\\RivaTuner Statistics Server\\RTSSHooks64.dll", CharSet = CharSet.Ansi)]
public static extern void UpdateProfiles();
[DllImport("user32.dll", SetLastError = true)]
static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
private static uint? GetTopLevelProcessId()
{
var hWnd = GetForegroundWindow();
var result = GetWindowThreadProcessId(hWnd, out uint processId);
if (result != 0)
return processId;
return null;
}
private static void PostMessage(uint Msg, IntPtr wParam, IntPtr lParam)
{
var hWnd = FindWindow(null, "RTSS");
@ -128,18 +149,6 @@ namespace PowerControl.Helpers
PostMessage(hWnd, Msg, wParam, lParam);
}
public static uint EnableFlag(uint flag, bool status)
{
var current = SetFlags(~flag, status ? flag : 0);
UpdateSettings();
return current;
}
public static void UpdateSettings()
{
PostMessage(WM_RTSS_UPDATESETTINGS, IntPtr.Zero, IntPtr.Zero);
}
public const uint WM_APP = 0x8000;
public const uint WM_RTSS_UPDATESETTINGS = WM_APP + 100;
public const uint WM_RTSS_SHOW_PROPERTIES = WM_APP + 102;