-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWin32.cs
43 lines (35 loc) · 1.2 KB
/
Win32.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
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
namespace DesktopClock
{
public static class Win32
{
private const int WS_EX_TRANSPARENT = 0x00000020;
private const int WS_EX_NOACTIVATE = 0x08000000;
private const int GWL_EXSTYLE = -20;
[DllImport("user32.dll")]
private static extern int GetWindowLong(IntPtr hwnd, int index);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle);
public static void MakeTransparent(Window window)
{
var handle = window.GetHandle();
// Change the extended window style to include WS_EX_TRANSPARENT
int extendedStyle = GetWindowLong(handle, GWL_EXSTYLE);
SetWindowLong(handle, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT);
}
public static void MakeNoActivate(Window window)
{
var handle = window.GetHandle();
// Change the extended window style to include WS_EX_NOACTIVATE
int extendedStyle = GetWindowLong(handle, GWL_EXSTYLE);
SetWindowLong(handle, GWL_EXSTYLE, extendedStyle | WS_EX_NOACTIVATE);
}
private static IntPtr GetHandle(this Window window)
{
return new WindowInteropHelper(window).Handle;
}
}
}