-
Notifications
You must be signed in to change notification settings - Fork 528
Expand file tree
/
Copy pathKeyShowView.xaml.cs
More file actions
106 lines (92 loc) · 3.09 KB
/
KeyShowView.xaml.cs
File metadata and controls
106 lines (92 loc) · 3.09 KB
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
using System;
using System.Runtime.InteropServices;
using System.Timers;
using System.Windows;
using System.Windows.Interop;
using Carnac.Logic;
namespace Carnac.UI
{
public partial class KeyShowView
{
public KeyShowView(KeyShowViewModel keyShowViewModel)
{
DataContext = keyShowViewModel;
InitializeComponent();
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
var hwnd = new WindowInteropHelper(this).Handle;
Win32Methods.SetWindowExTransparentAndNotInWindowList(hwnd);
var timer = new Timer(100);
timer.Elapsed +=
(s, x) =>
{
SetWindowPos(hwnd,
HWND.TOPMOST,
0, 0, 0, 0,
(uint)(SWP.NOMOVE | SWP.NOSIZE | SWP.SHOWWINDOW));
};
timer.Start();
var vm = ((KeyShowViewModel)DataContext);
Left = vm.Settings.Left;
vm.Settings.LeftChanged += SettingsLeftChanged;
Top = vm.Settings.Top;
vm.Settings.TopChanged += SettingsTopChanged;
WindowState = WindowState.Maximized;
}
[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int W, int H, uint uFlags);
/// <summary>
/// HWND values for hWndInsertAfter
/// </summary>
public static class HWND
{
public static readonly IntPtr
NOTOPMOST = new IntPtr(-2),
BROADCAST = new IntPtr(0xffff),
TOPMOST = new IntPtr(-1),
TOP = new IntPtr(0),
BOTTOM = new IntPtr(1);
}
/// <summary>
/// SetWindowPos Flags
/// </summary>
public static class SWP
{
public static readonly int
NOSIZE = 0x0001,
NOMOVE = 0x0002,
NOZORDER = 0x0004,
NOREDRAW = 0x0008,
NOACTIVATE = 0x0010,
DRAWFRAME = 0x0020,
FRAMECHANGED = 0x0020,
SHOWWINDOW = 0x0040,
HIDEWINDOW = 0x0080,
NOCOPYBITS = 0x0100,
NOOWNERZORDER = 0x0200,
NOREPOSITION = 0x0200,
NOSENDCHANGING = 0x0400,
DEFERERASE = 0x2000,
ASYNCWINDOWPOS = 0x4000;
}
private void WindowLoaded(object sender, RoutedEventArgs e)
{
}
void SettingsLeftChanged(object sender, EventArgs e)
{
WindowState = WindowState.Normal;
var vm = ((KeyShowViewModel)DataContext);
Left = vm.Settings.Left;
WindowState = WindowState.Maximized;
}
void SettingsTopChanged(object sender, EventArgs e)
{
WindowState = WindowState.Normal;
var vm = ((KeyShowViewModel)DataContext);
Top = vm.Settings.Top;
WindowState = WindowState.Maximized;
}
}
}