Skip to content

Commit b199c15

Browse files
author
panwenbo
committed
One.Toolbox
新增禁止Stick贴边最大化;
1 parent 9c1d29c commit b199c15

File tree

4 files changed

+43
-23
lines changed

4 files changed

+43
-23
lines changed

One.Toolbox/Helpers/HideWindowHelper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Runtime.InteropServices;
1+
using System.Diagnostics;
2+
using System.Runtime.InteropServices;
23
using System.Windows.Forms;
34
using System.Windows.Media;
45
using System.Windows.Media.Animation;
@@ -22,7 +23,6 @@ private struct Point
2223
public int X;
2324
public int Y;
2425

25-
// ReSharper disable once UnusedMember.Local
2626
public Point(int x, int y)
2727
{
2828
X = x;
@@ -38,6 +38,7 @@ public Point(int x, int y)
3838
private HideWindowHelper(Window window)
3939
{
4040
_window = window;
41+
4142
_timer = new Timer { Interval = 300 };
4243
_timer.Tick += _timer_Tick;
4344
}

One.Toolbox/ViewModels/Stick/StickItemVM.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,30 @@ namespace One.Toolbox.ViewModels.Stick;
2828

2929
public partial class StickItemVM : BaseVM
3030
{
31-
/// <summary> 预览 </summary>
32-
[ObservableProperty]
33-
private ImageSource screen;
34-
35-
[ObservableProperty]
36-
private bool showAddContent = true;
37-
38-
[ObservableProperty]
39-
private string buttonContent = "显示";
40-
4131
public StickWindow StickWindow { get; set; }
4232

4333
public int Index { get; set; }
4434

45-
[ObservableProperty]
46-
private bool defaultOn;
47-
4835
partial void OnDefaultOnChanged(bool value)
4936
{
5037
SaveSetting();
5138
}
5239

5340
#region Prop
5441

42+
[ObservableProperty]
43+
private bool defaultOn;
44+
45+
/// <summary> 预览 </summary>
46+
[ObservableProperty]
47+
private ImageSource screen;
48+
49+
[ObservableProperty]
50+
private bool showAddContent = true;
51+
52+
[ObservableProperty]
53+
private string buttonContent = "显示";
54+
5555
[ObservableProperty]
5656
private StickType stickType;
5757

@@ -74,7 +74,6 @@ partial void OnDefaultOnChanged(bool value)
7474

7575
private RichTextboxEx currentRtb;
7676
private System.Windows.Controls.Primitives.Popup popup;
77-
//private const string configName = "sticks.txt";
7877

7978
//string tempPath;
8079
public StickItemVM(int index)
@@ -127,7 +126,8 @@ private BitmapImage BitmapToBitmapImage(System.Drawing.Bitmap bitmap)
127126

128127
private void ScreenTheWindow()
129128
{
130-
System.Windows.Media.Imaging.RenderTargetBitmap targetBitmap = new System.Windows.Media.Imaging.RenderTargetBitmap((int)StickWindow.ActualWidth, (int)StickWindow.ActualHeight, 96d, 96d, System.Windows.Media.PixelFormats.Default);
129+
RenderTargetBitmap targetBitmap = new RenderTargetBitmap((int)StickWindow.ActualWidth, (int)StickWindow.ActualHeight, 96d, 96d, System.Windows.Media.PixelFormats.Default);
130+
131131
targetBitmap.Render(StickWindow);
132132
System.Windows.Media.Imaging.PngBitmapEncoder saveEncoder = new System.Windows.Media.Imaging.PngBitmapEncoder();
133133
saveEncoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(targetBitmap));
@@ -272,7 +272,7 @@ void InitData()
272272
{
273273
try
274274
{
275-
var m = IOHelper.Instance.ReadContentFromLocal<StickM>(One.Toolbox.Helpers.PathHelper.stickPath + "Stick" + Index + ".data");
275+
var m = IOHelper.Instance.ReadContentFromLocal<StickItemM>(One.Toolbox.Helpers.PathHelper.stickPath + "Stick" + Index + ".data");
276276

277277
CurrentTheme = m.CurrentTheme;
278278
StickName = m.StickName;
@@ -388,9 +388,9 @@ private void TestA(object obj)
388388

389389
#endregion CenterCommand
390390

391-
public StickM ToModel()
391+
public StickItemM ToModel()
392392
{
393-
StickM stickM = new StickM();
393+
StickItemM stickM = new StickItemM();
394394
stickM.CurrentTheme = CurrentTheme;
395395
stickM.StickName = StickName;
396396
stickM.StickType = StickType;
@@ -401,7 +401,7 @@ public StickM ToModel()
401401
}
402402
}
403403

404-
public class StickM
404+
public class StickItemM
405405
{
406406
public StickTheme CurrentTheme { get; set; }
407407
public string StickName { get; set; }

One.Toolbox/Views/Stick/StickWindow.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
xmlns:ocu="clr-namespace:One.Control.Utilities;assembly=One.Control"
1212
xmlns:vms="clr-namespace:One.Toolbox.ViewModels.Stick"
1313
x:Name="rootWnd"
14-
Title="StickWindow" ResizeMode="NoResize"
14+
Title="StickWindow"
1515
Width="200"
16-
Height="250"
16+
Height="250" MinHeight="100"
1717
d:DataContext="{d:DesignInstance Type=vms:StickItemVM}"
1818
d:DesignHeight="450"
1919
d:DesignWidth="300"

One.Toolbox/Views/Stick/StickWindow.xaml.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using One.Toolbox.Helpers;
22
using One.Toolbox.Views.Settings;
33

4+
using System.Runtime.InteropServices;
45
using System.Windows.Controls;
56

67
using System.Windows.Media;
@@ -39,10 +40,28 @@ private void ButtonPin_Click(object sender, RoutedEventArgs e)
3940
}
4041
}
4142

43+
private const int GWL_STYLE = -16;
44+
private const int WS_MAXIMIZEBOX = 0x00010000;
45+
46+
[DllImport("user32.dll", SetLastError = true)]
47+
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
48+
49+
[DllImport("user32.dll")]
50+
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
51+
4252
private HideWindowHelper _hideWindowHelper;
4353

4454
private void rootWnd_Loaded(object sender, RoutedEventArgs e)
4555
{
56+
IntPtr hWnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
57+
int style = GetWindowLong(hWnd, GWL_STYLE);
58+
59+
// 移除 WS_MAXIMIZEBOX 样式,禁用最大化按钮
60+
style &= ~WS_MAXIMIZEBOX;
61+
62+
SetWindowLong(hWnd, GWL_STYLE, style);
63+
//使用以上代码,你可以禁用 Windows 系统中应用程序贴边触发全屏或重新布局的行为。
64+
4665
_hideWindowHelper = HideWindowHelper
4766
.CreateFor(this)
4867
.AddHider<HideOnLeft>()

0 commit comments

Comments
 (0)