Skip to content

Commit 67df6f9

Browse files
committed
fix: animations when entering fullscreen
1 parent 7b283a2 commit 67df6f9

3 files changed

Lines changed: 162 additions & 63 deletions

File tree

FlashpointSecurePlayer/ProgressManager.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ private static IntPtr State {
300300
return;
301301
}
302302

303+
if (!ProgressBar.IsHandleCreated || ProgressBar.Handle == IntPtr.Zero) {
304+
return;
305+
}
306+
303307
SendMessage(ProgressBar.Handle, PBM_SETSTATE, ProgressManager.state, IntPtr.Zero);
304308
}
305309
}

FlashpointSecurePlayer/Shared.cs

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,20 @@ public enum GW : uint {
248248
[DllImport("USER32.DLL", SetLastError = true)]
249249
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
250250

251+
[StructLayout(LayoutKind.Sequential)]
252+
public struct POINT {
253+
public int x;
254+
public int y;
255+
}
256+
257+
[StructLayout(LayoutKind.Sequential)]
258+
public struct RECT {
259+
public int left;
260+
public int right;
261+
public int top;
262+
public int bottom;
263+
}
264+
251265
public enum HookType : int {
252266
WH_MSGFILTER = -1,
253267
WH_JOURNALRECORD = 0,
@@ -292,12 +306,6 @@ public enum KBDLLHOOKSTRUCTFlags : uint {
292306
[DllImport("USER32.DLL")]
293307
public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, KBDLLHOOKSTRUCT lParam);
294308

295-
[StructLayout(LayoutKind.Sequential)]
296-
public struct POINT {
297-
public int X;
298-
public int Y;
299-
}
300-
301309
[StructLayout(LayoutKind.Sequential)]
302310
public struct MSLLHOOKSTRUCT {
303311
public POINT pt;
@@ -317,6 +325,42 @@ public struct MSLLHOOKSTRUCT {
317325
[return: MarshalAs(UnmanagedType.Bool)]
318326
public static extern bool UnhookWindowsHookEx(IntPtr hhk);
319327

328+
public enum SW : uint {
329+
SW_HIDE = 0,
330+
SW_SHOWNORMAL = 1,
331+
SW_NORMAL = 1,
332+
SW_SHOWMINIMIZED = 2,
333+
SW_SHOWMAXIMIZED = 3,
334+
SW_MAXIMIZE = 3,
335+
SW_SHOWNOACTIVATE = 4,
336+
SW_SHOW = 5,
337+
SW_MINIMIZE = 6,
338+
SW_SHOWMINNOACTIVE = 7,
339+
SW_SHOWNA = 8,
340+
SW_RESTORE = 9,
341+
SW_SHOWDEFAULT = 10,
342+
SW_FORCEMINIMIZE = 11,
343+
SW_MAX = 11
344+
}
345+
346+
[StructLayout(LayoutKind.Sequential)]
347+
public struct WINDOWPLACEMENT {
348+
public int length;
349+
public int flags;
350+
public SW showCmd;
351+
public POINT ptMinPosition;
352+
public POINT ptMaxPosition;
353+
public RECT rcNormalPosition;
354+
}
355+
356+
[DllImport("USER32.DLL", SetLastError = true)]
357+
[return: MarshalAs(UnmanagedType.Bool)]
358+
public static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
359+
360+
[DllImport("USER32.DLL", SetLastError = true)]
361+
[return: MarshalAs(UnmanagedType.Bool)]
362+
public static extern bool SetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
363+
320364
[StructLayout(LayoutKind.Sequential)]
321365
public struct SECURITY_ATTRIBUTES {
322366
public uint nLength;

FlashpointSecurePlayer/WebBrowserMode.cs

Lines changed: 108 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,34 @@ private IntPtr LowLevelMouseProc(int nCode, IntPtr wParam, IntPtr lParam) {
5656
return CallNextHookEx(mouseHook, nCode, wParam, lParam);
5757
}
5858

59+
public WINDOWPLACEMENT WindowPlacement {
60+
get {
61+
if (!IsHandleCreated || Handle == IntPtr.Zero) {
62+
throw new NullReferenceException("Handle must not be NULL.");
63+
}
64+
65+
WINDOWPLACEMENT value = new WINDOWPLACEMENT();
66+
value.length = Marshal.SizeOf(value);
67+
68+
if (!GetWindowPlacement(Handle, ref value)) {
69+
Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
70+
}
71+
return value;
72+
}
73+
74+
set {
75+
if (!IsHandleCreated || Handle == IntPtr.Zero) {
76+
throw new NullReferenceException("Handle must not be NULL.");
77+
}
78+
79+
value.length = Marshal.SizeOf(value);
80+
81+
if (!SetWindowPlacement(Handle, ref value)) {
82+
Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
83+
}
84+
}
85+
}
86+
5987
private const int FULLSCREEN_EXIT_LABEL_TIMER_TIME = 2500;
6088

6189
private System.Windows.Forms.Timer exitFullscreenLabelTimer = null;
@@ -86,12 +114,9 @@ private bool ExitFullscreenLabelTimer {
86114

87115
private bool fullscreen = false;
88116
private FormBorderStyle fullscreenFormBorderStyle = FormBorderStyle.Sizable;
89-
private FormWindowState fullscreenWindowState = FormWindowState.Maximized;
90-
private Point fullscreenLocation;
91-
private Size fullscreenSize;
117+
private WINDOWPLACEMENT fullscreenWindowPlacement;
92118

93-
private Point closableWebBrowserLocation;
94-
private Size closableWebBrowserSize;
119+
private Rectangle closableWebBrowserBounds;
95120

96121
// be very careful modifying this property
97122
// it is very picky about the order things happen
@@ -102,6 +127,10 @@ public bool Fullscreen {
102127
}
103128

104129
set {
130+
if (!IsHandleCreated || Handle == IntPtr.Zero) {
131+
return;
132+
}
133+
105134
if (closableWebBrowser == null) {
106135
return;
107136
}
@@ -115,19 +144,22 @@ public bool Fullscreen {
115144
if (fullscreen) {
116145
// get the original properties before modifying them
117146
fullscreenFormBorderStyle = FormBorderStyle;
118-
fullscreenWindowState = WindowState;
119-
fullscreenLocation = Location;
120-
fullscreenSize = Size;
147+
fullscreenWindowPlacement = WindowPlacement;
148+
149+
closableWebBrowserBounds = closableWebBrowser.Bounds;
121150

122-
closableWebBrowserLocation = closableWebBrowser.Location;
123-
closableWebBrowserSize = closableWebBrowser.Size;
151+
WINDOWPLACEMENT windowPlacement = fullscreenWindowPlacement;
124152

125153
// need to do this first to have an effect if starting maximized
126-
WindowState = FormWindowState.Normal;
154+
windowPlacement.showCmd = SW.SW_NORMAL;
155+
WindowPlacement = windowPlacement;
156+
127157
// disable resizing
128158
FormBorderStyle = FormBorderStyle.None;
159+
129160
// enter fullscreen
130-
WindowState = FormWindowState.Maximized;
161+
windowPlacement.showCmd = SW.SW_MAXIMIZE;
162+
WindowPlacement = windowPlacement;
131163

132164
// make strips invisible so the Closable Web Browser can be Docked
133165
// (this must happen AFTER entering fullscreen to prevent toolbar mouseover bug)
@@ -157,11 +189,15 @@ public bool Fullscreen {
157189
}
158190
}
159191

192+
WINDOWPLACEMENT windowPlacement = fullscreenWindowPlacement;
193+
160194
// need to do this first to reset the window to its former size
161195
FormBorderStyle = FormBorderStyle.Sizable;
196+
162197
// exit fullscreen
163-
WindowState = FormWindowState.Normal;
164-
198+
windowPlacement.showCmd = SW.SW_NORMAL;
199+
WindowPlacement = windowPlacement;
200+
165201
// make strips visible so the Closable Web Browser can be Anchored
166202
fullscreenButton.Checked = false;
167203
toolBarToolStrip.Visible = true;
@@ -170,12 +206,9 @@ public bool Fullscreen {
170206

171207
// reset to the original properties before modifying them
172208
FormBorderStyle = fullscreenFormBorderStyle;
173-
WindowState = fullscreenWindowState;
174-
Location = fullscreenLocation;
175-
Size = fullscreenSize;
209+
WindowPlacement = fullscreenWindowPlacement;
176210

177-
closableWebBrowser.Location = closableWebBrowserLocation;
178-
closableWebBrowser.Size = closableWebBrowserSize;
211+
closableWebBrowser.Bounds = closableWebBrowserBounds;
179212

180213
// commit by bringing the window to the front
181214
BringToFront();
@@ -545,56 +578,74 @@ private void WebBrowserMode_FormClosing(object sender, FormClosingEventArgs e) {
545578
private void WebBrowserMode_Activated(object sender, EventArgs e) {
546579
Application.AddMessageFilter(messageFilter);
547580

548-
if (Fullscreen) {
549-
if (WindowState == FormWindowState.Minimized) {
550-
BringToFront();
551-
}
581+
if (!IsHandleCreated || Handle == IntPtr.Zero) {
582+
return;
583+
}
584+
585+
if (!Fullscreen) {
586+
return;
587+
}
588+
589+
SW showCmd = WindowPlacement.showCmd;
590+
591+
if (showCmd == SW.SW_SHOWMINIMIZED
592+
|| showCmd == SW.SW_MINIMIZE
593+
|| showCmd == SW.SW_SHOWMINNOACTIVE) {
594+
BringToFront();
552595
}
553596
}
554597

555598
private void WebBrowserMode_Deactivate(object sender, EventArgs e) {
556599
Application.RemoveMessageFilter(messageFilter);
557600

558-
if (Fullscreen) {
559-
IntPtr foregroundWindow = GetForegroundWindow();
560-
561-
// we are the active window, because we are only now deactivating
562-
// if this process has the foreground window, it'll be the active window
563-
if (Handle == foregroundWindow) {
564-
// this process opened a new window
565-
if (!CanFocus) {
566-
// if there is a window above us in the z-order
567-
IntPtr previousWindow = GetWindow(Handle, GW.GW_HWNDPREV);
568-
569-
if (previousWindow != IntPtr.Zero) {
570-
// if we own the window above us in the z-order
571-
if (Handle == GetWindow(previousWindow, GW.GW_OWNER)) {
572-
// the new window is a dialog that prevents focus to this window
573-
return;
574-
}
575-
}
576-
}
601+
if (!IsHandleCreated || Handle == IntPtr.Zero) {
602+
return;
603+
}
577604

578-
// the new window is not a dialog that prevents focus to this window
579-
Fullscreen = false;
580-
return;
581-
}
605+
if (!Fullscreen) {
606+
return;
607+
}
582608

583-
// another process opened a window
584-
if (foregroundWindow != IntPtr.Zero) {
585-
// if we own the foreground window
586-
if (Handle == GetWindow(foregroundWindow, GW.GW_OWNER)) {
587-
// the new window is owned by this window
588-
if (CanFocus) {
589-
// the new window is not a dialog that prevents focus to this window
590-
Fullscreen = false;
609+
IntPtr foregroundWindow = GetForegroundWindow();
610+
611+
// we are the active window, because we are only now deactivating
612+
// if this process has the foreground window, it'll be the active window
613+
if (Handle == foregroundWindow) {
614+
// this process opened a new window
615+
if (!CanFocus) {
616+
// if there is a window above us in the z-order
617+
IntPtr previousWindow = GetWindow(Handle, GW.GW_HWNDPREV);
618+
619+
if (previousWindow != IntPtr.Zero) {
620+
// if we own the window above us in the z-order
621+
if (Handle == GetWindow(previousWindow, GW.GW_OWNER)) {
622+
// the new window is a dialog that prevents focus to this window
623+
return;
591624
}
592-
return;
593625
}
594626
}
595627

596-
WindowState = FormWindowState.Minimized;
628+
// the new window is not a dialog that prevents focus to this window
629+
Fullscreen = false;
630+
return;
631+
}
632+
633+
// another process opened a window
634+
if (foregroundWindow != IntPtr.Zero) {
635+
// if we own the foreground window
636+
if (Handle == GetWindow(foregroundWindow, GW.GW_OWNER)) {
637+
// the new window is owned by this window
638+
if (CanFocus) {
639+
// the new window is not a dialog that prevents focus to this window
640+
Fullscreen = false;
641+
}
642+
return;
643+
}
597644
}
645+
646+
WINDOWPLACEMENT windowPlacement = WindowPlacement;
647+
windowPlacement.showCmd = SW.SW_MINIMIZE;
648+
WindowPlacement = windowPlacement;
598649
}
599650

600651
private void closableWebBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e) {
@@ -685,7 +736,7 @@ private void closableWebBrowser_WebBrowserPaint(object sender, EventArgs e) {
685736
// lame fix: browser hangs when window.open top attribute > control height (why?)
686737
// Width, Height, and WindowState changes all work here
687738
// Width/Height are less obvious and Height doesn't cause text reflow
688-
if (WindowState != FormWindowState.Maximized) {
739+
if (WindowPlacement.showCmd != SW.SW_SHOWMAXIMIZED) {
689740
// add first in case it's zero
690741
Height++;
691742
Height--;

0 commit comments

Comments
 (0)