From 5f2a2074742123ffa882d09bec1826ab64ba764c Mon Sep 17 00:00:00 2001 From: Jaehyuk-Lee Date: Sun, 6 Jun 2021 05:58:56 +0900 Subject: [PATCH] enable click-through --- Overlay/DutyOvForm.cs | 6 ------ Tab/DutyForm.cs | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/Overlay/DutyOvForm.cs b/Overlay/DutyOvForm.cs index 6b5fcb2..7b80e1e 100644 --- a/Overlay/DutyOvForm.cs +++ b/Overlay/DutyOvForm.cs @@ -61,9 +61,6 @@ namespace DutyContent.Overlay private void DoMoveDown(MouseEventArgs e) { - if (DcConfig.Duty.OverlayClickThru) - return; - if (e.Button == MouseButtons.Left) { ThirdParty.NativeMethods.ReleaseCapture(); @@ -73,9 +70,6 @@ namespace DutyContent.Overlay protected override void OnMouseDown(MouseEventArgs e) { - if (DcConfig.Duty.OverlayClickThru) - return; - base.OnMouseDown(e); DoMoveDown(e); } diff --git a/Tab/DutyForm.cs b/Tab/DutyForm.cs index d0d9f51..8ab7a45 100644 --- a/Tab/DutyForm.cs +++ b/Tab/DutyForm.cs @@ -9,6 +9,7 @@ using System.Net; using System.Net.Http; using System.Text; using System.IO; +using System.Runtime.InteropServices; namespace DutyContent.Tab { @@ -34,6 +35,12 @@ namespace DutyContent.Tab _overlay = new Overlay.DutyOvForm(); } + // Used for click-through function + [DllImport("user32.dll", SetLastError = true)] + static extern int GetWindowLong(IntPtr hWnd, int nIndex); + [DllImport("user32.dll")] + static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); + private void DutyTabForm_FormClosing(object sender, FormClosingEventArgs e) { @@ -75,6 +82,8 @@ namespace DutyContent.Tab _overlay.Show(); else _overlay.Hide(); + if (DcConfig.Duty.OverlayClickThru) + enableOverlayClickThru(); // chkEnableSound.Checked = DcConfig.Duty.EnableSound; @@ -669,6 +678,10 @@ namespace DutyContent.Tab return; DcConfig.Duty.OverlayClickThru = chkOverlayClickThru.Checked; + if (DcConfig.Duty.OverlayClickThru) + enableOverlayClickThru(); + else + disableOverlayClickThru(); SaveConfig(); } @@ -1314,5 +1327,31 @@ namespace DutyContent.Tab } } } + + void enableOverlayClickThru() + { + int initialStyle = GetWindowLong(_overlay.Handle, -20); + if (DcConfig.Duty.OverlayClickThru) + { + SetWindowLong(_overlay.Handle, -20, initialStyle | 0x80000 | 0x20); + } + else + { + SetWindowLong(_overlay.Handle, -20, (0x00000 | 0x80000)); + } + } + + void disableOverlayClickThru() + { + int initialStyle = GetWindowLong(_overlay.Handle, -20); + if (DcConfig.Duty.OverlayClickThru) + { + SetWindowLong(_overlay.Handle, -20, initialStyle | 0x80000 | 0x20); + } + else + { + SetWindowLong(_overlay.Handle, -20, (0x00000 | 0x80000)); + } + } } }