From 25c9704ef1ec8fc0cad49a969e2ac0fe944f95a7 Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Mon, 20 Nov 2023 10:43:33 +0000 Subject: [PATCH] Allow splash screen to move. Signed-off-by: Konstantina Chremmou --- XenAdmin/SplashScreen.Designer.cs | 2 ++ XenAdmin/SplashScreen.cs | 20 ++++++++++++++++++++ XenCenterLib/Win32.cs | 12 ++++++++++-- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/XenAdmin/SplashScreen.Designer.cs b/XenAdmin/SplashScreen.Designer.cs index c264a8b3a..88e1bf5d8 100644 --- a/XenAdmin/SplashScreen.Designer.cs +++ b/XenAdmin/SplashScreen.Designer.cs @@ -41,6 +41,7 @@ private void InitializeComponent() resources.ApplyResources(this.pictureBox1, "pictureBox1"); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.TabStop = false; + this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown); // // timer1 // @@ -52,6 +53,7 @@ private void InitializeComponent() this.labelCopyright.BackColor = System.Drawing.Color.Transparent; resources.ApplyResources(this.labelCopyright, "labelCopyright"); this.labelCopyright.Name = "labelCopyright"; + this.labelCopyright.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelCopyright_MouseDown); // // SplashScreen // diff --git a/XenAdmin/SplashScreen.cs b/XenAdmin/SplashScreen.cs index 00d2376d1..fc22f663e 100644 --- a/XenAdmin/SplashScreen.cs +++ b/XenAdmin/SplashScreen.cs @@ -32,6 +32,7 @@ using System.Drawing; using System.Windows.Forms; using XenAdmin.Core; +using XenCenterLib; namespace XenAdmin { @@ -67,5 +68,24 @@ private void timer1_Tick(object sender, EventArgs e) timer1.Stop(); ShowMainWindowRequested?.Invoke(); } + + private void pictureBox1_MouseDown(object sender, MouseEventArgs e) + { + SendToForm(e.Button); + } + + private void labelCopyright_MouseDown(object sender, MouseEventArgs e) + { + SendToForm(e.Button); + } + + private void SendToForm(MouseButtons mouseButton) + { + if (mouseButton == MouseButtons.Left) + { + Win32.ReleaseCapture(); + Win32.SendMessage(Handle, Win32.WM_NCLBUTTONDOWN, Win32.HT_CAPTION, 0); + } + } } } diff --git a/XenCenterLib/Win32.cs b/XenCenterLib/Win32.cs index 759763c8e..c39507e58 100644 --- a/XenCenterLib/Win32.cs +++ b/XenCenterLib/Win32.cs @@ -101,6 +101,8 @@ public static extern int ToUnicode(uint wVirtKey, uint wScanCode, IntPtr lpKeySt public const int WM_KEYDOWN = 0x100; // Mouse Hooks + public const int WM_NCLBUTTONDOWN = 0xA1; + public const int HT_CAPTION = 0x2; public const int WM_LBUTTONDOWN = 0x201; public const int WM_LBUTTONDBLCLK = 0x203; public const int WM_MOUSEWHEEL = 0x20A; @@ -186,11 +188,17 @@ public struct POINT [DllImport("user32.dll")] public static extern bool DestroyWindow(IntPtr hwnd); + [DllImport("user32.dll")] + public static extern bool ReleaseCapture(); + + [DllImport("user32.dll")] + public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam); + [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] - public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam); + public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] - public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam); + public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, string lParam); [DllImport("user32.dll")] public static extern IntPtr SetFocus(IntPtr hwnd);