-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
125 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,13 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": ".NET Core Launch (console)", | ||
"name": "Launch", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build", | ||
"program": "${workspaceFolder}/bin/Debug/net7.0/ReMOSD.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}", | ||
"console": "externalTerminal", | ||
"stopAtEntry": false | ||
}, | ||
{ | ||
"name": ".NET Core Attach", | ||
"type": "coreclr", | ||
"request": "attach" | ||
"preLaunchTask": "Build", | ||
"program": "${workspaceFolder}/bin/ReMOSD.dll", | ||
"console": "integratedTerminal" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Runtime.InteropServices; | ||
using System.Threading; | ||
|
||
using static ReMOSD.PInvoke; | ||
|
||
namespace ReMOSD; | ||
|
||
class MediaOsd | ||
{ | ||
public nint HWnd { get; private set; } | ||
|
||
MediaOsd() {} | ||
|
||
public void SetRegion(nint value) | ||
{ | ||
var result = SetWindowRgn(HWnd, value, true); | ||
if (result == 0) throw new Win32Exception(Marshal.GetLastWin32Error()); | ||
} | ||
|
||
public uint GetDpi() | ||
{ | ||
var dpi = GetDpiForWindow(HWnd); | ||
if (dpi == 0) throw new Win32Exception(Marshal.GetLastWin32Error()); | ||
|
||
return dpi; | ||
} | ||
|
||
public static MediaOsd Find() | ||
{ | ||
var shellHWnd = GetShellWindow(); | ||
|
||
// Trigger show volume control window so it is created and can be found later | ||
// (to pack APPCOMMAND lParam https://stackoverflow.com/a/29301152/18449435) | ||
// (https://forums.codeguru.com/showthread.php?147192-How-to-construct-WM_APPCOMMAND-message) | ||
SendMessage(shellHWnd, WM_APPCOMMAND, 0, (int)APPCOMMAND_VOLUME_MUTE << 16); | ||
SendMessage(shellHWnd, WM_APPCOMMAND, 0, (int)APPCOMMAND_VOLUME_MUTE << 16); | ||
|
||
var hWnd = default(nint); | ||
for (var attempt = 1; attempt <= 5; ++attempt) | ||
{ | ||
hWnd = FindWindowExA(default, default, "NativeHWNDHost\0", default); | ||
if (hWnd != default) break; | ||
|
||
Thread.Sleep(250); | ||
} | ||
if (hWnd == default) throw new InvalidOperationException("Media OSD was not found :("); | ||
|
||
var osd = new MediaOsd() { | ||
HWnd = hWnd | ||
}; | ||
return osd; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Runtime.InteropServices; | ||
|
||
namespace ReMOSD; | ||
|
||
static partial class PInvoke | ||
{ | ||
/// <summary> https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-appcommand </summary> | ||
public const uint WM_APPCOMMAND = 793; | ||
|
||
/// <summary> https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-appcommand </summary> | ||
public const uint APPCOMMAND_VOLUME_MUTE = 8; | ||
|
||
/// <summary> https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowrgn </summary> | ||
[DllImport("user32.dll")] | ||
public static extern int SetWindowRgn(nint hWnd, nint hRgn, bool bRedraw); | ||
|
||
/// <summary> https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdpiforwindow </summary> | ||
[DllImport("user32.dll")] | ||
public static extern uint GetDpiForWindow(nint hWnd); | ||
|
||
/// <summary> https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getshellwindow </summary> | ||
[DllImport("user32.dll")] | ||
public static extern nint GetShellWindow(); | ||
|
||
/// <summary> https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage </summary> | ||
[DllImport("user32.dll")] | ||
public static extern nint SendMessage(nint hWnd, uint Msg, nint wParam, nint lParam); | ||
|
||
/// <summary> https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-findwindowexa </summary> | ||
[DllImport("user32.dll")] | ||
public static extern nint FindWindowExA(nint hWndParent, nint hWndChildAfter, string lpszClass, string? lpszWindow); | ||
|
||
/// <summary> https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createrectrgn </summary> | ||
[DllImport("gdi32.dll")] | ||
public static extern nint CreateRectRgn(int x1, int y1, int x2, int y2); | ||
|
||
/// <summary> https://learn.microsoft.com/en-us/windows/console/allocconsole </summary> | ||
[DllImport("kernel32.dll")] | ||
public static extern bool AllocConsole(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters