-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMiniMap-Displayer.cs
114 lines (96 loc) · 4.18 KB
/
MiniMap-Displayer.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.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DbD_MiniMap
{
public partial class MiniMap_Displayer : Form
{
public MiniMap_Displayer()
{
InitializeComponent();
}
[DllImport("user32.dll", SetLastError = true)]
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
const int GWL_EXSTYLE = -20;
const int WS_EX_LAYERED = 0x80000;
const int WS_EX_TRANSPARENT = 0x20;
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
var style = GetWindowLong(this.Handle, GWL_EXSTYLE);
SetWindowLong(this.Handle, GWL_EXSTYLE, style | WS_EX_LAYERED | WS_EX_TRANSPARENT);
}
private string _fileName;
public string FileName
{
get { return _fileName; }
set { _fileName = value; }
}
private void MiniMap_Displayer_VisibleChanged(object sender, EventArgs e)
{
int locationX = int.Parse(FileManagement.GetValue("LocationX"));
int locationY = int.Parse(FileManagement.GetValue("LocationY"));
int size = int.Parse(FileManagement.GetValue("Size"));
pbMiniMap.Size = new Size(100 + size, 100 + size);
this.Size = pbMiniMap.Size;
this.Location = new Point(Screen.PrimaryScreen.Bounds.Width / 2 - this.Width / 2 + locationX, Screen.PrimaryScreen.Bounds.Height / 2 - this.Height / 2 - locationY);
pbMiniMap.Location = new Point(this.Width/2 - pbMiniMap.Width/2, this.Height / 2 - pbMiniMap.Height / 2);
if (_fileName != "None" && _fileName != null)
{
pbMiniMap.LoadAsync(_fileName);
pbMiniMap.Show();
}
else
{
pbMiniMap.Hide();
}
var style = GetWindowLong(this.Handle, GWL_EXSTYLE);
SetWindowLong(this.Handle, GWL_EXSTYLE, style | WS_EX_LAYERED | WS_EX_TRANSPARENT);
}
private void MiniMap_Displayer_Move(object sender, EventArgs e)
{
var style = GetWindowLong(this.Handle, GWL_EXSTYLE);
SetWindowLong(this.Handle, GWL_EXSTYLE, style | WS_EX_LAYERED | WS_EX_TRANSPARENT);
}
private void MiniMap_Displayer_Resize(object sender, EventArgs e)
{
var style = GetWindowLong(this.Handle, GWL_EXSTYLE);
SetWindowLong(this.Handle, GWL_EXSTYLE, style | WS_EX_LAYERED | WS_EX_TRANSPARENT);
}
private void MiniMap_Displayer_Load(object sender, EventArgs e)
{
this.BackColor = SystemColors.HotTrack;
this.TransparencyKey = SystemColors.HotTrack;
var style = GetWindowLong(this.Handle, GWL_EXSTYLE);
SetWindowLong(this.Handle, GWL_EXSTYLE, style | WS_EX_LAYERED | WS_EX_TRANSPARENT);
}
private void pbMiniMap_LoadCompleted(object sender, AsyncCompletedEventArgs e)
{
var style = GetWindowLong(this.Handle, GWL_EXSTYLE);
SetWindowLong(this.Handle, GWL_EXSTYLE, style | WS_EX_LAYERED | WS_EX_TRANSPARENT);
}
private void pbMiniMap_LocationChanged(object sender, EventArgs e)
{
var style = GetWindowLong(this.Handle, GWL_EXSTYLE);
SetWindowLong(this.Handle, GWL_EXSTYLE, style | WS_EX_LAYERED | WS_EX_TRANSPARENT);
}
private void pbMiniMap_VisibleChanged(object sender, EventArgs e)
{
var style = GetWindowLong(this.Handle, GWL_EXSTYLE);
SetWindowLong(this.Handle, GWL_EXSTYLE, style | WS_EX_LAYERED | WS_EX_TRANSPARENT);
}
private void MiniMap_Displayer_FormClosing(object sender, FormClosingEventArgs e)
{
Application.Exit();
}
}
}