-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMediaEngine.cs
3949 lines (3506 loc) · 183 KB
/
CMediaEngine.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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using MFMediaEngine;
using static MFMediaEngine.MediaEngineTools;
using DXGI;
using static DXGI.DXGITools;
using GlobalStructures;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media.Imaging;
using Microsoft.UI.Composition;
using Microsoft.UI.Xaml.Hosting;
using System.IO;
using System.Runtime.InteropServices.WindowsRuntime;
//using D3D11;
namespace WinUI3_MediaEngine
{
public class CMediaEngine : IMFMediaEngineNotify, IMFTimedTextNotify, IDisposable // , System.ComponentModel.INotifyPropertyChanged
{
[DllImport("User32.dll", SetLastError = true)]
public static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr CreateSolidBrush(int crColor);
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool FillRect(IntPtr hdc, [In] ref RECT rect, IntPtr hbrush);
[DllImport("User32", ExactSpelling = true, CharSet = CharSet.Auto)]
public static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("User32", ExactSpelling = true, CharSet = CharSet.Auto)]
public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr CreateCompatibleDC(IntPtr hDC);
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr CreateCompatibleBitmap(IntPtr hDC, int nWidth, int nHeight);
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr CreateBitmap(int nWidth, int nHeight, uint nPlanes, uint nBitCount, IntPtr lpBits);
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool DeleteDC(IntPtr hDC);
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool DeleteObject(IntPtr ho);
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool BitBlt(IntPtr hDC, int x, int y, int nWidth, int nHeight, IntPtr hSrcDC, int xSrc, int ySrc, int dwRop);
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool PatBlt(IntPtr hdc, int x, int y, int w, int h, int rop);
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int SetStretchBltMode(IntPtr hdc, int mode);
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool StretchBlt(IntPtr hdcDest, int xDest, int yDest, int wDest, int hDest, IntPtr hdcSrc, int xSrc, int ySrc, int wSrc, int hSrc, int rop);
public const int BLACKONWHITE = 1;
public const int WHITEONBLACK = 2;
public const int COLORONCOLOR = 3;
public const int HALFTONE = 4;
public const int MAXSTRETCHBLTMODE = 4;
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int GetObject(IntPtr hFont, int nSize, out BITMAP bm);
[StructLayoutAttribute(LayoutKind.Sequential)]
public struct BITMAP
{
public int bmType;
public int bmWidth;
public int bmHeight;
public int bmWidthBytes;
public short bmPlanes;
public short bmBitsPixel;
public IntPtr bmBits;
}
public int RGB(byte r, byte g, byte b)
{
return (r) | ((g) << 8) | ((b) << 16);
}
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern short GetKeyState(int nVirtKey);
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern int GetSystemMetrics(int nIndex);
public const int SM_CXSCREEN = 0;
public const int SM_CYSCREEN = 1;
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern uint GetDpiForWindow(IntPtr hwnd);
public const int VK_LSHIFT = 0xA0;
public const int VK_RMENU = 0xA5;
public const int VK_LMENU = 0xA4;
public const int VK_LCONTROL = 0xA2;
public const int VK_RCONTROL = 0xA3;
public const int VK_LBUTTON = 0x01;
public const int VK_RBUTTON = 0x02;
public const int VK_MBUTTON = 0x04;
public const int VK_XBUTTON1 = 0x05;
public const int VK_XBUTTON2 = 0x06;
public const int VK_ESCAPE = 0x1B;
public const long STGM_READ = 0x00000000L;
public const long GENERIC_READ = (0x80000000L);
public const long GENERIC_WRITE = (0x40000000L);
[DllImport("Shlwapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern HRESULT SHCreateStreamOnFile(string pszFile, int grfMode, out System.Runtime.InteropServices.ComTypes.IStream ppstm);
[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool DeleteFile(string lpFileName);
[DllImport("GdiPlus.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern GpStatus GdiplusStartup(out IntPtr token, ref StartupInput input, out StartupOutput output);
[DllImport("GdiPlus.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern void GdiplusShutdown(IntPtr token);
[StructLayout(LayoutKind.Sequential)]
public struct StartupInput
{
public int GdiplusVersion; // Must be 1
// public DebugEventProc DebugEventCallback; // Ignored on free builds
public IntPtr DebugEventCallback;
public bool SuppressBackgroundThread; // FALSE unless you're prepared to call
// the hook/unhook functions properly
public bool SuppressExternalCodecs; // FALSE unless you want GDI+ only to use
// its internal image codecs.
public static StartupInput GetDefault()
{
StartupInput result = new StartupInput();
result.GdiplusVersion = 1;
// result.DebugEventCallback = null;
result.SuppressBackgroundThread = false;
result.SuppressExternalCodecs = false;
return result;
}
}
[StructLayout(LayoutKind.Sequential)]
public struct StartupOutput
{
public IntPtr hook;//not used
public IntPtr unhook;//not used.
}
[DllImport("GdiPlus.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern GpStatus GdipCreateFromHDC(IntPtr hdc, out IntPtr graphics);
[DllImport("GdiPlus.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern GpStatus GdipDeleteGraphics(IntPtr graphics);
[DllImport("GdiPlus.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern GpStatus GdipDrawImageRect(IntPtr graphics, IntPtr image, float x, float y, float width, float height);
[DllImport("GdiPlus.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern GpStatus GdipDrawImagePointRect(IntPtr graphics, IntPtr image, float x, float y,
float srcx, float srcy, float srcwidth, float srcheight, GpUnit srcUnit);
[DllImport("GdiPlus.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern GpStatus GdipCreateBitmapFromFile(string filename, out IntPtr bitmap);
[DllImport("GdiPlus.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern GpStatus GdipCreateBitmapFromStream(System.Runtime.InteropServices.ComTypes.IStream Stream, out IntPtr bitmap);
[DllImport("GdiPlus.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern GpStatus GdipCreateHBITMAPFromBitmap(IntPtr nativeBitmap, out IntPtr hbitmap, int argbBackground);
[DllImport("GdiPlus.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern GpStatus GdipCreateBitmapFromScan0(int width, int height, int stride, PixelFormat format, IntPtr scan0, out IntPtr bitmap);
[DllImport("GdiPlus.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern GpStatus GdipDisposeImage(IntPtr image);
[DllImport("GdiPlus.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern GpStatus GdipSaveImageToFile(IntPtr image, string filename, ref Guid clsidEncoder, IntPtr /*EncoderParameters**/ encoderParams);
[DllImport("GdiPlus.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern GpStatus GdipGetImageDimension(IntPtr image, ref float width, ref float height);
[DllImport("GdiPlus.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern GpStatus GdipGetImagePixelFormat(IntPtr image, out PixelFormat format);
[DllImport("GdiPlus.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern GpStatus GdipBitmapLockBits(IntPtr bitmap, ref GpRect rect, uint flags, PixelFormat format, [In, Out] BitmapData lockedBitmapData);
[DllImport("GdiPlus.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern GpStatus GdipBitmapUnlockBits(IntPtr bitmap, BitmapData lockedBitmapData);
public enum GpStatus : int
{
Ok = 0,
GenericError = 1,
InvalidParameter = 2,
OutOfMemory = 3,
ObjectBusy = 4,
InsufficientBuffer = 5,
NotImplemented = 6,
Win32Error = 7,
WrongState = 8,
Aborted = 9,
FileNotFound = 10,
ValueOverflow = 11,
AccessDenied = 12,
UnknownImageFormat = 13,
FontFamilyNotFound = 14,
FontStyleNotFound = 15,
NotTrueTypeFont = 16,
UnsupportedGdiplusVersion = 17,
GdiplusNotInitialized = 18,
PropertyNotFound = 19,
PropertyNotSupported = 20,
ProfileNotFound = 21,
}
public enum GpUnit
{
UnitWorld, // 0 -- World coordinate (non-physical unit)
UnitDisplay, // 1 -- Variable -- for PageTransform only
UnitPixel, // 2 -- Each unit is one device pixel.
UnitPoint, // 3 -- Each unit is a printer's point, or 1/72 inch.
UnitInch, // 4 -- Each unit is 1 inch.
UnitDocument, // 5 -- Each unit is 1/300 inch.
UnitMillimeter // 6 -- Each unit is 1 millimeter.
};
public enum PixelFormat : int
{
PixelFormatIndexed = 0x00010000, // Indexes into a palette
PixelFormatGDI = 0x00020000, // Is a GDI-supported format
PixelFormatAlpha = 0x00040000, // Has an alpha component
PixelFormatPAlpha = 0x00080000, // Pre-multiplied alpha
PixelFormatExtended = 0x00100000, // Extended color 16 bits/channel
PixelFormatCanonical = 0x00200000,
PixelFormatUndefined = 0,
PixelFormatDontCare = 0,
PixelFormat1bppIndexed = (1 | (1 << 8) | PixelFormatIndexed | PixelFormatGDI),
PixelFormat4bppIndexed = (2 | (4 << 8) | PixelFormatIndexed | PixelFormatGDI),
PixelFormat8bppIndexed = (3 | (8 << 8) | PixelFormatIndexed | PixelFormatGDI),
PixelFormat16bppGrayScale = (4 | (16 << 8) | PixelFormatExtended),
PixelFormat16bppRGB555 = (5 | (16 << 8) | PixelFormatGDI),
PixelFormat16bppRGB565 = (6 | (16 << 8) | PixelFormatGDI),
PixelFormat16bppARGB1555 = (7 | (16 << 8) | PixelFormatAlpha | PixelFormatGDI),
PixelFormat24bppRGB = (8 | (24 << 8) | PixelFormatGDI),
PixelFormat32bppRGB = (9 | (32 << 8) | PixelFormatGDI),
PixelFormat32bppARGB = (10 | (32 << 8) | PixelFormatAlpha | PixelFormatGDI | PixelFormatCanonical),
PixelFormat32bppPARGB = (11 | (32 << 8) | PixelFormatAlpha | PixelFormatPAlpha | PixelFormatGDI),
PixelFormat48bppRGB = (12 | (48 << 8) | PixelFormatExtended),
PixelFormat64bppARGB = (13 | (64 << 8) | PixelFormatAlpha | PixelFormatCanonical | PixelFormatExtended),
PixelFormat64bppPARGB = (14 | (64 << 8) | PixelFormatAlpha | PixelFormatPAlpha | PixelFormatExtended),
PixelFormat32bppCMYK = (15 | (32 << 8)),
PixelFormatMax = 16
}
[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public sealed class BitmapData
{
public uint Width;
public uint Height;
public int Stride;
public int PixelFormat;
public IntPtr Scan0;
public int Reserved;
};
[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct GpRect
{
public int X;
public int Y;
public int Width;
public int Height;
public GpRect()
{
X = Y = Width = Height = 0;
}
public GpRect(int x, int y, int width, int height)
{
X = x;
Y = y;
Width = width;
Height = height;
}
};
[DllImport("Urlmon.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern HRESULT URLDownloadToCacheFile(IntPtr lpUnkcaller, string szURL, StringBuilder szFileName, uint cchFileName, uint dwReserved, IntPtr pBSC);
public const int WH_MIN = (-1);
public const int WH_MSGFILTER = (-1);
public const int WH_JOURNALRECORD = 0;
public const int WH_JOURNALPLAYBACK = 1;
public const int WH_KEYBOARD = 2;
public const int WH_GETMESSAGE = 3;
public const int WH_CALLWNDPROC = 4;
public const int WH_CBT = 5;
public const int WH_SYSMSGFILTER = 6;
public const int WH_MOUSE = 7;
public const int WH_HARDWARE = 8;
public const int WH_DEBUG = 9;
public const int WH_SHELL = 10;
public const int WH_FOREGROUNDIDLE = 11;
public const int WH_CALLWNDPROCRET = 12;
public const int WH_KEYBOARD_LL = 13;
public const int WH_MOUSE_LL = 14;
public const int WH_MAX = 14;
public const int WH_MINHOOK = WH_MIN;
public const int WH_MAXHOOK = WH_MAX;
[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct MSLLHOOKSTRUCT
{
public System.Drawing.Point pt;
public int mouseData;
public int flags;
public int time;
public uint dwExtraInfo;
}
[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct MOUSEHOOKSTRUCT
{
public POINT pt;
public IntPtr hwnd;
public uint wHitTestCode;
public uint dwExtraInfo;
}
[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct KBDLLHOOKSTRUCT
{
public uint vkCode;
public uint scanCode;
public uint flags;
public uint time;
public uint dwExtraInfo;
}
public delegate int HookProc(int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern bool UnhookWindowsHookEx(int idHook);
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern int CallNextHookEx(int idHook, int nCode, IntPtr wParam, IntPtr lParam);
public const int WM_MOUSEMOVE = 0x0200;
public const int WM_LBUTTONDOWN = 0x0201;
public const int WM_LBUTTONUP = 0x0202;
public const int WM_RBUTTONDOWN = 0x0204;
public const int WM_RBUTTONUP = 0x0205;
[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern uint GetCurrentThreadId();
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern IntPtr GetForegroundWindow();
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern int DrawText(IntPtr hdc, StringBuilder lpStr, int nCount, ref RECT lpRect, int wFormat);
public const int
DT_TOP = 0x00000000,
DT_LEFT = 0x00000000,
DT_CENTER = 0x00000001,
DT_RIGHT = 0x00000002,
DT_VCENTER = 0x00000004,
DT_BOTTOM = 0x00000008,
DT_WORDBREAK = 0x00000010,
DT_SINGLELINE = 0x00000020,
DT_EXPANDTABS = 0x00000040,
DT_TABSTOP = 0x00000080,
DT_NOCLIP = 0x00000100,
DT_EXTERNALLEADING = 0x00000200,
DT_CALCRECT = 0x00000400,
DT_NOPREFIX = 0x00000800,
DT_INTERNAL = 0x00001000,
DT_EDITCONTROL = 0x00002000,
DT_PATH_ELLIPSIS = 0x00004000,
DT_END_ELLIPSIS = 0x00008000,
DT_MODIFYSTRING = 0x00010000,
DT_RTLREADING = 0x00020000,
DT_WORD_ELLIPSIS = 0x00040000,
DT_NOFULLWIDTHCHARBREAK = 0x00080000,
DT_HIDEPREFIX = 0x00100000,
DT_PREFIXONLY = 0x00200000;
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int SetTextColor(IntPtr hdc, int color);
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int SetBkColor(IntPtr hdc, int color);
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern int SetBkMode(IntPtr hdc, int mode);
public const int TRANSPARENT = 1;
public const int OPAQUE = 2;
public const int BKMODE_LAST = 2;
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr CreateFontIndirect([In, MarshalAs(UnmanagedType.LPStruct)] LOGFONT lplf);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class LOGFONT
{
public int lfHeight = 0;
public int lfWidth = 0;
public int lfEscapement = 0;
public int lfOrientation = 0;
public int lfWeight = 0;
public byte lfItalic = 0;
public byte lfUnderline = 0;
public byte lfStrikeOut = 0;
public byte lfCharSet = 0;
public byte lfOutPrecision = 0;
public byte lfClipPrecision = 0;
public byte lfQuality = 0;
public byte lfPitchAndFamily = 0;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string lfFaceName = string.Empty;
}
/* Font Weights */
public const int FW_DONTCARE = 0;
public const int FW_THIN = 100;
public const int FW_EXTRALIGHT = 200;
public const int FW_LIGHT = 300;
public const int FW_NORMAL = 400;
public const int FW_MEDIUM = 500;
public const int FW_SEMIBOLD = 600;
public const int FW_BOLD = 700;
public const int FW_EXTRABOLD = 800;
public const int FW_HEAVY = 900;
public const int DEFAULT_QUALITY = 0;
public const int DRAFT_QUALITY = 1;
public const int PROOF_QUALITY = 2;
public const int NONANTIALIASED_QUALITY = 3;
public const int ANTIALIASED_QUALITY = 4;
public const int CLEARTYPE_QUALITY = 5;
public const int CLEARTYPE_NATURAL_QUALITY = 6;
public const int DEFAULT_PITCH = 0;
public const int FIXED_PITCH = 1;
public const int VARIABLE_PITCH = 2;
public const int MONO_FONT = 8;
public const int OUT_DEFAULT_PRECIS = 0;
public const int OUT_STRING_PRECIS = 1;
public const int OUT_CHARACTER_PRECIS = 2;
public const int OUT_STROKE_PRECIS = 3;
public const int OUT_TT_PRECIS = 4;
public const int OUT_DEVICE_PRECIS = 5;
public const int OUT_RASTER_PRECIS = 6;
public const int OUT_TT_ONLY_PRECIS = 7;
public const int OUT_OUTLINE_PRECIS = 8;
public const int OUT_SCREEN_OUTLINE_PRECIS = 9;
public const int OUT_PS_ONLY_PRECIS = 10;
public const int CLIP_DEFAULT_PRECIS = 0;
public const int CLIP_CHARACTER_PRECIS = 1;
public const int CLIP_STROKE_PRECIS = 2;
public const int CLIP_MASK = 0xf;
public const int CLIP_LH_ANGLES = (1 << 4);
public const int CLIP_TT_ALWAYS = (2 << 4);
public const int CLIP_DFA_DISABLE = (4 << 4);
public const int CLIP_EMBEDDED = (8 << 4);
public const int ANSI_CHARSET = 0;
public const int DEFAULT_CHARSET = 1;
public const int SYMBOL_CHARSET = 2;
/* Font Families */
public const int FF_DONTCARE = (0 << 4); /* Don't care or don't know. */
public const int FF_ROMAN = (1 << 4); /* Variable stroke width, serifed. */
/* Times Roman, Century Schoolbook, etc. */
public const int FF_SWISS = (2 << 4); /* Variable stroke width, sans-serifed. */
/* Helvetica, Swiss, etc. */
public const int FF_MODERN = (3 << 4); /* Constant stroke width, serifed or sans-serifed. */
/* Pica, Elite, Courier, etc. */
public const int FF_SCRIPT = (4 << 4); /* Cursive, etc. */
public const int FF_DECORATIVE = (5 << 4); /* Old English, etc. */
[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int MulDiv(int nNumber, int nNumerator, int nDenominator);
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
public const int HORZSIZE = 4; /* Horizontal size in millimeters */
public const int VERTSIZE = 6; /* Vertical size in millimeters */
public const int HORZRES = 8; /* Horizontal width in pixels */
public const int VERTRES = 10; /* Vertical height in pixels */
public const int PHYSICALWIDTH = 110; /* Physical Width in device units */
public const int PHYSICALHEIGHT = 111; /* Physical Height in device units */
public const int PHYSICALOFFSETX = 112; /* Physical Printable Area x margin */
public const int PHYSICALOFFSETY = 113; /* Physical Printable Area y margin */
public const int LOGPIXELSX = 88; /* Logical pixels/inch in X */
public const int LOGPIXELSY = 90; /* Logical pixels/inch in Y */
public enum AC : byte
{
SRC_OVER = 0,
SRC_ALPHA = 1
}
[StructLayout(LayoutKind.Sequential)]
public struct BLENDFUNCTION
{
public AC BlendOp;
public byte BlendFlags;
public byte SourceConstantAlpha;
public AC AlphaFormat;
}
[DllImport("MSImg32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool AlphaBlend(IntPtr hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest, int hHeightDest, IntPtr hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, BLENDFUNCTION blendFunction);
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr CreateDIBSection(IntPtr hdc, ref BITMAPINFO pbmi, uint usage, ref IntPtr ppvBits, IntPtr hSection, int offset);
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr CreateDIBSection(IntPtr hdc, ref BITMAPV5HEADER pbmi, uint usage, ref IntPtr ppvBits, IntPtr hSection, int offset);
[StructLayout(LayoutKind.Sequential)]
public struct BITMAPINFOHEADER
{
[MarshalAs(UnmanagedType.I4)]
public int biSize;
[MarshalAs(UnmanagedType.I4)]
public int biWidth;
[MarshalAs(UnmanagedType.I4)]
public int biHeight;
[MarshalAs(UnmanagedType.I2)]
public short biPlanes;
[MarshalAs(UnmanagedType.I2)]
public short biBitCount;
[MarshalAs(UnmanagedType.I4)]
public int biCompression;
[MarshalAs(UnmanagedType.I4)]
public int biSizeImage;
[MarshalAs(UnmanagedType.I4)]
public int biXPelsPerMeter;
[MarshalAs(UnmanagedType.I4)]
public int biYPelsPerMeter;
[MarshalAs(UnmanagedType.I4)]
public int biClrUsed;
[MarshalAs(UnmanagedType.I4)]
public int biClrImportant;
}
[StructLayout(LayoutKind.Sequential)]
public struct BITMAPINFO
{
[MarshalAs(UnmanagedType.Struct, SizeConst = 40)]
public BITMAPINFOHEADER bmiHeader;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024)]
public int[] bmiColors;
}
[StructLayout(LayoutKind.Sequential)]
public struct BITMAPV5HEADER
{
public int bV5Size;
public int bV5Width;
public int bV5Height;
public short bV5Planes;
public short bV5BitCount;
public int bV5Compression;
public int bV5SizeImage;
public int bV5XPelsPerMeter;
public int bV5YPelsPerMeter;
public int bV5ClrUsed;
public int bV5ClrImportant;
public int bV5RedMask;
public int bV5GreenMask;
public int bV5BlueMask;
public int bV5AlphaMask;
public int bV5CSType;
public CIEXYZTRIPLE bV5Endpoints;
public int bV5GammaRed;
public int bV5GammaGreen;
public int bV5GammaBlue;
public int bV5Intent;
public int bV5ProfileData;
public int bV5ProfileSize;
public int bV5Reserved;
}
[StructLayout(LayoutKind.Sequential)]
public struct CIEXYZTRIPLE
{
public CIEXYZ ciexyzRed;
public CIEXYZ ciexyzGreen;
public CIEXYZ ciexyzBlue;
}
[StructLayout(LayoutKind.Sequential)]
public struct CIEXYZ
{
public int ciexyzX;
public int ciexyzY;
public int ciexyzZ;
}
public const int BI_RGB = 0;
public const int BI_RLE8 = 1;
public const int BI_RLE4 = 2;
public const int BI_BITFIELDS = 3;
public const int BI_JPEG = 4;
public const int BI_PNG = 5;
public const int DIB_RGB_COLORS = 0;
public const int DIB_PAL_COLORS = 1;
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int StretchDIBits(IntPtr hdc, int XDest, int YDest, int nDestWidth, int nDestHeight, int XSrc, int YSrc, int nSrcWidth, int nSrcHeight, IntPtr lpBits, ref BITMAPINFO lpBitsInfo, int iUsage, int dwRop);
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int StretchDIBits(IntPtr hdc, int XDest, int YDest, int nDestWidth, int nDestHeight, int XSrc, int YSrc, int nSrcWidth, int nSrcHeight, byte[] lpBits, ref BITMAPINFO lpBitsInfo, int iUsage, int dwRop);
public const int SRCCOPY = 0x00CC0020; /* dest = source */
public const int SRCPAINT = 0x00EE0086; /* dest = source OR dest */
public const int SRCAND = 0x008800C6; /* dest = source AND dest */
public const int SRCINVERT = 0x00660046; /* dest = source XOR dest */
public const int SRCERASE = 0x00440328; /* dest = source AND (NOT dest ) */
public const int NOTSRCCOPY = 0x00330008; /* dest = (NOT source) */
public const int NOTSRCERASE = 0x001100A6; /* dest = (NOT src) AND (NOT dest) */
public const int MERGECOPY = 0x00C000CA; /* dest = (source AND pattern) */
public const int MERGEPAINT = 0x00BB0226; /* dest = (NOT source) OR dest */
public const int PATCOPY = 0x00F00021; /* dest = pattern */
public const int PATPAINT = 0x00FB0A09; /* dest = DPSnoo */
public const int PATINVERT = 0x005A0049; /* dest = pattern XOR dest */
public const int DSTINVERT = 0x00550009; /* dest = (NOT dest) */
public const int BLACKNESS = 0x00000042; /* dest = BLACK */
public const int WHITENESS = 0x00FF0062; /* dest = WHITE */
public const int NOMIRRORBITMAP = unchecked((int)0x80000000); /* Do not Mirror the bitmap in this call */
public const int CAPTUREBLT = 0x40000000; /* Include layered windows */
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int GetDIBits(IntPtr hdc, IntPtr hbm, uint start, uint cLines, byte[] lpvBits, ref BITMAPINFO lpbmi, uint usage);
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int GetDIBits(IntPtr hdc, IntPtr hbm, uint start, uint cLines, byte[] lpvBits, ref BITMAPV5HEADER lpbmi, uint usage);
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int SetDIBitsToDevice(IntPtr hdc, int xDest, int yDest, uint w, uint h, int xSrc, int ySrc,
uint StartScan, uint cLines, IntPtr lpvBits, ref BITMAPINFO lpbmi, uint ColorUse);
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int SetDIBitsToDevice(IntPtr hdc, int xDest, int yDest, uint w, uint h, int xSrc, int ySrc,
uint StartScan, uint cLines, IntPtr lpvBits, ref BITMAPV5HEADER lpbmi, uint ColorUse);
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool IntersectRect(out RECT lprcDst, ref RECT lprcSrc1, ref RECT lprcSrc2);
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool PtInRect(ref RECT lprc, POINT pt);
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "RtlMoveMemory")]
public static extern void CopyMemory(IntPtr Destination, IntPtr Source, int Length);
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool bRedraw);
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr CreateRoundRectRgn(int x1, int y1, int x2, int y2, int cx, int cy);
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr CreateRectRgn(int x1, int y1, int x2, int y2);
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int CombineRgn(IntPtr hrgnDest, IntPtr hrgnSrc1, IntPtr hrgnSrc2, int iMode);
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int SelectClipRgn(IntPtr hdc, IntPtr hrgn);
public const int RGN_AND = 1;
public const int RGN_OR = 2;
public const int RGN_XOR = 3;
public const int RGN_DIFF = 4;
public const int RGN_COPY = 5;
public const int RGN_MIN = RGN_AND;
public const int RGN_MAX = RGN_COPY;
public const int ERROR = 0;
public const int NULLREGION = 1;
public const int SIMPLEREGION = 2;
public const int COMPLEXREGION = 3;
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
public const int SWP_NOSIZE = 0x0001;
public const int SWP_NOMOVE = 0x0002;
public const int SWP_NOZORDER = 0x0004;
public const int SWP_NOREDRAW = 0x0008;
public const int SWP_NOACTIVATE = 0x0010;
public const int SWP_FRAMECHANGED = 0x0020; /* The frame changed: send WM_NCCALCSIZE */
public const int SWP_SHOWWINDOW = 0x0040;
public const int SWP_HIDEWINDOW = 0x0080;
public const int SWP_NOCOPYBITS = 0x0100;
public const int SWP_NOOWNERZORDER = 0x0200; /* Don't do owner Z ordering */
public const int SWP_NOSENDCHANGING = 0x0400; /* Don't send WM_WINDOWPOSCHANGING */
public const int SWP_DRAWFRAME = SWP_FRAMECHANGED;
public const int SWP_NOREPOSITION = SWP_NOOWNERZORDER;
public const int SWP_DEFERERASE = 0x2000;
public const int SWP_ASYNCWINDOWPOS = 0x4000;
[DllImport("User32.dll", SetLastError = true)]
public static extern IntPtr CreateWindowEx(int dwExStyle, string lpClassName, string lpWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam);
public const int WS_OVERLAPPED = 0x00000000,
WS_POPUP = unchecked((int)0x80000000),
WS_CHILD = 0x40000000,
WS_MINIMIZE = 0x20000000,
WS_VISIBLE = 0x10000000,
WS_DISABLED = 0x08000000,
WS_CLIPSIBLINGS = 0x04000000,
WS_CLIPCHILDREN = 0x02000000,
WS_MAXIMIZE = 0x01000000,
WS_CAPTION = 0x00C00000,
WS_BORDER = 0x00800000,
WS_DLGFRAME = 0x00400000,
WS_VSCROLL = 0x00200000,
WS_HSCROLL = 0x00100000,
WS_SYSMENU = 0x00080000,
WS_THICKFRAME = 0x00040000,
WS_TABSTOP = 0x00010000,
WS_MINIMIZEBOX = 0x00020000,
WS_MAXIMIZEBOX = 0x00010000,
WS_OVERLAPPEDWINDOW = WS_OVERLAPPED |
WS_CAPTION |
WS_SYSMENU |
WS_THICKFRAME |
WS_MINIMIZEBOX |
WS_MAXIMIZEBOX;
public const int WS_EX_DLGMODALFRAME = 0x00000001;
public const int WS_EX_NOPARENTNOTIFY = 0x00000004;
public const int WS_EX_TOPMOST = 0x00000008;
public const int WS_EX_ACCEPTFILES = 0x00000010;
public const int WS_EX_TRANSPARENT = 0x00000020;
public const int WS_EX_MDICHILD = 0x00000040;
public const int WS_EX_TOOLWINDOW = 0x00000080;
public const int WS_EX_WINDOWEDGE = 0x00000100;
public const int WS_EX_CLIENTEDGE = 0x00000200;
public const int WS_EX_CONTEXTHELP = 0x00000400;
public const int WS_EX_RIGHT = 0x00001000;
public const int WS_EX_LEFT = 0x00000000;
public const int WS_EX_RTLREADING = 0x00002000;
public const int WS_EX_LTRREADING = 0x00000000;
public const int WS_EX_LEFTSCROLLBAR = 0x00004000;
public const int WS_EX_RIGHTSCROLLBAR = 0x00000000;
public const int WS_EX_CONTROLPARENT = 0x00010000;
public const int WS_EX_STATICEDGE = 0x00020000;
public const int WS_EX_APPWINDOW = 0x00040000;
public const int WS_EX_OVERLAPPEDWINDOW = (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE);
public const int WS_EX_PALETTEWINDOW = (WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST);
public const int WS_EX_LAYERED = 0x00080000;
public const int WS_EX_NOINHERITLAYOUT = 0x00100000; // Disable inheritence of mirroring by children
public const int WS_EX_NOREDIRECTIONBITMAP = 0x00200000;
public const int WS_EX_LAYOUTRTL = 0x00400000; // Right to left mirroring
public const int WS_EX_COMPOSITED = 0x02000000;
public const int WS_EX_NOACTIVATE = 0x08000000;
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool MoveWindow(IntPtr hWnd, int x, int y, int cx, int cy, bool repaint);
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool ShowWindow(IntPtr hWnd, int nShowCmd);
public const int SW_HIDE = 0;
public const int SW_SHOWNORMAL = 1;
public const int SW_SHOWMINIMIZED = 2;
public const int SW_SHOWMAXIMIZED = 3;
public const int SW_SHOWNOACTIVATE = 4;
public const int SW_SHOW = 5;
public const uint LWA_COLORKEY = 0x00000001;
public const uint LWA_ALPHA = 0x00000002;
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndParent);
const int GWL_STYLE = (-16);
const int GWL_EXSTYLE = (-20);
public static IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
{
if (IntPtr.Size == 4)
{
return SetWindowLongPtr32(hWnd, nIndex, dwNewLong);
}
return SetWindowLongPtr64(hWnd, nIndex, dwNewLong);
}
[DllImport("User32.dll", CharSet = CharSet.Auto, EntryPoint = "SetWindowLong")]
public static extern IntPtr SetWindowLongPtr32(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
[DllImport("User32.dll", CharSet = CharSet.Auto, EntryPoint = "SetWindowLongPtr")]
public static extern IntPtr SetWindowLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
// public static IntPtr GetWindowLong(HandleRef hWnd, int nIndex)
public static long GetWindowLong(IntPtr hWnd, int nIndex)
{
if (IntPtr.Size == 4)
{
return GetWindowLong32(hWnd, nIndex);
}
return GetWindowLongPtr64(hWnd, nIndex);
}
[DllImport("User32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto)]
public static extern long GetWindowLong32(IntPtr hWnd, int nIndex);
[DllImport("User32.dll", EntryPoint = "GetWindowLongPtr", CharSet = CharSet.Auto)]
public static extern long GetWindowLongPtr64(IntPtr hWnd, int nIndex);
private IMFMediaEngine m_pMediaEngine = null;
private IMFMediaEngineEx m_pMediaEngineEx = null;
private IntPtr m_pD3D11DevicePtr = IntPtr.Zero;
private IntPtr m_pD3D11DeviceContextPtr = IntPtr.Zero;
private IMFDXGIDeviceManager m_pDXGIDeviceManager = null;
private IntPtr m_hWnd = IntPtr.Zero;
private FrameworkElement m_VideoContainer = null;
private Slider m_SliderTime = null;
private TextBlock m_TextBlockElapsedTime = null;
public IntPtr m_hWndContainer = IntPtr.Zero;
private IDXGISwapChain1 m_pDXGISwapChain1 = null;
private MFARGB m_BorderColor;
private bool m_bPlaying = false;
private bool m_bPause = false;
private bool m_bInitialized = false;
private IMFMediaEngineClassFactory m_pMediaEngineClassFactory = null;
private IntPtr m_pUnknownMediaEngineNotify = IntPtr.Zero;
private IMFAttributes m_pAttributes = null;
private uint m_nFlags = 0;
private IntPtr m_initToken = IntPtr.Zero;
private IntPtr m_hBitmapLogo = IntPtr.Zero;
private IntPtr m_hBitmapOverlay = IntPtr.Zero;
private IntPtr m_hBitmapNotes = IntPtr.Zero;
private bool m_bOverLay = false;
private bool m_bEffects = false;
private EFFECT m_nEffects = EFFECT.NONE;
private bool m_bCapture = false;
private IntPtr m_hGDIPlusBitmapCapture = IntPtr.Zero;
private IntPtr m_hBitmapCapture = IntPtr.Zero;
private WriteableBitmap m_hWriteableBitmapCapture = null;
private IMFTimedText m_pTimedText = null;
private bool m_bSubtitles = false;
private string m_sSubtitlesURL = string.Empty;
private string m_sSubtitleText = string.Empty;
private bool m_bFullScreen = false;
private static int m_hHook = 0;
private HookProc MouseProcedure;
private double m_nControlsHeight = 0;
public enum ME_MODE
{
MODE_FRAME_SERVER = 0,
MODE_RENDERING = 2,
MODE_AUDIO = 3
}
public enum DT_VERTICAL
{
TOP = 0,
CENTER = 1,
BOTTOM = 2
}
public enum EFFECT
{
NONE = 0,
GRAYSCALE = 0x0001,
INVERT = 0x0002,
RGB = 0x0004,
LIGHTEN = 0x0008,
}
public byte EFFECT_RGB_INTENSITY_RED = 0;
public byte EFFECT_RGB_INTENSITY_GREEN = 0;
public byte EFFECT_RGB_INTENSITY_BLUE = 0;
public double EFFECT_LIGHTEN_INTENSITY = 0.5;
public CMediaEngine()
{
HRESULT hr = HRESULT.S_OK;
hr = MFStartup(MF_VERSION);
StartupInput input = StartupInput.GetDefault();
StartupOutput output;
GpStatus nStatus = GdiplusStartup(out m_initToken, ref input, out output);
}
HRESULT IMFMediaEngineNotify.EventNotify(MF_MEDIA_ENGINE_EVENT nEvent, IntPtr param1, uint param2)
{
HRESULT hr = HRESULT.S_OK;
switch (nEvent)
{
case MF_MEDIA_ENGINE_EVENT.MF_MEDIA_ENGINE_EVENT_PLAY:
case MF_MEDIA_ENGINE_EVENT.MF_MEDIA_ENGINE_EVENT_PLAYING:
m_bPlaying = true;
m_bPause = false;
break;
case MF_MEDIA_ENGINE_EVENT.MF_MEDIA_ENGINE_EVENT_PAUSE:
m_bPause = true;
break;
case MF_MEDIA_ENGINE_EVENT.MF_MEDIA_ENGINE_EVENT_ENDED:
m_bPlaying = false;
m_bPause = false;
Notify(nEvent);
break;
//case MF_MEDIA_ENGINE_EVENT.MF_MEDIA_ENGINE_EVENT_FIRSTFRAMEREADY:
case MF_MEDIA_ENGINE_EVENT.MF_MEDIA_ENGINE_EVENT_LOADEDMETADATA:
//case MF_MEDIA_ENGINE_EVENT.MF_MEDIA_ENGINE_EVENT_DURATIONCHANGE:
//case MF_MEDIA_ENGINE_EVENT.MF_MEDIA_ENGINE_EVENT_LOADEDDATA:
//case MF_MEDIA_ENGINE_EVENT.MF_MEDIA_ENGINE_EVENT_CANPLAY:
//case MF_MEDIA_ENGINE_EVENT.MF_MEDIA_ENGINE_EVENT_CANPLAYTHROUGH:
//case MF_MEDIA_ENGINE_EVENT.MF_MEDIA_ENGINE_EVENT_TIMEUPDATE:
// Duration = m_pMediaEngine.GetDuration();
Notify(nEvent);
break;
//case MF_MEDIA_ENGINE_EVENT.MF_MEDIA_ENGINE_EVENT_WAITING:
// m_bPlaying = false;
// m_bPause = false;
// break;
case MF_MEDIA_ENGINE_EVENT.MF_MEDIA_ENGINE_EVENT_TIMEUPDATE:
Notify(nEvent);
break;
case MF_MEDIA_ENGINE_EVENT.MF_MEDIA_ENGINE_EVENT_SEEKING:
case MF_MEDIA_ENGINE_EVENT.MF_MEDIA_ENGINE_EVENT_SEEKED:
m_bPlaying = true;
break;
case MF_MEDIA_ENGINE_EVENT.MF_MEDIA_ENGINE_EVENT_ERROR:
m_bPlaying = false;
m_bPause = false;
string sError = string.Format("EVENT_ERROR ({0}, 0x{1:X})", param1, param2);
DisplayTimedText(sError, true, 10000);
break;
}
// MF_MEDIA_ENGINE_EVENT_ERROR (4, 0x80070005) : HRESULT: 0x80070005 (E_ACCESSDENIED)
// System.Diagnostics.Debug.WriteLine("Event : {0} ({1}, 0x{2:X})", nEvent, param1, param2);
return hr;
}
Grid gridContainer = null;
CImageButton buttonPlayPause = null;
CImageButton buttonStop = null;
CImageButton buttonRepeat = null;
CImageButton buttonFullscreen = null;