Skip to content

Commit 1908d0d

Browse files
committed
Version 3.14.0.0
1 parent 2d0d1d0 commit 1908d0d

4 files changed

Lines changed: 28 additions & 88 deletions

File tree

CapsLockIndicatorV3/IndicatorOverlay.cs

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,14 @@ public partial class IndicatorOverlay : Form
2525
static extern int GetWindowLongInt(IntPtr hWnd, int nIndex);
2626
[DllImport("user32.dll")]
2727
static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);
28-
//[DllImport("user32.dll")]
29-
//static extern int GetDpiForWindow(IntPtr hWnd);
3028

31-
/*
32-
static float GetDisplayScaleFactor(IntPtr windowHandle)
33-
{
34-
try
35-
{
36-
return GetDpiForWindow(windowHandle) / 96f;
37-
}
38-
catch
39-
{
40-
return 1;
41-
}
42-
}
43-
*/
44-
45-
const int GWL_EXSTYLE = -20;
4629
const uint WS_EX_LAYERED = 0x80000;
30+
const uint WS_EX_TOPMOST = 0x00000008;
31+
const uint WS_EX_TOOLWINDOW = 0x00000080;
32+
const uint WS_EX_TRANSPARENT = 0x00000020;
4733
const uint LWA_ALPHA = 0x2;
4834
const uint LWA_COLORKEY = 0x1;
49-
const uint WS_EX_TRANSPARENT = 0x00000020;
35+
const int GWL_EXSTYLE = -20;
5036
const int WM_NCHITTEST = 0x84;
5137
const int HTTRANSPARENT = -1;
5238

@@ -84,7 +70,7 @@ protected override CreateParams CreateParams
8470
get
8571
{
8672
CreateParams cp = base.CreateParams;
87-
cp.ExStyle |= 0x00000008 | 0x80;
73+
cp.ExStyle |= (int)(WS_EX_TOPMOST | WS_EX_TOOLWINDOW);
8874
return cp;
8975
}
9076
}
@@ -113,14 +99,7 @@ void UpdatePosition()
11399
{
114100
Rectangle workingArea = Screen.GetWorkingArea(Cursor.Position);
115101

116-
//var factor = DPIHelper.GetScalingFactorPercent(Handle);
117-
118-
Size = new Size(
119-
Width,
120-
Height
121-
//(int)(originalSize.Width * factor),
122-
//(int)(originalSize.Height * factor)
123-
);
102+
Size = new Size(Width, Height);
124103

125104
switch (pos)
126105
{
@@ -185,27 +164,23 @@ private int ClickThroughWindow(double opacity = 1d)
185164
return -1;
186165

187166
uint windowLong = GetWindowLong(Handle, GWL_EXSTYLE);
188-
SetWindowLong32(Handle, GWL_EXSTYLE, windowLong ^ WS_EX_LAYERED);
167+
SetWindowLong32(Handle, GWL_EXSTYLE, windowLong | WS_EX_LAYERED);
189168
SetLayeredWindowAttributes(Handle, 0, (byte)(opacity * 255), LWA_ALPHA);
190169

191-
var style = GetWindowLong(Handle, GWL_EXSTYLE);
192-
SetWindowLong(Handle, GWL_EXSTYLE, style | WS_EX_LAYERED | WS_EX_TRANSPARENT);
170+
SetWindowStyles();
193171

194172
return 0;
195173
}
196174

175+
private void SetWindowStyles()
176+
{
177+
var style = GetWindowLong(Handle, GWL_EXSTYLE);
178+
SetWindowLong(Handle, GWL_EXSTYLE, style | WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_TOPMOST);
179+
}
180+
197181
public IndicatorOverlay(string content)
198182
{
199183
InitializeComponent();
200-
201-
//if (IsDisposed)
202-
// return;
203-
204-
//originalSize = Size;
205-
206-
//contentLabel.Text = content;
207-
208-
//ClickThroughWindow();
209184
}
210185

211186
public IndicatorOverlay(string content, int timeoutInMs, IndicatorDisplayPosition position)
@@ -299,6 +274,7 @@ public void UpdateIndicator(string content, IndicatorDisplayPosition position)
299274
fadeTimer.Start();
300275
Show();
301276
UpdatePosition();
277+
SetWindowStyles();
302278
}
303279

304280
public void UpdateIndicator(string content, int timeoutInMs, IndicatorDisplayPosition position)
@@ -323,6 +299,7 @@ public void UpdateIndicator(string content, int timeoutInMs, IndicatorDisplayPos
323299
}
324300
Show();
325301
UpdatePosition();
302+
SetWindowStyles();
326303
}
327304

328305
public void UpdateIndicator(string content, int timeoutInMs, Color bgColour, Color fgColour, Color bdColour, int bdSize, Font font, IndicatorDisplayPosition position, int indOpacity, bool alwaysShow)
@@ -355,6 +332,7 @@ public void UpdateIndicator(string content, int timeoutInMs, Color bgColour, Col
355332
Show();
356333
Invalidate();
357334
UpdatePosition();
335+
SetWindowStyles();
358336
}
359337

360338
void WindowCloseTimerTick(object sender, EventArgs e)
@@ -376,6 +354,7 @@ private void fadeTimer_Tick(object sender, EventArgs e)
376354
private void positionUpdateTimer_Tick(object sender, EventArgs e)
377355
{
378356
UpdatePosition();
357+
SetWindowStyles();
379358
}
380359
}
381360
}

CapsLockIndicatorV3/Program.cs

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ namespace CapsLockIndicatorV3
1818
{
1919
internal sealed class Program
2020
{
21-
// Fix hand cursor
2221
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
2322
private static extern IntPtr LoadCursor(IntPtr hInstance, int lpCursorName);
23+
24+
[DllImport("user32.dll")]
25+
private static extern bool SetProcessDPIAware();
26+
2427
private const int IDC_HAND = 32649;
2528
private static Cursor SystemHandCursor;
2629

@@ -55,58 +58,16 @@ enum DisplayType
5558

5659
public static MainForm MainForm { get; private set; }
5760

58-
static void SetDisplay(DisplayType type, int keys)
59-
{
60-
switch (type)
61-
{
62-
case DisplayType.Icon:
63-
SettingsManager.Set("numIco", (keys & (int)KeyType.NumLock) != 0);
64-
SettingsManager.Set("capsIco", (keys & (int)KeyType.CapsLock) != 0);
65-
SettingsManager.Set("scrollIco", (keys & (int)KeyType.ScrollLock) != 0);
66-
break;
67-
case DisplayType.Notification:
68-
SettingsManager.Set("numInd", (keys & (int)KeyType.NumLock) != 0);
69-
SettingsManager.Set("capsInd", (keys & (int)KeyType.CapsLock) != 0);
70-
SettingsManager.Set("scrollInd", (keys & (int)KeyType.ScrollLock) != 0);
71-
break;
72-
default:
73-
break;
74-
}
75-
}
76-
static void SetHideStartup(bool v)
77-
{
78-
SettingsManager.Set("hideOnStartup", v);
79-
}
80-
static void SetStartup(bool v)
81-
{
82-
RegistryKey rk = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
83-
84-
if (v)
85-
rk.SetValue("CapsLock Indicator", Application.ExecutablePath);
86-
else
87-
rk.DeleteValue("CapsLock Indicator", false);
88-
}
89-
static void SetVerCheck(bool v)
90-
{
91-
SettingsManager.Set("checkForUpdates", v);
92-
}
93-
static void SetLocale(string l)
94-
{
95-
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(l);
96-
}
97-
static void SetDisplayLocation(string v)
98-
{
99-
if (Enum.TryParse(v, out IndicatorDisplayPosition position))
100-
SettingsManager.Set("overlayPosition", position);
101-
}
102-
10361
// Create a mutex to check if an instance is already running
10462
static Mutex mutex = new Mutex(true, "{6f54c357-0542-4d7d-9225-338bc3cd7834}");
10563
[STAThread]
10664
private static void Main(string[] args)
10765
{
10866
SettingsManager.Load();
10967

68+
if (Environment.OSVersion.Version.Major >= 6)
69+
SetProcessDPIAware();
70+
11071
if (mutex.WaitOne(TimeSpan.Zero, true)) // No instance is open
11172
{
11273
Application.EnableVisualStyles();

CapsLockIndicatorV3/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
//
2525
// You can specify all the values or you can use the default the Revision and
2626
// Build Numbers by using the '*' as shown below:
27-
[assembly: AssemblyVersion("3.13.5.0")]
28-
[assembly: AssemblyFileVersion("3.13.5.0")]
27+
[assembly: AssemblyVersion("3.14.0.0")]
28+
[assembly: AssemblyFileVersion("3.14.0.0")]
2929
[assembly: Guid ("6f54c357-0542-4d7d-9225-338bc3cd7834")]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<p align="center"><br /></p>
3131

3232
# Edit & compile source code
33-
You need Microsoft Visual Studio 2019 to edit and compile the source code. CapsLock Indicator has no other dependencies other than the Microsoft .NET SDK 4.5.
33+
You need Microsoft Visual Studio 2019 and the Microsoft .NET 4.7.1 SDK to edit and compile the source code.
3434

3535
# Contributing
3636
If you have a feature suggestion or a bug to file **and you are able to implement this in the code**, feel free to [open a pull request](https://github.com/jonaskohl/CapsLockIndicator/pulls). If you only want to report a bug or suggest a feature, [open a new issue](https://github.com/jonaskohl/CapsLockIndicator/issues/new).

0 commit comments

Comments
 (0)