-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
57 lines (47 loc) · 1.38 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
using System.Runtime.InteropServices;
using System.Timers;
using System.Windows;
using System.Windows.Input;
using Timer = System.Timers.Timer;
namespace ExampleApp;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
public MainWindow()
{
InitializeComponent();
DataContext = this;
}
private void CloseBtn_OnClick(object sender, RoutedEventArgs e)
{
Close();
}
private void MainWindow_OnMouseDown(object sender, MouseButtonEventArgs e)
{
if(e.LeftButton != MouseButtonState.Pressed)
return;
ReleaseCapture();
SendMessage(GetForegroundWindow(), WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
private void MinimizeBtn_OnClick(object sender, RoutedEventArgs e)
{
WindowState = WindowState.Minimized;
}
private void SafeThreadInvoker(Action a)
{
if (!CheckAccess())
Dispatcher.Invoke(a);
else
a();
}
}