-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEVRPlayListener.cs
317 lines (278 loc) · 10.1 KB
/
EVRPlayListener.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using DirectShowLib;
using System.ComponentModel;
namespace babgvant.EVRPlay
{
class EVRPlayListener : IDisposable
{
#region Enum
private enum ClassStyle : uint
{
VREDRAW = 0x0001,
HREDRAW = 0x0002,
DBLCLKS = 0x0008,
OWNDC = 0x0020,
CLASSDC = 0x0040,
PARENTDC = 0x0080,
NOCLOSE = 0x0200,
SAVEBITS = 0x0800,
BYTEALIGNCLIENT = 0x1000,
BYTEALIGNWINDOW = 0x2000,
GLOBALCLASS = 0x4000
}
private enum WindowStyle : uint
{
OVERLAPPED = 0x00000000,
POPUP = 0x80000000,
CHILD = 0x40000000,
MINIMIZE = 0x20000000,
VISIBLE = 0x10000000,
DISABLED = 0x08000000,
CLIPSIBLINGS = 0x04000000,
CLIPCHILDREN = 0x02000000,
MAXIMIZE = 0x01000000,
CAPTION = 0x00C00000, /* WS_BORDER | WS_DLGFRAME */
BORDER = 0x00800000,
DLGFRAME = 0x00400000,
VSCROLL = 0x00200000,
HSCROLL = 0x00100000,
SYSMENU = 0x00080000,
THICKFRAME = 0x00040000,
GROUP = 0x00020000,
TABSTOP = 0x00010000,
MINIMIZEBOX = 0x00020000,
MAXIMIZEBOX = 0x00010000,
TILED = OVERLAPPED,
ICONIC = MINIMIZE,
SIZEBOX = THICKFRAME,
TILEDWINDOW = OVERLAPPEDWINDOW,
OVERLAPPEDWINDOW = OVERLAPPED | CAPTION |
SYSMENU |
THICKFRAME |
MINIMIZEBOX |
MAXIMIZEBOX,
POPUPWINDOW = POPUP |
BORDER |
SYSMENU,
CHILDWINDOW = CHILD,
EX_DLGMODALFRAME = 0x00000001,
EX_NOPARENTNOTIFY = 0x00000004,
EX_TOPMOST = 0x00000008,
EX_ACCEPTFILES = 0x00000010,
EX_TRANSPARENT = 0x00000020,
EX_MDICHILD = 0x00000040,
EX_TOOLWINDOW = 0x00000080,
EX_WINDOWEDGE = 0x00000100,
EX_CLIENTEDGE = 0x00000200,
EX_CONTEXTHELP = 0x00000400,
EX_RIGHT = 0x00001000,
EX_LEFT = 0x00000000,
EX_RTLREADING = 0x00002000,
EX_LTRREADING = 0x00000000,
EX_LEFTSCROLLBAR = 0x00004000,
EX_RIGHTSCROLLBAR = 0x00000000,
EX_CONTROLPARENT = 0x00010000,
EX_STATICEDGE = 0x00020000,
EX_APPWINDOW = 0x00040000,
EX_OVERLAPPEDWINDOW = (EX_WINDOWEDGE | EX_CLIENTEDGE),
EX_PALETTEWINDOW = (EX_WINDOWEDGE | EX_TOOLWINDOW | EX_TOPMOST),
EX_LAYERED = 0x00080000,
EX_NOINHERITLAYOUT = 0x00100000, // Disable inheritence of mirroring by children
EX_LAYOUTRTL = 0x00400000, // Right to left mirroring
EX_COMPOSITED = 0x02000000,
EX_NOACTIVATE = 0x08000000
}
#endregion
#region Struct
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
struct WNDCLASS
{
public ClassStyle style;
public WndProc lpfnWndProc;
public int cbClsExtra;
public int cbWndExtra;
public IntPtr hInstance;
public IntPtr hIcon;
public IntPtr hCursor;
public IntPtr hbrBackground;
[MarshalAs(UnmanagedType.LPWStr)]
public string lpszMenuName;
[MarshalAs(UnmanagedType.LPWStr)]
public string lpszClassName;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
struct WNDCLASSEX
{
[MarshalAs(UnmanagedType.U4)]
public int cbSize;
[MarshalAs(UnmanagedType.U4)]
public ClassStyle style;
public WndProc lpfnWndProc;
public int cbClsExtra;
public int cbWndExtra;
public IntPtr hInstance;
public IntPtr hIcon;
public IntPtr hCursor;
public IntPtr hbrBackground;
public string lpszMenuName;
public string lpszClassName;
public IntPtr hIconSm;
}
#endregion
#region pinvoke
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern ushort RegisterClass([In] ref WNDCLASS lpWndClass);
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Auto)]
extern static ushort RegisterClassEx([MarshalAs(UnmanagedType.Struct)]ref WNDCLASSEX wndClassEx);
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Auto)]
extern static bool UnregisterClass(string lpClassName, IntPtr hInstance);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern bool GetClassInfoEx(IntPtr hinst, string lpszClass, out WNDCLASSEX lpwcx);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern IntPtr CreateWindowEx(
WindowStyle dwExStyle,
ushort sClassAtom,
string lpWindowName,
UInt32 dwStyle,
Int32 x,
Int32 y,
Int32 nWidth,
Int32 nHeight,
IntPtr hWndParent,
IntPtr hMenu,
IntPtr hInstance,
IntPtr lpParam);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern IntPtr CreateWindowEx(
WindowStyle dwExStyle,
string lpClassName,
string lpWindowName,
UInt32 dwStyle,
Int32 x,
Int32 y,
Int32 nWidth,
Int32 nHeight,
IntPtr hWndParent,
IntPtr hMenu,
IntPtr hInstance,
IntPtr lpParam);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern System.IntPtr DefWindowProc(IntPtr hWnd, WM msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern bool DestroyWindow(IntPtr hWnd);
#endregion
delegate IntPtr WndProc(IntPtr hWnd, WM msg, IntPtr wParam, IntPtr lParam);
private bool m_disposed = false;
private IntPtr m_hwnd;
private MainForm m_parent;
private WndProc m_KeepMe;
private const string EVR_CLASS = "EVRPlayApp";
private const string EVR_WIN = "EVRPlayWin";
public EVRPlayListener(MainForm parent)
{
m_parent = parent;
m_KeepMe = new WndProc(CustomWndProc);
IntPtr hInstance = Marshal.GetHINSTANCE(this.GetType().Module);
WNDCLASSEX wndClassEx = new WNDCLASSEX();
wndClassEx.cbSize = Marshal.SizeOf(typeof(WNDCLASSEX));
wndClassEx.style = ClassStyle.GLOBALCLASS;
wndClassEx.cbClsExtra = 0;
wndClassEx.cbWndExtra = 0;
wndClassEx.hbrBackground = IntPtr.Zero;
wndClassEx.hCursor = IntPtr.Zero;
wndClassEx.hIcon = IntPtr.Zero;
wndClassEx.hIconSm = IntPtr.Zero;
wndClassEx.lpszClassName = EVR_CLASS;
wndClassEx.lpszMenuName = null;
wndClassEx.hInstance = hInstance;
wndClassEx.lpfnWndProc = m_KeepMe;
ushort atom = RegisterClassEx(ref wndClassEx);
//WNDCLASSEX lpwcx;
//bool isReg = GetClassInfoEx(hInstance, EVR_CLASS, out lpwcx);
if (atom == 0)
{
int error = Marshal.GetLastWin32Error();
throw new Win32Exception(error);
}
// Create window
//m_hwnd = CreateWindowEx(
// WindowStyle.EX_NOACTIVATE,
// atom,
// EVR_WIN,
// 0,
// 0,
// 0,
// 0,
// 0,
// IntPtr.Zero,
// IntPtr.Zero,
// Marshal.GetHINSTANCE(parent.GetType().Module),
// IntPtr.Zero
//);
m_hwnd = CreateWindowEx(
WindowStyle.EX_NOACTIVATE,
EVR_CLASS,
EVR_WIN,
0,
0,
0,
0,
0,
IntPtr.Zero,
IntPtr.Zero,
hInstance,
IntPtr.Zero
);
if (m_hwnd == IntPtr.Zero)
{
int error = Marshal.GetLastWin32Error();
throw new Win32Exception(error);
}
}
private IntPtr CustomWndProc(IntPtr hWnd, WM msg, IntPtr wParam, IntPtr lParam)
{
switch (msg)
{
case WM.SAGE:
switch ((SageMessage)lParam)
{
case SageMessage.SageTVRecordings:
m_parent.ShowMediaBrowser(BrowseMode.Recordings);
break;
case SageMessage.VideoLibrary:
m_parent.ShowMediaBrowser(BrowseMode.Media);
break;
}
break;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
#region IDisposable
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (!m_disposed)
{
if (disposing)
{
// Dispose managed resources
}
// Dispose unmanaged resources
if (m_hwnd != IntPtr.Zero)
{
DestroyWindow(m_hwnd);
m_hwnd = IntPtr.Zero;
}
}
}
#endregion
}
}