-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
114 lines (95 loc) · 3.87 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
namespace RoundedWindowsEdges
{
public partial class MainWindow : Window
{
public const int WS_EX_TRANSPARENT = 0x00000020;
public const int GWL_EXSTYLE = (-20);
public const int WS_EX_TOOLWINDOW = 0x00000080;
[DllImport("user32.dll")]
public static extern int GetWindowLong(IntPtr hwnd, int index);
[DllImport("user32.dll")]
public static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle);
private AppConfig config;
private int currentCornerSize;
public MainWindow()
{
InitializeComponent();
DataContext = this;
}
public MainWindow(Rect screenBounds, int cornerSize) : this()
{
InitializeForScreen(screenBounds, cornerSize);
LoadConfig();
}
private void InitializeForScreen(Rect screenBounds, int cornerSize)
{
this.CornerSize = cornerSize;
this.Left = screenBounds.Left;
this.Top = screenBounds.Top;
this.Width = screenBounds.Width;
this.Height = screenBounds.Height;
Debug.WriteLine($"Window initialized: Left = {this.Left}, Top = {this.Top}, Width = {this.Width}, Height = {this.Height}");
}
public int CornerSize { get; set; }
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
IntPtr hwnd = new WindowInteropHelper(this).Handle;
int extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW);
}
private void WndRoundedWindowsEdges_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
this.Hide(); // Hide instead of cancelling close to ensure cleanup
}
private void WndRoundedWindowsEdges_Loaded(object sender, RoutedEventArgs e)
{
Point location = this.PointToScreen(new Point(0, 0));
this.WindowStartupLocation = WindowStartupLocation.Manual;
}
private void WndRoundedWindowsEdges_LostFocus(object sender, RoutedEventArgs e)
{
this.Activate();
this.Topmost = true;
this.Topmost = false;
this.Focus();
}
public void ChangeCornerSize(int size)
{
Debug.WriteLine("ChangeCornerSize method called");
imgCornerTL.Width = size;
imgCornerTL.Height = size;
imgCornerTR.Width = size;
imgCornerTR.Height = size;
imgCornerBR.Width = size;
imgCornerBR.Height = size;
imgCornerBL.Width = size;
imgCornerBL.Height = size;
Debug.WriteLine($"Changing corner size to {size}");
Debug.WriteLine($"imgCornerTL: {imgCornerTL.Visibility}, {imgCornerTL.Width}, {imgCornerTL.Height}");
Debug.WriteLine($"imgCornerTR: {imgCornerTR.Visibility}, {imgCornerTR.Width}, {imgCornerTR.Height}");
Debug.WriteLine($"imgCornerBR: {imgCornerBR.Visibility}, {imgCornerBR.Width}, {imgCornerBR.Height}");
Debug.WriteLine($"imgCornerBL: {imgCornerBL.Visibility}, {imgCornerBL.Width}, {imgCornerBL.Height}");
// Save the new size to the config file
config.CornerSize = size;
config.SaveConfig();
currentCornerSize = size;
}
private void LoadConfig()
{
Debug.WriteLine("LoadConfig method called");
config = AppConfig.LoadConfig();
ChangeCornerSize(config.CornerSize);
}
public int GetCornerSize()
{
return currentCornerSize;
}
}
}