cleanup code

This commit is contained in:
Holger Börchers 2018-05-18 20:00:56 +02:00
parent e68f256d80
commit 6d086205d4
2 changed files with 25 additions and 18 deletions

View File

@ -1,30 +1,41 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// ReSharper disable InconsistentNaming
namespace Katteker.Gui namespace Katteker.Gui
{ {
/// <summary> /// <summary>
/// Native methods. /// Native methods.
/// </summary> /// </summary>
public static class NativeMethods public static class NativeMethods
{ {
/// <summary> /// <summary>
/// Release the capture /// Hit Test Caption
/// </summary>
public const int HTCAPTION = 0x2;
/// <summary>
/// Posted when the user presses the left mouse button while the cursor is within the nonclient area of a window.
/// </summary>
public const int WM_NCLBUTTONDOWN = 0xA1;
/// <summary>
/// Release the capture
/// </summary> /// </summary>
[DllImport("User32.dll")] [DllImport("User32.dll")]
public static extern bool ReleaseCapture(); public static extern bool ReleaseCapture();
/// <summary> /// <summary>
/// Send message /// Send message
/// </summary> /// </summary>
[DllImport("User32.dll")] [DllImport("User32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
/// <summary> /// <summary>
/// Set Process API aware /// Set Process API aware
/// </summary> /// </summary>
[DllImport("user32.dll")] [DllImport("user32.dll")]
public static extern bool SetProcessDPIAware(); public static extern bool SetProcessDPIAware();
} }
} }

View File

@ -8,13 +8,11 @@ namespace Katteker.Gui
{ {
public sealed partial class UpdateWindow : Form public sealed partial class UpdateWindow : Form
{ {
private readonly UpdateManager _updateManager;
private readonly ReleaseEntry _entry; private readonly ReleaseEntry _entry;
private const int HTCAPTION = 0x2; private readonly UpdateManager _updateManager;
private const int WM_NCLBUTTONDOWN = 0xA1;
/// <summary> /// <summary>
/// The Update Window /// The Update Window
/// </summary> /// </summary>
public UpdateWindow(UpdateManager updateManager, ReleaseEntry entry) public UpdateWindow(UpdateManager updateManager, ReleaseEntry entry)
{ {
@ -33,15 +31,12 @@ namespace Katteker.Gui
/// <inheritdoc /> /// <inheritdoc />
/// <summary> /// <summary>
/// Clean up any resources being used. /// Clean up any resources being used.
/// </summary> /// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing) if (disposing) components?.Dispose();
{
components?.Dispose();
}
base.Dispose(disposing); base.Dispose(disposing);
} }
@ -67,9 +62,10 @@ namespace Katteker.Gui
MaximizeBtn_Click(sender, e); MaximizeBtn_Click(sender, e);
return; return;
} }
if (e.Button != MouseButtons.Left) return; if (e.Button != MouseButtons.Left) return;
NativeMethods.ReleaseCapture(); NativeMethods.ReleaseCapture();
NativeMethods.SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0); NativeMethods.SendMessage(Handle, NativeMethods.WM_NCLBUTTONDOWN, NativeMethods.HTCAPTION, 0);
} }
@ -128,9 +124,9 @@ namespace Katteker.Gui
} }
catch (Exception ex) catch (Exception ex)
{ {
MessageBox.Show(Resources.CouldNotUpdateYourApplication + Environment.NewLine + ex.Message, Gui.Properties.Resources.Updater, MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(Resources.CouldNotUpdateYourApplication + Environment.NewLine + ex.Message,
Resources.Updater, MessageBoxButtons.OK, MessageBoxIcon.Error);
WriteTitle(Resources.Updater); WriteTitle(Resources.Updater);
} }
finally finally
{ {