This commit is contained in:
Lorenz Cuno Klopfenstein 2018-08-23 12:50:42 +02:00
parent 27b1b4d5da
commit 1ac70ff5ec
11 changed files with 92 additions and 93 deletions

View file

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Drawing; using System.Drawing;
@ -16,7 +16,7 @@ namespace OnTopReplica {
partial class MainForm : AspectRatioForm { partial class MainForm : AspectRatioForm {
//GUI elements //GUI elements
ThumbnailPanel _thumbnailPanel; private ThumbnailPanel _thumbnailPanel;
//Managers //Managers
readonly MessagePumpManager _msgPumpManager = new MessagePumpManager(); readonly MessagePumpManager _msgPumpManager = new MessagePumpManager();
@ -30,13 +30,13 @@ namespace OnTopReplica {
FullscreenManager = new FullscreenFormManager(this); FullscreenManager = new FullscreenFormManager(this);
_quickRegionDrawingHandler = new ThumbnailPanel.RegionDrawnHandler(HandleQuickRegionDrawn); _quickRegionDrawingHandler = new ThumbnailPanel.RegionDrawnHandler(HandleQuickRegionDrawn);
//WinForms init pass //WinForms init pass
InitializeComponent(); InitializeComponent();
//Store default values //Store default values
DefaultNonClickTransparencyKey = this.TransparencyKey; DefaultNonClickTransparencyKey = TransparencyKey;
DefaultBorderStyle = this.FormBorderStyle; DefaultBorderStyle = FormBorderStyle;
//Thumbnail panel //Thumbnail panel
_thumbnailPanel = new ThumbnailPanel { _thumbnailPanel = new ThumbnailPanel {
@ -52,7 +52,7 @@ namespace OnTopReplica {
); );
//Set to Key event preview //Set to Key event preview
this.KeyPreview = true; KeyPreview = true;
Log.Write("Main form constructed"); Log.Write("Main form constructed");
} }
@ -456,6 +456,6 @@ namespace OnTopReplica {
} }
#endregion #endregion
} }
} }

View file

@ -7,6 +7,7 @@ using WindowsFormsAero.TaskDialog;
using OnTopReplica.SidePanels; using OnTopReplica.SidePanels;
namespace OnTopReplica { namespace OnTopReplica {
partial class MainForm { partial class MainForm {
private void Menu_opening(object sender, CancelEventArgs e) { private void Menu_opening(object sender, CancelEventArgs e) {
@ -58,11 +59,11 @@ namespace OnTopReplica {
private void Menu_Opacity_opening(object sender, CancelEventArgs e) { private void Menu_Opacity_opening(object sender, CancelEventArgs e) {
ToolStripMenuItem[] items = { ToolStripMenuItem[] items = {
toolStripMenuItem1, toolStripMenuItem1,
toolStripMenuItem2, toolStripMenuItem2,
toolStripMenuItem3, toolStripMenuItem3,
toolStripMenuItem4 toolStripMenuItem4
}; };
foreach (ToolStripMenuItem i in items) { foreach (ToolStripMenuItem i in items) {
if (((double)i.Tag) == this.Opacity) if (((double)i.Tag) == this.Opacity)

View file

@ -78,12 +78,15 @@ namespace OnTopReplica.Native {
[Flags] [Flags]
public enum WindowExStyles : long { public enum WindowExStyles : long {
AppWindow = 0x40000, AcceptFiles = 0x00000010L,
AppWindow = 0x00040000L,
Layered = 0x80000, Layered = 0x80000,
NoActivate = 0x8000000L, NoActivate = 0x8000000L,
NoRedirectionBitmap = 0x00200000L,
ToolWindow = 0x80, ToolWindow = 0x80,
TopMost = 8, TopMost = 8,
Transparent = 0x20 Transparent = 0x20,
WindowEdge = 0x00000100L
} }
public static IntPtr GetWindowLong(IntPtr hWnd, WindowLong i) { public static IntPtr GetWindowLong(IntPtr hWnd, WindowLong i) {

View file

@ -3,14 +3,14 @@ using System.Collections.Generic;
using System.Text; using System.Text;
namespace OnTopReplica.Platforms { namespace OnTopReplica.Platforms {
#if DEBUG #if DEBUG
/// <summary> /// <summary>
/// Fake platform for debugging. /// Fake platform for debugging.
/// </summary> /// </summary>
class DebugPlatform : PlatformSupport { class DebugPlatform : PlatformSupport {
public override bool CheckCompatibility() { public override bool CheckCompatibility() {
return true; return true;
} }

View file

@ -4,8 +4,9 @@ using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
namespace OnTopReplica.Platforms { namespace OnTopReplica.Platforms {
class Other : PlatformSupport { class Other : PlatformSupport {
public override bool CheckCompatibility() { public override bool CheckCompatibility() {
MessageBox.Show(Strings.ErrorNoDwm, Strings.ErrorNoDwmTitle, MessageBox.Show(Strings.ErrorNoDwm, Strings.ErrorNoDwmTitle,
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);
@ -13,4 +14,5 @@ namespace OnTopReplica.Platforms {
} }
} }
} }

View file

@ -1,12 +1,9 @@
using System; namespace OnTopReplica.Platforms {
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OnTopReplica.Native;
namespace OnTopReplica.Platforms {
class WindowsEight : WindowsSeven { class WindowsEight : WindowsSeven {
// Equivalent to Windows 7 :)
} }
} }

View file

@ -1,6 +1,4 @@
using System; using OnTopReplica.Native;
using System.Windows.Forms;
using OnTopReplica.Native;
using WindowsFormsAero.Dwm; using WindowsFormsAero.Dwm;
namespace OnTopReplica.Platforms { namespace OnTopReplica.Platforms {
@ -10,8 +8,7 @@ namespace OnTopReplica.Platforms {
private double? PreviousOpacity { get; set; } private double? PreviousOpacity { get; set; }
public override void PreHandleFormInit() { public override void PreHandleFormInit() {
//Set Application ID WindowsSevenMethods.SetCurrentProcessExplicitAppUserModelID(Program.ApplicationId);
WindowsSevenMethods.SetCurrentProcessExplicitAppUserModelID("LorenzCunoKlopfenstein.OnTopReplica.MainForm");
} }
public override void PostHandleFormInit(MainForm form) { public override void PostHandleFormInit(MainForm form) {
@ -34,7 +31,7 @@ namespace OnTopReplica.Platforms {
form.Opacity = PreviousOpacity.GetValueOrDefault(1.0); form.Opacity = PreviousOpacity.GetValueOrDefault(1.0);
PreviousOpacity = null; PreviousOpacity = null;
} }
form.Show(); form.Show();
} }

View file

@ -1,11 +1,10 @@
using System; using System.Windows.Forms;
using System.Windows.Forms;
using WindowsFormsAero.Dwm; using WindowsFormsAero.Dwm;
namespace OnTopReplica.Platforms { namespace OnTopReplica.Platforms {
class WindowsVista : PlatformSupport { class WindowsVista : PlatformSupport {
public override bool CheckCompatibility() { public override bool CheckCompatibility() {
if (!WindowsFormsAero.OsSupport.IsCompositionEnabled) { if (!WindowsFormsAero.OsSupport.IsCompositionEnabled) {
MessageBox.Show(Strings.ErrorDwmOffContent, Strings.ErrorDwmOff, MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(Strings.ErrorDwmOffContent, Strings.ErrorDwmOff, MessageBoxButtons.OK, MessageBoxIcon.Error);
@ -24,7 +23,7 @@ namespace OnTopReplica.Platforms {
form.ShowInTaskbar = false; form.ShowInTaskbar = false;
DwmManager.SetWindowFlip3dPolicy(form, WindowsFormsAero.Flip3DPolicy.ExcludeAbove); DwmManager.SetWindowFlip3dPolicy(form, WindowsFormsAero.Flip3DPolicy.ExcludeAbove);
_icon = new NotificationIcon(form); _icon = new NotificationIcon(form);
} }

View file

@ -1,15 +1,14 @@
using System; using System.Windows.Forms;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace OnTopReplica.Platforms { namespace OnTopReplica.Platforms {
class WindowsXp : PlatformSupport { class WindowsXp : PlatformSupport {
public override bool CheckCompatibility() { public override bool CheckCompatibility() {
MessageBox.Show(Strings.ErrorNoDwm, Strings.ErrorNoDwmTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(Strings.ErrorNoDwm, Strings.ErrorNoDwmTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
return false; return false;
} }
} }
} }

View file

@ -3,14 +3,17 @@ using System.IO;
using System.Reflection; using System.Reflection;
using System.Threading; using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using OnTopReplica.Platforms;
using OnTopReplica.Properties; using OnTopReplica.Properties;
using OnTopReplica.StartupOptions; using OnTopReplica.StartupOptions;
using OnTopReplica.Update; using OnTopReplica.Update;
namespace OnTopReplica { namespace OnTopReplica {
static class Program { static class Program {
public const string ApplicationId = "LorenzCunoKlopfenstein.OnTopReplica.MainForm";
public static PlatformSupport Platform { get; private set; } public static PlatformSupport Platform { get; private set; }
public static UpdateManager Update { get; private set; } public static UpdateManager Update { get; private set; }
@ -60,7 +63,7 @@ namespace OnTopReplica {
} }
if (options.Status == CliStatus.Information || options.Status == CliStatus.Error) if (options.Status == CliStatus.Information || options.Status == CliStatus.Error)
return; return;
//Load language //Load language
Thread.CurrentThread.CurrentUICulture = Settings.Default.Language; Thread.CurrentThread.CurrentUICulture = Settings.Default.Language;

View file

@ -1,79 +1,77 @@
using System; using System;
using System.Collections.Generic;
using System.Text; using System.Text;
using System.Drawing; using System.Drawing;
using OnTopReplica.Native; using OnTopReplica.Native;
namespace OnTopReplica { namespace OnTopReplica {
/// <summary> /// <summary>
/// Helper class that keeps a window handle (HWND), /// Helper class that keeps a window handle (HWND),
/// the title of the window and can load its icon. /// the title of the window and can load its icon.
/// </summary> /// </summary>
public class WindowHandle : System.Windows.Forms.IWin32Window { public class WindowHandle : System.Windows.Forms.IWin32Window {
IntPtr _handle; IntPtr _handle;
string _title; string _title;
/// <summary> /// <summary>
/// Creates a new WindowHandle instance. The handle pointer must be valid, the title /// Creates a new WindowHandle instance. The handle pointer must be valid, the title
/// may be null or empty and will be updated as requested. /// may be null or empty and will be updated as requested.
/// </summary> /// </summary>
public WindowHandle(IntPtr p, string title) { public WindowHandle(IntPtr p, string title) {
_handle = p; _handle = p;
_title = title; _title = title;
} }
/// <summary> /// <summary>
/// Creates a new WindowHandle instance. Additional features of the handle will be queried as needed. /// Creates a new WindowHandle instance. Additional features of the handle will be queried as needed.
/// </summary> /// </summary>
/// <param name="p"></param>
public WindowHandle(IntPtr p) { public WindowHandle(IntPtr p) {
_handle = p; _handle = p;
_title = null; _title = null;
} }
public string Title { public string Title {
get { get {
if (_title == null) { if (_title == null) {
_title = WindowMethods.GetWindowText(_handle) ?? string.Empty; _title = WindowMethods.GetWindowText(_handle) ?? string.Empty;
} }
return _title; return _title;
} }
} }
Icon _icon = null; Icon _icon = null;
bool _iconFetched = false; bool _iconFetched = false;
public Icon Icon { public Icon Icon {
get { get {
if (!_iconFetched) { if (!_iconFetched) {
//Fetch icon from window //Fetch icon from window
IntPtr hIcon; IntPtr hIcon;
if (MessagingMethods.SendMessageTimeout(_handle, WM.GETICON, new IntPtr(2), new IntPtr(0), if (MessagingMethods.SendMessageTimeout(_handle, WM.GETICON, new IntPtr(2), new IntPtr(0),
MessagingMethods.SendMessageTimeoutFlags.AbortIfHung | MessagingMethods.SendMessageTimeoutFlags.Block, 500, out hIcon) == IntPtr.Zero) { MessagingMethods.SendMessageTimeoutFlags.AbortIfHung | MessagingMethods.SendMessageTimeoutFlags.Block, 500, out hIcon) == IntPtr.Zero) {
hIcon = IntPtr.Zero; hIcon = IntPtr.Zero;
} }
if (hIcon != IntPtr.Zero) { if (hIcon != IntPtr.Zero) {
_icon = Icon.FromHandle(hIcon); _icon = Icon.FromHandle(hIcon);
} }
else { else {
//Fetch icon from window class //Fetch icon from window class
hIcon = (IntPtr)WindowMethods.GetClassLong(_handle, WindowMethods.ClassLong.IconSmall); hIcon = (IntPtr)WindowMethods.GetClassLong(_handle, WindowMethods.ClassLong.IconSmall);
if (hIcon.ToInt64() != 0) { if (hIcon.ToInt64() != 0) {
_icon = Icon.FromHandle(hIcon); _icon = Icon.FromHandle(hIcon);
} }
} }
} }
_iconFetched = true; _iconFetched = true;
return _icon; return _icon;
} }
} }
string _class = null; string _class = null;
@ -113,32 +111,32 @@ namespace OnTopReplica {
} }
return sb.ToString(); return sb.ToString();
} }
public override bool Equals(object obj) { public override bool Equals(object obj) {
if (ReferenceEquals(obj, this)) if (ReferenceEquals(obj, this))
return true; return true;
System.Windows.Forms.IWin32Window win = obj as System.Windows.Forms.IWin32Window; System.Windows.Forms.IWin32Window win = obj as System.Windows.Forms.IWin32Window;
if (win == null) if (win == null)
return false; return false;
return (_handle.Equals(win.Handle)); return (_handle.Equals(win.Handle));
} }
public override int GetHashCode() { public override int GetHashCode() {
return _handle.GetHashCode(); return _handle.GetHashCode();
} }
#endregion #endregion
#region IWin32Window Members #region IWin32Window Members
public IntPtr Handle { public IntPtr Handle {
get { return _handle; } get { return _handle; }
} }
#endregion #endregion
/// <summary> /// <summary>
/// Creates a new windowHandle instance from a given IntPtr handle. /// Creates a new windowHandle instance from a given IntPtr handle.
@ -148,5 +146,5 @@ namespace OnTopReplica {
return new WindowHandle(handle, null); return new WindowHandle(handle, null);
} }
} }
} }