Skip to content

Commit

Permalink
#11 Double Draw: Trying to provide a clean way to force a resolution …
Browse files Browse the repository at this point in the history
…change.
  • Loading branch information
FrigoCoder committed Jan 6, 2018
1 parent 39363cc commit ba9df5a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
17 changes: 8 additions & 9 deletions FrigoTab/SessionForm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;

Expand Down Expand Up @@ -60,9 +62,6 @@ protected override void WndProc (ref Message m) {
case WindowMessages.MouseClicked:
MouseClicked(new Point((int) m.WParam, (int) m.LParam));
break;
case WindowMessages.DisplayChange:
DisplayChange();
break;
}
base.WndProc(ref m);
}
Expand All @@ -77,7 +76,9 @@ private void BeginSession () {
return;
}

ForceResolutionChange();
WindowHandle.GetForegroundWindow().PostMessage(WindowMessages.ActivateApp, 0, Thread.CurrentThread.ManagedThreadId);
ChangeDisplaySettings(IntPtr.Zero, 0);
Bounds = GetScreenBounds();

backgrounds = new BackgroundWindows(this, finder);
screenForms = new ScreenForms(this);
Expand Down Expand Up @@ -149,15 +150,13 @@ private void DisplayChange () {
}
}

private static void ForceResolutionChange () {
WindowHandle foreground = WindowHandle.GetForegroundWindowHandle();
foreground.PostMessage(WindowMessages.ActivateApp, 0, Thread.CurrentThread.ManagedThreadId);
}

private static Rectangle GetScreenBounds () {
return Screen.AllScreens.Select(screen => screen.Bounds).Aggregate(Rectangle.Union);
}

[DllImport("user32.dll")]
private static extern int ChangeDisplaySettings (IntPtr lpDevMode, int dwFlags);

}

}
7 changes: 3 additions & 4 deletions FrigoTab/WindowHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ public enum WindowExStyles : long {
public struct WindowHandle {

public static readonly WindowHandle Null = new WindowHandle(IntPtr.Zero);
public static WindowHandle GetForegroundWindowHandle () => GetForegroundWindow();
public static bool operator == (WindowHandle h1, WindowHandle h2) => h1.handle == h2.handle;
public static bool operator != (WindowHandle h1, WindowHandle h2) => h1.handle != h2.handle;

[DllImport("user32.dll")]
public static extern WindowHandle GetForegroundWindow ();

private readonly IntPtr handle;

public WindowHandle (IntPtr handle) {
Expand Down Expand Up @@ -150,9 +152,6 @@ private static extern bool SendMessageCallback (WindowHandle hWnd, WindowMessage
[DllImport("user32.dll")]
private static extern bool PostMessage (WindowHandle hWnd, WindowMessages msg, IntPtr wParam, IntPtr lParam);

[DllImport("user32.dll")]
private static extern WindowHandle GetForegroundWindow ();

[DllImport("user32.dll")]
private static extern bool GetWindowRect (WindowHandle hWnd, out Rect lpRect);

Expand Down

0 comments on commit ba9df5a

Please sign in to comment.