Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/AlwaysOnTopper.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis von der Eltz <luisvde@outlook.de>2020-05-04 22:14:26 +0300
committerLuis von der Eltz <luisvde@outlook.de>2020-05-04 22:14:26 +0300
commit2cc4dc6cab37b0f7897317f6561332be5d88bd44 (patch)
treebbab987243bc64a3fb39535e53f535e36d4e6ae6
parent1a231cdcb1dd54d50ce482aaf9df74f9c3a535d3 (diff)
Getting rid of form for event pump
-rw-r--r--Program.cs41
1 files changed, 32 insertions, 9 deletions
diff --git a/Program.cs b/Program.cs
index 08736d1..7952ed6 100644
--- a/Program.cs
+++ b/Program.cs
@@ -27,6 +27,33 @@ namespace AlwaysOnTopper
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
+ [StructLayout(LayoutKind.Sequential)]
+ public struct POINT
+ {
+ public int X;
+ public int Y;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ public struct MSG
+ {
+ IntPtr hwnd;
+ uint message;
+ UIntPtr wParam;
+ IntPtr lParam;
+ int time;
+ POINT pt;
+ }
+
+ [DllImport("user32.dll")]
+ static extern sbyte GetMessage(out MSG lpMsg, IntPtr hWnd, uint wMsgFilterMin, uint wMsgFilterMax);
+
+ [DllImport("user32.dll")]
+ static extern bool TranslateMessage([In] ref MSG lpMsg);
+
+ [DllImport("user32.dll")]
+ static extern IntPtr DispatchMessage([In] ref MSG lpmsg);
+
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool GetMenuItemInfo(IntPtr hMenu, UInt32 uItem, bool fByPosition, [In, Out] MENUITEMINFO lpmii);
@@ -317,16 +344,12 @@ namespace AlwaysOnTopper
SetWinEventHook(EVENT_OBJECT_FOCUS, EVENT_OBJECT_FOCUS, IntPtr.Zero,
WinEventObjectFocus, 0, 0, WINEVENT_OUTOFCONTEXT);
-
- // Dumb form for message queue
- var form = new Form();
- form.Load += new EventHandler((object o, EventArgs e) =>
- {
- form.WindowState = FormWindowState.Minimized;
- form.ShowInTaskbar = false;
- });
- Application.Run(form);
+ while (GetMessage(out var message, IntPtr.Zero, 0, 0) > 0) {
+ TranslateMessage(ref message);
+ DispatchMessage(ref message);
+ }
+
}
catch (Exception ex)
{