| 4 | namespace PenguLoader.Main |
| 5 | { |
| 6 | static class Native |
| 7 | { |
| 8 | public static IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong) |
| 9 | { |
| 10 | return IntPtr.Size == 8 |
| 11 | ? SetWindowLongPtr64(hWnd, nIndex, dwNewLong) |
| 12 | : new IntPtr(SetWindowLong32(hWnd, nIndex, dwNewLong.ToInt32())); |
| 13 | } |
| 14 | |
| 15 | public static IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex) |
| 16 | { |
| 17 | return IntPtr.Size == 8 |
| 18 | ? GetWindowLongPtr64(hWnd, nIndex) |
| 19 | : GetWindowLongPtr32(hWnd, nIndex); |
| 20 | } |
| 21 | |
| 22 | public static void SetFocusToPreviousInstance() |
| 23 | { |
| 24 | PostMessage((IntPtr)HWND_BROADCAST, WM_SHOWME, IntPtr.Zero, IntPtr.Zero); |
| 25 | } |
| 26 | |
| 27 | const int HWND_BROADCAST = 0xFFFF; |
| 28 | |
| 29 | public static readonly int WM_SHOWME = RegisterWindowMessage(Program.Name); |
| 30 | |
| 31 | [DllImport("user32.dll", EntryPoint = "SetWindowLong")] |
| 32 | static extern int SetWindowLong32(IntPtr hWnd, int nIndex, int dwNewLong); |
| 33 | |
| 34 | [DllImport("user32.dll", EntryPoint = "SetWindowLongPtr")] |
| 35 | static extern IntPtr SetWindowLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong); |
| 36 | |
| 37 | [DllImport("user32.dll", EntryPoint = "GetWindowLong")] |
| 38 | private static extern IntPtr GetWindowLongPtr32(IntPtr hWnd, int nIndex); |
| 39 | |
| 40 | [DllImport("user32.dll", EntryPoint = "GetWindowLongPtr")] |
| 41 | private static extern IntPtr GetWindowLongPtr64(IntPtr hWnd, int nIndex); |
| 42 | |
| 43 | [DllImport("user32.dll", EntryPoint = "RegisterWindowMessageW", CharSet = CharSet.Unicode)] |
| 44 | static extern int RegisterWindowMessage(string message); |
| 45 | |
| 46 | [DllImport("user32.dll", EntryPoint = "PostMessageW")] |
| 47 | [return: MarshalAs(UnmanagedType.Bool)] |
| 48 | static extern bool PostMessage(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam); |
| 49 | } |
| 50 | } |
nothing calls this directly
no outgoing calls
no test coverage detected