ScreenRecorderWindow.xaml.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. using H.Pipes;
  2. using InABox.Core;
  3. using InABox.WPF;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Reactive.Subjects;
  8. using System.Runtime.InteropServices;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Data;
  14. using System.Windows.Documents;
  15. using System.Windows.Input;
  16. using System.Windows.Interop;
  17. using System.Windows.Media;
  18. using System.Windows.Media.Imaging;
  19. using System.Windows.Navigation;
  20. using System.Windows.Shapes;
  21. using WampSharp.V2;
  22. using WampSharp.V2.Realm;
  23. namespace PRSRecordingNotes
  24. {
  25. /// <summary>
  26. /// Interaction logic for MainWindow.xaml
  27. /// </summary>
  28. public partial class ScreenRecorderWindow : Window
  29. {
  30. public PipeClient<string> _client { get; private set; }
  31. //IWampHost _host = null;
  32. //IWampHostedRealm _realm = null;
  33. //IWampSubject _subject = null;
  34. //IDisposable _subscription = null;
  35. private const int GWL_STYLE = -16;
  36. private const int WS_SYSMENU = 0x80000;
  37. [DllImport("user32.dll", SetLastError = true)]
  38. private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
  39. [DllImport("user32.dll")]
  40. private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
  41. public ScreenRecorderWindow()
  42. {
  43. Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense(CoreUtils.SyncfusionLicense(SyncfusionVersion.v19_4));
  44. InitializeComponent();
  45. HotKeyManager.Initialize();
  46. HotKeyManager.RegisterHotKey(
  47. Key.F6,
  48. () => {
  49. ResumeRecording(false);
  50. return true;
  51. }
  52. );
  53. Move.Source = Properties.Resources.target.AsBitmapImage();
  54. _client = new PipeClient<string>("PRSScreenRecorder",".");
  55. _client.MessageReceived += (o, args) =>
  56. {
  57. ServerMessage(args.Message);
  58. };
  59. _client.ConnectAsync();
  60. //_host = new WampSharp.V2.DefaultWampHost("ws://127.0.0.1:8001/prs");
  61. //_host.Open();
  62. //_realm = _host.RealmContainer.GetRealmByName("PRS");
  63. //_realm.SessionCreated += _realm_SessionCreated;
  64. //_realm.SessionClosed += _realm_SessionClosed;
  65. //_subject = _realm.Services.GetSubject("ScreenRecording");
  66. //_subscription = _subject.Subscribe(
  67. // x =>
  68. // {
  69. // String command = x.Arguments[0].Deserialize<String>();
  70. // if (String.Equals(command, "EDIT"))
  71. // Dispatcher.Invoke(() => { EditNotes(); });
  72. // else if (String.Equals(command, "QUIT"))
  73. // Dispatcher.Invoke(() => { System.Windows.Application.Current.Shutdown(); });
  74. // }
  75. //);
  76. Hide();
  77. }
  78. private void ServerMessage(string message)
  79. {
  80. if (String.Equals(message, "EDIT"))
  81. Dispatcher.Invoke(() => { EditNotes(); });
  82. else if (String.Equals(message, "QUIT"))
  83. Dispatcher.Invoke(() => { System.Windows.Application.Current.Shutdown(); });
  84. }
  85. private void _realm_SessionClosed(object sender, WampSessionCloseEventArgs e)
  86. {
  87. }
  88. private void _realm_SessionCreated(object sender, WampSessionCreatedEventArgs e)
  89. {
  90. }
  91. private void Window_Loaded(object sender, RoutedEventArgs e)
  92. {
  93. var hwnd = new WindowInteropHelper(this).Handle;
  94. SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);
  95. }
  96. public void EditNotes()
  97. {
  98. Buttons.Visibility = Visibility.Visible;
  99. Show();
  100. }
  101. private void Close_Click(object sender, RoutedEventArgs e)
  102. {
  103. ResumeRecording(true);
  104. }
  105. private void Resume_Click(object sender, RoutedEventArgs e)
  106. {
  107. ResumeRecording(false);
  108. }
  109. private void ResumeRecording(bool hide)
  110. {
  111. if (hide)
  112. Hide();
  113. Buttons.Visibility = Visibility.Collapsed;
  114. _client.WriteAsync("RESUME");
  115. //_subject.OnNext(new WampEvent() { Arguments = new[] { "RESUME" } });
  116. }
  117. private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
  118. {
  119. }
  120. //bool bMoving = false;
  121. //Point offset;
  122. private void Move_MouseDown(object sender, MouseButtonEventArgs e)
  123. {
  124. //offset = e.GetPosition(this);
  125. //bMoving = true;
  126. this.DragMove();
  127. }
  128. private void Move_MouseUp(object sender, MouseButtonEventArgs e)
  129. {
  130. //bMoving = false;
  131. }
  132. private void Move_MouseMove(object sender, MouseEventArgs e)
  133. {
  134. //if (!bMoving)
  135. // return;
  136. //var current = e.GetPosition(this);
  137. //Left = current.X - offset.X;
  138. //Top = current.Y - offset.Y;
  139. }
  140. /// <summary>Brings main window to foreground.</summary>
  141. public void BringToForeground()
  142. {
  143. //if (this.WindowState == WindowState.Minimized || this.Visibility == Visibility.Hidden)
  144. //{
  145. // this.Show();
  146. // this.WindowState = WindowState.Normal;
  147. //}
  148. //// According to some sources these steps gurantee that an app will be brought to foreground.
  149. //this.Activate();
  150. //this.Topmost = true;
  151. //this.Topmost = false;
  152. //this.Focus();
  153. }
  154. }
  155. }