星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ScreenRecordingToolbarWindow.xaml.cs 46KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209
  1. using Common.system;
  2. using System;
  3. using System.IO;
  4. using System.Threading;
  5. using System.Windows;
  6. using System.Windows.Forms;
  7. using System.Windows.Ink;
  8. using System.Windows.Media;
  9. using System.Windows.Media.Imaging;
  10. using System.Windows.Threading;
  11. using XHWK.Model;
  12. namespace XHWK.WKTool
  13. {
  14. /// <summary>
  15. /// 录屏工具栏
  16. /// </summary>
  17. public partial class ScreenRecordingToolbarWindow : Window
  18. {
  19. #region 初始变量
  20. /// <summary>
  21. /// 视频保存名称
  22. /// </summary>
  23. private string VideoSavePathName;
  24. /// <summary>
  25. /// 是否首次录屏
  26. /// </summary>
  27. private bool IsFirstRS = true;
  28. /// <summary>
  29. /// 是否暂停
  30. /// </summary>
  31. private bool IsSuspend = true;
  32. /// <summary>
  33. /// 视频信息
  34. /// </summary>
  35. private Model_Video VideoInfo = null;
  36. //声明一个 DrawingAttributes 类型的变量
  37. private DrawingAttributes drawingAttributes;
  38. private DispatcherTimer t = null;
  39. /// <summary>
  40. /// 计时器状态
  41. /// </summary>
  42. private enum State
  43. {
  44. Start,
  45. Pause,
  46. End
  47. }
  48. /// <summary>
  49. /// 状态
  50. /// </summary>
  51. private State _state = State.End;
  52. /// <summary>
  53. /// 计时用
  54. /// </summary>
  55. private TimeSpan _timeSpan = new TimeSpan(0, 0, 0, 0, 0);
  56. private KeyboardHookCommon k_hook;
  57. /// <summary>
  58. /// 🖊状态 0红色 1蓝色 10红色批注内 11蓝色批注内
  59. /// </summary>
  60. public int flg = 0;
  61. private System.Timers.Timer timer = new System.Timers.Timer();
  62. #endregion
  63. #region 初始化
  64. /// <summary>
  65. /// 录屏工具栏
  66. /// </summary>
  67. public ScreenRecordingToolbarWindow()
  68. {
  69. InitializeComponent();
  70. ResizeMode = ResizeMode.NoResize;
  71. }
  72. /// <summary>
  73. /// 初始化
  74. /// </summary>
  75. public void Initialize()
  76. {
  77. if (APP.W_PracticeWindow == null)
  78. {
  79. APP.W_PracticeWindow = new PracticeWindow
  80. {
  81. //APP.W_PracticeWindow.Topmost = true;
  82. Width = pwidth,
  83. Height = pHeight,
  84. Left = 0,
  85. Top = 0
  86. };
  87. //practiceWin.Owner = this;
  88. }
  89. APP.W_PracticeWindow.Show();
  90. new Thread(new ThreadStart(new Action(() =>
  91. {
  92. Thread.Sleep(100);
  93. Dispatcher.Invoke(() =>
  94. {
  95. Owner = APP.W_PracticeWindow;
  96. Topmost = true;
  97. });
  98. }))).Start();
  99. APP.W_PracticeWindow.Hide();
  100. //timer = new System.Timers.Timer(200);
  101. //timer.Interval = 300;
  102. //timer.Elapsed += new System.Timers.ElapsedEventHandler(TimerDealy);
  103. //timer.Enabled = true; //启动计时器
  104. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  105. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  106. flg = 0;
  107. k_hook = new KeyboardHookCommon();
  108. k_hook.KeyDownEvent += K_hook_KeyDownEvent;
  109. //创建 DrawingAttributes 类的一个实例
  110. drawingAttributes = new DrawingAttributes();
  111. //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  112. //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  113. blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  114. drawingAttributes.FitToCurve = true;
  115. //隐藏画笔工具栏
  116. //BtnToolbarDown_Click(null, null);
  117. gridToolbar.Visibility = Visibility.Hidden;
  118. gridColour.Visibility = Visibility.Hidden;
  119. gridThickness.Visibility = Visibility.Hidden;
  120. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar26.png"));//大圆圈三角形
  121. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
  122. BtnStopRecordingScreen.IsEnabled = false; //停止录制按钮不点击
  123. imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  124. btnBlackPenOne.IsEnabled = false;//蓝笔不可点击
  125. imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  126. btnBlackPenTwo.IsEnabled = false;//红笔不可点击
  127. //imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar29.png"));
  128. //btnReturn.IsEnabled = true;//返回主界面可点击
  129. txbTime.Visibility = Visibility.Hidden;//时间不显示
  130. BtnRecordingScreen.ToolTip = "开始";
  131. if (t == null)
  132. {
  133. t = new DispatcherTimer();
  134. t.Tick += OnTimer;
  135. t.Interval = new TimeSpan(0, 0, 0, 1);
  136. t.IsEnabled = true;
  137. t.Start();
  138. }
  139. t.Interval = new TimeSpan(0, 0, 0, 1);
  140. //Stack();
  141. //ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar25.png"));
  142. //BtnRecordingScreen_Click(null, null);
  143. }
  144. private void TimerDealy(object o, EventArgs e)
  145. {
  146. Dispatcher.Invoke(() =>
  147. {
  148. if (Left > 1630)
  149. {
  150. return;
  151. }
  152. //获取鼠标在屏幕上的位置
  153. double mouse_x = Form.MousePosition.X; //需要添加引用System.Drawing
  154. double mouse_y = Form.MousePosition.Y;
  155. bool is_in_collasped_range = (mouse_y > Left + Height) || (mouse_x < Left || mouse_x > Left + Width);//缩起的条件
  156. bool is_in_visiable_range = (mouse_y < 1 && mouse_x >= Left && mouse_x <= Left + Width); //展开的条件
  157. if (Left < 1630 && Left >= 0 && is_in_collasped_range)
  158. {
  159. System.Threading.Thread.Sleep(300);
  160. Left += 20 /*-this.ActualWidth - 3*/;
  161. }
  162. else if (Left < 0 && is_in_visiable_range)
  163. {
  164. Left = 1;
  165. }
  166. });
  167. }
  168. private void K_hook_KeyDownEvent(object sender, System.Windows.Forms.KeyEventArgs e)
  169. {
  170. if (e.KeyValue == (int)System.Windows.Forms.Keys.F5 && (int)Control.ModifierKeys == (int)Keys.Control)
  171. {
  172. //开始,暂停
  173. BtnRecordingScreen_Click(null, null);
  174. }
  175. if (e.KeyValue == (int)Keys.S && (int)Control.ModifierKeys == (int)Keys.Control)
  176. {
  177. //结束
  178. BtnStopRecordingScreen_Click(null, null);
  179. }
  180. }
  181. #endregion
  182. #region 事件
  183. /// <summary>
  184. /// 时钟回调
  185. /// </summary>
  186. /// <param name="sender"></param>
  187. /// <param name="e"></param>
  188. private void OnTimer(object sender, EventArgs e)
  189. {
  190. switch (_state)
  191. {
  192. case State.Start:
  193. {
  194. _timeSpan += new TimeSpan(0, 0, 0, 1);
  195. }
  196. break;
  197. case State.Pause:
  198. {
  199. }
  200. break;
  201. case State.End:
  202. {
  203. _timeSpan = new TimeSpan();
  204. //_timeSpan = new TimeSpan(0, 23, 12, 45, 54);
  205. }
  206. break;
  207. }
  208. string time = string.Format("{0:D2}:{1:D2}",/* _timeSpan.Hours,*/ _timeSpan.Minutes, _timeSpan.Seconds);
  209. //char[] times = time.ToCharArray();
  210. txbTime.Text = time;
  211. }
  212. /// <summary>
  213. /// 开始
  214. /// </summary>
  215. /// <param name="sender"></param>
  216. /// <param name="e"></param>
  217. private void Stack()
  218. {
  219. _state = State.Start;
  220. }
  221. /// <summary>
  222. /// 暂停
  223. /// </summary>
  224. private void TimeOut()
  225. {
  226. _state = State.Pause;
  227. }
  228. /// <summary>
  229. /// 结束
  230. /// </summary>
  231. /// <param name="sender"></param>
  232. /// <param name="e"></param>
  233. private void End()
  234. {
  235. _state = State.End;
  236. }
  237. #region 录屏
  238. /// <summary>
  239. /// 设置录屏文件地址
  240. /// </summary>
  241. private void SetUpVideoPathName()
  242. {
  243. //FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  244. FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  245. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temprs/");
  246. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
  247. int num = 1;
  248. while (FileToolsCommon.IsExistFile(VideoSavePathName))
  249. {
  250. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏_" + num + "." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
  251. num++;
  252. }
  253. }
  254. /// <summary>
  255. /// 是否已经按下按钮
  256. /// </summary>
  257. private bool IsPressButton = false;
  258. /// <summary>
  259. /// 开始或暂停录制
  260. /// </summary>
  261. /// <param name="sender"></param>
  262. /// <param name="e"></param>
  263. private void BtnRecordingScreen_Click(object sender, RoutedEventArgs e)
  264. {
  265. #region 防止连击
  266. if (IsPressButton)
  267. {
  268. return;
  269. }
  270. else
  271. {
  272. IsPressButton = true;
  273. new Thread(new ThreadStart(new Action(() =>
  274. {
  275. Thread.Sleep(500);
  276. IsPressButton = false;
  277. }))).Start();
  278. }
  279. #endregion
  280. if (IsSuspend)
  281. {
  282. if (IsFirstRS)
  283. {
  284. #region 检测麦克风扬声器是否可用
  285. string audioSpeakerPath = FileToolsCommon.GetFileAbsolutePath("adoS.m");
  286. string audioMicrophonePath = FileToolsCommon.GetFileAbsolutePath("adoM.m");
  287. try
  288. {
  289. FileToolsCommon.DeleteFile(audioSpeakerPath);
  290. FileToolsCommon.DeleteFile(audioMicrophonePath);
  291. }
  292. catch (Exception)
  293. {
  294. }
  295. //扬声器
  296. if (APP.FFmpeg.StartRecordSpeakerAudio(audioSpeakerPath))
  297. {
  298. APP.FFmpeg.StopRecordAudio(2);
  299. //Thread.Sleep(500);
  300. //麦克风
  301. if (APP.FFmpeg.StartRecordAudio(audioMicrophonePath))
  302. {
  303. }
  304. else
  305. {
  306. //无法录制麦克风
  307. MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制麦克风,是否继续?", "消息提示", MessageBoxButton.OKCancel);
  308. if (Res == MessageBoxResult.Cancel)
  309. {
  310. return;
  311. }
  312. }
  313. APP.FFmpeg.StopRecordAudio(1);
  314. }
  315. else
  316. {
  317. //无法录制扬声器音频
  318. MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制音频,是否继续?", "消息提示", MessageBoxButton.OKCancel);
  319. if (Res == MessageBoxResult.Cancel)
  320. {
  321. return;
  322. }
  323. }
  324. #endregion
  325. VideoInfo = new Model_Video
  326. {
  327. VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType")),
  328. WkType = Enum_WKVidetype.RecordingScreen
  329. };
  330. SetUpVideoPathName();
  331. k_hook.Start();//安装键盘钩子
  332. if (APP.W_CountdownWindow == null)
  333. {
  334. APP.W_CountdownWindow = new CountdownWindow();
  335. APP.W_CountdownWindow.Initialize(true, 1800);
  336. //APP.W_CountdownWindow.Topmost = true;
  337. }
  338. else
  339. {
  340. APP.W_CountdownWindow.Initialize(true, 1800);
  341. //APP.W_CountdownWindow.Topmost = true;
  342. }
  343. APP.W_CountdownWindow.Show();
  344. }
  345. IsSuspend = false;
  346. //#region 录像倒计时
  347. //if (APP.W_CountdownWindow == null)
  348. //{
  349. // APP.W_CountdownWindow = new CountdownWindow();
  350. // //APP.W_CountdownWindow.Topmost = true;
  351. //}
  352. //else
  353. //{
  354. // APP.W_CountdownWindow.Initialize();
  355. // //APP.W_CountdownWindow.Topmost = true;
  356. //}
  357. //APP.W_CountdownWindow.Show();
  358. //#endregion
  359. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar25.png"));//播放状态
  360. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar14.png"));
  361. BtnStopRecordingScreen.IsEnabled = true; //停止录制按钮可点击
  362. imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar27.png"));
  363. btnBlackPenOne.IsEnabled = true;//蓝笔可点击
  364. imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar28.png"));
  365. btnBlackPenTwo.IsEnabled = true;//红笔可点击
  366. txbTime.Visibility = Visibility.Visible;//时间显示
  367. //imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar30.png"));
  368. //borOne.Background = new SolidColorBrush(Colors.LightBlue);
  369. BtnRecordingScreen.ToolTip = "暂停";
  370. try
  371. {
  372. #region 4秒内不可点击
  373. new Thread(new ThreadStart(new Action(() =>
  374. {
  375. //Dispatcher.Invoke(() =>
  376. //{
  377. // ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
  378. // BtnRecordingScreen.IsEnabled = false;
  379. // BtnStopRecordingScreen.IsEnabled = false;
  380. //});
  381. //Thread.Sleep(4000);
  382. Dispatcher.Invoke(() =>
  383. {
  384. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar14.png"));
  385. BtnRecordingScreen.IsEnabled = true;
  386. BtnStopRecordingScreen.IsEnabled = true;
  387. });
  388. }))).Start();
  389. #endregion
  390. new Thread(new ThreadStart(new Action(() =>
  391. {
  392. if (IsFirstRS)
  393. {
  394. Thread.Sleep(800);
  395. }
  396. if (APP.FFmpeg.myProcess != null)
  397. {
  398. Thread.Sleep(100);
  399. }
  400. System.Drawing.Size DesktopSize = PrimaryScreen.DESKTOP;
  401. bool SynRes = APP.FFmpeg.StartRecordingVideo(VideoSavePathName, DesktopSize, out string ErrMessage);
  402. Thread.Sleep(1300);
  403. Dispatcher.Invoke(() =>
  404. {
  405. if (!SynRes)
  406. {
  407. MessageWindow.Show(ErrMessage);
  408. //隐藏画笔工具栏
  409. //BtnToolbarDown_Click(null, null);
  410. gridToolbar.Visibility = Visibility.Hidden;
  411. gridColour.Visibility = Visibility.Hidden;
  412. gridThickness.Visibility = Visibility.Hidden;
  413. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar26.png"));//大圆圈三角形
  414. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
  415. BtnStopRecordingScreen.IsEnabled = false; //停止录制按钮不点击
  416. imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  417. btnBlackPenOne.IsEnabled = false;//蓝笔不可点击
  418. imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  419. btnBlackPenTwo.IsEnabled = false;//红笔不可点击
  420. txbTime.Visibility = Visibility.Hidden;//时间不显示
  421. BtnRecordingScreen.ToolTip = "开始";
  422. IsSuspend = true;
  423. IsFirstRS = true;
  424. return;
  425. }
  426. Stack();
  427. });
  428. }))).Start();
  429. }
  430. catch (Exception ex)
  431. {
  432. MessageWindow.Show(ex.Message);
  433. }
  434. IsFirstRS = false;
  435. }
  436. else
  437. {
  438. TimeOut();
  439. IsSuspend = true;
  440. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar26.png"));//大圆圈三角形
  441. BtnStopRecordingScreen.IsEnabled = false; //停止录制按钮不点击
  442. BtnRecordingScreen.ToolTip = "开始";
  443. //imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  444. //btnBlackPenOne.IsEnabled = false;//蓝笔不可点击
  445. //imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  446. //btnBlackPenTwo.IsEnabled = false;//红笔不可点击
  447. txbTime.Visibility = Visibility.Hidden;//时间不显示
  448. //imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar29.png"));
  449. //btnReturn.IsEnabled = true;//返回主界面可点击
  450. #region 2秒内不可点击
  451. new Thread(new ThreadStart(new Action(() =>
  452. {
  453. //Dispatcher.Invoke(() =>
  454. //{
  455. // ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
  456. // BtnRecordingScreen.IsEnabled = false;
  457. // BtnStopRecordingScreen.IsEnabled = false;
  458. //});
  459. //Thread.Sleep(2000);
  460. Dispatcher.Invoke(() =>
  461. {
  462. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar14.png"));
  463. BtnRecordingScreen.IsEnabled = true;
  464. BtnStopRecordingScreen.IsEnabled = true;
  465. });
  466. }))).Start();
  467. #endregion
  468. try
  469. {
  470. APP.FFmpeg.SuspendFFmpeg();
  471. }
  472. catch (Exception ex)
  473. {
  474. MessageWindow.Show(ex.Message);
  475. }
  476. }
  477. }
  478. /// <summary>
  479. /// 停止录像
  480. /// </summary>
  481. /// <param name="sender"></param>
  482. /// <param name="e"></param>
  483. private void BtnStopRecordingScreen_Click(object sender, RoutedEventArgs e)
  484. {
  485. #region 防止连击
  486. if (IsPressButton)
  487. {
  488. return;
  489. }
  490. else
  491. {
  492. IsPressButton = true;
  493. new Thread(new ThreadStart(new Action(() =>
  494. {
  495. Thread.Sleep(500);
  496. IsPressButton = false;
  497. }))).Start();
  498. }
  499. #endregion
  500. k_hook.Stop();
  501. IsSuspend = true;
  502. txbTime.Text = "00:00";
  503. txbTime.Visibility = Visibility.Hidden;
  504. End();
  505. if (APP.W_PracticeWindow != null)
  506. {
  507. if (APP.W_PracticeWindow.Visibility == Visibility.Visible)
  508. {
  509. Owner = null;
  510. APP.W_PracticeWindow.ReturnPractice();
  511. }
  512. }
  513. if (gridToolbar.Visibility == Visibility.Visible)
  514. {
  515. gridToolbar.Visibility = Visibility.Hidden;
  516. gridColour.Visibility = Visibility.Hidden;
  517. gridThickness.Visibility = Visibility.Hidden;
  518. }
  519. if (APP.W_XHMicroLessonSystemWindow == null)
  520. {
  521. APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
  522. }
  523. APP.W_XHMicroLessonSystemWindow.InitializeKeyDownEvent();
  524. APP.W_XHMicroLessonSystemWindow.Show();
  525. if (!IsFirstRS)
  526. {
  527. try
  528. {
  529. if (_timeSpan.Minutes > 0 || _timeSpan.Seconds > 3)
  530. {
  531. try
  532. {
  533. APP.FFmpeg.StopFFmpeg(VideoSavePathName);
  534. }
  535. catch (Exception ex)
  536. {
  537. LogHelper.WriteErrLog("【停止录屏】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  538. }
  539. IsFirstRS = true;
  540. //生成缩略图
  541. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  542. FileToolsCommon.CreateDirectory(ThumbnailPath);
  543. //缩略图存储位置
  544. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileName(VideoSavePathName).Replace(".", "") + ".JPG";
  545. new Thread(new ThreadStart(new Action(() =>
  546. {
  547. while (!FileToolsCommon.IsExistFile(VideoSavePathName))
  548. {
  549. Thread.Sleep(100);
  550. }
  551. FileToolsCommon.DeleteFile(ThumbnailPathName);
  552. //VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  553. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  554. VideoInfo.VideoPath = VideoSavePathName;
  555. VideoInfo.ThumbnailPath = ThumbnailPathName;
  556. APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName, 200, 130);
  557. VideoInfo.FileGuid = Guid.NewGuid().ToString();
  558. VideoInfo.IsUpload = false;
  559. VideoInfo.Uploaded = 0;
  560. VideoInfo.Savefolder = APP.UserInfo.Schoolid + "/resource";
  561. APP.VideoList.Add(VideoInfo);
  562. //保存数据
  563. APP.SaveWkData();
  564. }))).Start();
  565. Click_stopRecordingScreen();
  566. }
  567. else
  568. {
  569. //视频过短
  570. APP.FFmpeg.SuspendFFmpeg();
  571. IsFirstRS = true;
  572. MessageWindow.Show("录屏时间过短,请重新录制!");
  573. }
  574. }
  575. catch (Exception ex)
  576. {
  577. LogHelper.WriteErrLog("【停止录屏】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  578. }
  579. }
  580. Hide();
  581. }
  582. #endregion
  583. #region 画笔相关
  584. /// <summary>
  585. /// 画笔工具栏关闭事件
  586. /// </summary>
  587. /// <param name="sender"></param>
  588. /// <param name="e"></param>
  589. private void BtnToolbarDown_Click(object sender, RoutedEventArgs e)
  590. {
  591. gridToolbar.Visibility = Visibility.Hidden;
  592. gridColour.Visibility = Visibility.Hidden;
  593. gridThickness.Visibility = Visibility.Hidden;
  594. APP.W_PracticeWindow.Hide();
  595. }
  596. /// <summary>
  597. /// 画笔点击事件
  598. /// </summary>
  599. /// <param name="sender"></param>
  600. /// <param name="e"></param>
  601. private void BtnBrush_Click(object sender, RoutedEventArgs e)
  602. {
  603. #region 防止连击
  604. if (IsPressButton)
  605. {
  606. return;
  607. }
  608. else
  609. {
  610. IsPressButton = true;
  611. new Thread(new ThreadStart(new Action(() =>
  612. {
  613. Thread.Sleep(500);
  614. IsPressButton = false;
  615. }))).Start();
  616. }
  617. #endregion
  618. string time = GetTimeStamp();
  619. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  620. if (!Directory.Exists(tempPath))
  621. {
  622. Directory.CreateDirectory(tempPath);
  623. }
  624. #region 录屏批注取消画笔
  625. //string imagePath = Path.Combine(tempPath, time + ".jpg");
  626. //ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  627. #endregion
  628. try
  629. {
  630. if (flg == 11)
  631. {
  632. Dispatcher.Invoke(() =>
  633. {
  634. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  635. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  636. });
  637. flg = 1;
  638. //this.Owner = null;
  639. APP.W_PracticeWindow.ReturnPractice();
  640. }
  641. else if (flg == 10)
  642. {
  643. Dispatcher.Invoke(() =>
  644. {
  645. borOne.Background = new SolidColorBrush(Colors.LightSkyBlue);
  646. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  647. });
  648. APP.W_PracticeWindow.Blue();
  649. flg = 11;
  650. }
  651. else
  652. {
  653. //new Thread(new ThreadStart(new Action(() =>
  654. //{
  655. Dispatcher.Invoke(() =>
  656. {
  657. borOne.Background = new SolidColorBrush(Colors.LightSkyBlue);
  658. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  659. });
  660. //}))).Start();
  661. if (APP.W_PracticeWindow == null)
  662. {
  663. APP.W_PracticeWindow = new PracticeWindow
  664. {
  665. //APP.W_PracticeWindow.Topmost = true;
  666. Width = pwidth,
  667. Height = pHeight,
  668. Left = 0,
  669. Top = 0
  670. };
  671. //practiceWin.Owner = this;
  672. }
  673. APP.W_PracticeWindow.Initialize();// imagePath);
  674. flg = 11;
  675. APP.W_PracticeWindow.Blue();
  676. APP.W_PracticeWindow.Show();
  677. new Thread(new ThreadStart(new Action(() =>
  678. {
  679. Thread.Sleep(100);
  680. Dispatcher.Invoke(() =>
  681. {
  682. Owner = APP.W_PracticeWindow;
  683. Topmost = true;
  684. });
  685. }))).Start();
  686. }
  687. }
  688. catch (Exception ex)
  689. {
  690. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  691. }
  692. //imgCanvas.Source = new BitmapImage(new Uri(imagePath));
  693. }
  694. /// <summary>
  695. /// 屏幕宽
  696. /// </summary>
  697. internal double pwidth = SystemParameters.PrimaryScreenWidth;
  698. /// <summary>
  699. /// 屏幕高
  700. /// </summary>
  701. internal double pHeight = SystemParameters.PrimaryScreenHeight;
  702. /// <summary>
  703. /// 获取时间戳
  704. /// </summary>
  705. /// <returns></returns>
  706. public string GetTimeStamp()
  707. {
  708. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  709. return Convert.ToInt64(ts.TotalMilliseconds).ToString();
  710. }
  711. /// <summary>
  712. /// 画笔粗细事件
  713. /// </summary>
  714. /// <param name="sender"></param>
  715. /// <param name="e"></param>
  716. private void BtnThickness_Click(object sender, RoutedEventArgs e)
  717. {
  718. gridThickness.Visibility = Visibility.Visible;
  719. gridColour.Visibility = Visibility.Collapsed;
  720. }
  721. /// <summary>
  722. /// 画笔颜色事件
  723. /// </summary>
  724. /// <param name="sender"></param>
  725. /// <param name="e"></param>
  726. private void BtnColour_Click(object sender, RoutedEventArgs e)
  727. {
  728. gridColour.Visibility = Visibility.Visible;
  729. gridThickness.Visibility = Visibility.Collapsed;
  730. }
  731. /// <summary>
  732. /// 白色
  733. /// </summary>
  734. /// <param name="sender"></param>
  735. /// <param name="e"></param>
  736. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  737. {
  738. //drawingAttributes.Color = Colors.White;
  739. APP.W_PracticeWindow.White();
  740. gridColour.Visibility = Visibility.Collapsed;
  741. gridThickness.Visibility = Visibility.Collapsed;
  742. }
  743. /// <summary>
  744. /// 红色
  745. /// </summary>
  746. /// <param name="sender"></param>
  747. /// <param name="e"></param>
  748. private void BtnRed_Click(object sender, RoutedEventArgs e)
  749. {
  750. //drawingAttributes.Color = Colors.Red;
  751. APP.W_PracticeWindow.Red();
  752. gridColour.Visibility = Visibility.Collapsed;
  753. gridThickness.Visibility = Visibility.Collapsed;
  754. }
  755. /// <summary>
  756. /// 黄色
  757. /// </summary>
  758. /// <param name="sender"></param>
  759. /// <param name="e"></param>
  760. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  761. {
  762. //drawingAttributes.Color = Colors.Gold;
  763. APP.W_PracticeWindow.Yellow();
  764. gridColour.Visibility = Visibility.Collapsed;
  765. gridThickness.Visibility = Visibility.Collapsed;
  766. }
  767. /// <summary>
  768. /// 青色
  769. /// </summary>
  770. /// <param name="sender"></param>
  771. /// <param name="e"></param>
  772. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  773. {
  774. //drawingAttributes.Color = Colors.LimeGreen;
  775. APP.W_PracticeWindow.CyanBlue();
  776. gridColour.Visibility = Visibility.Collapsed;
  777. gridThickness.Visibility = Visibility.Collapsed;
  778. }
  779. /// <summary>
  780. /// 灰色
  781. /// </summary>
  782. /// <param name="sender"></param>
  783. /// <param name="e"></param>
  784. private void BtnGray_Click(object sender, RoutedEventArgs e)
  785. {
  786. //drawingAttributes.Color = Colors.Gray;
  787. APP.W_PracticeWindow.Gray();
  788. gridColour.Visibility = Visibility.Collapsed;
  789. gridThickness.Visibility = Visibility.Collapsed;
  790. }
  791. /// <summary>
  792. /// 蓝色
  793. /// </summary>
  794. /// <param name="sender"></param>
  795. /// <param name="e"></param>
  796. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  797. {
  798. //drawingAttributes.Color = Colors.DeepSkyBlue;
  799. APP.W_PracticeWindow.Blue();
  800. gridColour.Visibility = Visibility.Collapsed;
  801. gridThickness.Visibility = Visibility.Collapsed;
  802. }
  803. /// <summary>
  804. /// 画笔 细
  805. /// </summary>
  806. /// <param name="sender"></param>
  807. /// <param name="e"></param>
  808. private void BtnFine_Click(object sender, RoutedEventArgs e)
  809. {
  810. APP.W_PracticeWindow.Fine();
  811. gridColour.Visibility = Visibility.Collapsed;
  812. gridThickness.Visibility = Visibility.Collapsed;
  813. }
  814. /// <summary>
  815. /// 画笔 中
  816. /// </summary>
  817. /// <param name="sender"></param>
  818. /// <param name="e"></param>
  819. private void BtnIn_Click(object sender, RoutedEventArgs e)
  820. {
  821. APP.W_PracticeWindow.In();
  822. gridColour.Visibility = Visibility.Collapsed;
  823. gridThickness.Visibility = Visibility.Collapsed;
  824. }
  825. /// <summary>
  826. /// 画笔粗
  827. /// </summary>
  828. /// <param name="sender"></param>
  829. /// <param name="e"></param>
  830. private void BtnCrude_Click(object sender, RoutedEventArgs e)
  831. {
  832. APP.W_PracticeWindow.Crude();
  833. gridColour.Visibility = Visibility.Collapsed;
  834. gridThickness.Visibility = Visibility.Collapsed;
  835. }
  836. /// <summary>
  837. /// 橡皮
  838. /// </summary>
  839. /// <param name="sender"></param>
  840. /// <param name="e"></param>
  841. private void BtnEraser_Click(object sender, RoutedEventArgs e)
  842. {
  843. APP.W_PracticeWindow.Eraser();
  844. }
  845. /// <summary>
  846. /// 🖊
  847. /// </summary>
  848. /// <param name="sender"></param>
  849. /// <param name="e"></param>
  850. private void BtnPen_Click(object sender, RoutedEventArgs e)
  851. {
  852. APP.W_PracticeWindow.Pen();
  853. }
  854. /// <summary>
  855. /// ⚪
  856. /// </summary>
  857. /// <param name="sender"></param>
  858. /// <param name="e"></param>
  859. private void BtnRound_Click(object sender, RoutedEventArgs e)
  860. {
  861. APP.W_PracticeWindow.Round();
  862. }
  863. /// <summary>
  864. /// 矩形
  865. /// </summary>
  866. /// <param name="sender"></param>
  867. /// <param name="e"></param>
  868. private void BtnRectangle_Click(object sender, RoutedEventArgs e)
  869. {
  870. APP.W_PracticeWindow.Rectangle();
  871. }
  872. #endregion
  873. #endregion
  874. /// <summary>
  875. /// 停止录屏
  876. /// </summary>
  877. public delegate void StopRecordingScreen();
  878. /// <summary>
  879. /// 停止录屏
  880. /// </summary>
  881. public event StopRecordingScreen Click_stopRecordingScreen;
  882. /// <summary>
  883. /// 黑笔
  884. /// </summary>
  885. /// <param name="sender"></param>
  886. /// <param name="e"></param>
  887. private void BtnBlackPen_Click(object sender, RoutedEventArgs e)
  888. {
  889. }
  890. /// <summary>
  891. /// 移动工具栏
  892. /// </summary>
  893. /// <param name="sender"></param>
  894. /// <param name="e"></param>
  895. private void Grid_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  896. {
  897. DragMove();
  898. }
  899. /// <summary>
  900. /// 红笔
  901. /// </summary>
  902. /// <param name="sender"></param>
  903. /// <param name="e"></param>
  904. private void BtnBlackPenTwo_Click(object sender, RoutedEventArgs e)
  905. {
  906. #region 防止连击
  907. if (IsPressButton)
  908. {
  909. return;
  910. }
  911. else
  912. {
  913. IsPressButton = true;
  914. new Thread(new ThreadStart(new Action(() =>
  915. {
  916. Thread.Sleep(500);
  917. IsPressButton = false;
  918. }))).Start();
  919. }
  920. #endregion
  921. string time = GetTimeStamp();
  922. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  923. if (!Directory.Exists(tempPath))
  924. {
  925. Directory.CreateDirectory(tempPath);
  926. }
  927. #region 录屏批注取消画笔
  928. string imagePath = Path.Combine(tempPath, time + ".jpg");
  929. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  930. #endregion
  931. try
  932. {
  933. if (flg == 10)
  934. {
  935. Dispatcher.Invoke(() =>
  936. {
  937. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  938. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  939. });
  940. flg = 0;
  941. //this.Owner = null;
  942. APP.W_PracticeWindow.ReturnPractice();
  943. }
  944. else if (flg == 11)
  945. {
  946. Dispatcher.Invoke(() =>
  947. {
  948. borTwo.Background = new SolidColorBrush(Colors.LightSkyBlue);
  949. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  950. });
  951. flg = 10;
  952. APP.W_PracticeWindow.Red();
  953. }
  954. else
  955. {
  956. Dispatcher.Invoke(() =>
  957. {
  958. borTwo.Background = new SolidColorBrush(Colors.LightSkyBlue);
  959. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  960. });
  961. if (APP.W_PracticeWindow == null)
  962. {
  963. APP.W_PracticeWindow = new PracticeWindow
  964. {
  965. //APP.W_PracticeWindow.Topmost = true;
  966. Width = pwidth,
  967. Height = pHeight,
  968. Left = 0,
  969. Top = 0
  970. };
  971. //practiceWin.Owner = this;
  972. }
  973. APP.W_PracticeWindow.Initialize();//imagePath);
  974. flg = 10;
  975. APP.W_PracticeWindow.Red();
  976. APP.W_PracticeWindow.Show();
  977. new Thread(new ThreadStart(new Action(() =>
  978. {
  979. Thread.Sleep(100);
  980. Dispatcher.Invoke(() =>
  981. {
  982. Owner = APP.W_PracticeWindow;
  983. Topmost = true;
  984. });
  985. }))).Start();
  986. }
  987. }
  988. catch (Exception ex)
  989. {
  990. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  991. }
  992. }
  993. /// <summary>
  994. /// 鼠标右键按下事件 废弃
  995. /// </summary>
  996. /// <param name="sender"></param>
  997. /// <param name="e"></param>
  998. private void RightButtonDown()
  999. {
  1000. if (flg > 9)
  1001. {
  1002. Owner = null;
  1003. APP.W_PracticeWindow.Hide();
  1004. }
  1005. else
  1006. {
  1007. //string time = GetTimeStamp();
  1008. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  1009. if (!Directory.Exists(tempPath))
  1010. {
  1011. Directory.CreateDirectory(tempPath);
  1012. }
  1013. #region 录屏批注取消画笔
  1014. //string imagePath = Path.Combine(tempPath, time + ".jpg");
  1015. //ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  1016. #endregion
  1017. try
  1018. {
  1019. if (APP.W_PracticeWindow == null)
  1020. {
  1021. APP.W_PracticeWindow = new PracticeWindow
  1022. {
  1023. //APP.W_PracticeWindow.Topmost = true;
  1024. Width = pwidth,
  1025. Height = pHeight,
  1026. Left = 0,
  1027. Top = 0
  1028. };
  1029. //practiceWin.Owner = this;
  1030. }
  1031. APP.W_PracticeWindow.Initialize();//imagePath);
  1032. if (flg == 0)
  1033. {
  1034. flg = 10;
  1035. APP.W_PracticeWindow.Red();
  1036. }
  1037. else
  1038. {
  1039. flg = 11;
  1040. APP.W_PracticeWindow.Blue();
  1041. }
  1042. APP.W_PracticeWindow.Show();
  1043. }
  1044. catch (Exception ex)
  1045. {
  1046. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  1047. }
  1048. }
  1049. }
  1050. /// <summary>
  1051. /// 返回主界面
  1052. /// </summary>
  1053. /// <param name="sender"></param>
  1054. /// <param name="e"></param>
  1055. private void BtnReturn_Click(object sender, RoutedEventArgs e)
  1056. {
  1057. if (!IsFirstRS)
  1058. {
  1059. MessageBoxResult br = MessageWindow.Show("退出将取消保存当前录屏,是否继续?", "提示", MessageBoxButton.OKCancel);
  1060. if (br == MessageBoxResult.Cancel)
  1061. {
  1062. return;
  1063. }
  1064. k_hook.Stop();
  1065. IsSuspend = true;
  1066. txbTime.Text = "00:00";
  1067. txbTime.Visibility = Visibility.Hidden;
  1068. End();
  1069. APP.W_PracticeWindow.ReturnPractice();
  1070. if (APP.W_PracticeWindow != null)
  1071. {
  1072. if (APP.W_PracticeWindow.Visibility == Visibility.Visible)
  1073. {
  1074. APP.W_PracticeWindow.Hide();
  1075. }
  1076. }
  1077. if (gridToolbar.Visibility == Visibility.Visible)
  1078. {
  1079. gridToolbar.Visibility = Visibility.Hidden;
  1080. gridColour.Visibility = Visibility.Hidden;
  1081. gridThickness.Visibility = Visibility.Hidden;
  1082. }
  1083. if (APP.W_XHMicroLessonSystemWindow == null)
  1084. {
  1085. APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
  1086. }
  1087. try
  1088. {
  1089. try
  1090. {
  1091. APP.FFmpeg.SuspendFFmpeg();
  1092. }
  1093. catch (Exception ex)
  1094. {
  1095. LogHelper.WriteErrLog("【录屏返回】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  1096. }
  1097. IsFirstRS = true;
  1098. new Thread(new ThreadStart(new Action(() =>
  1099. {
  1100. VideoInfo = null;
  1101. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temprs/");
  1102. }))).Start();
  1103. }
  1104. catch (Exception ex)
  1105. {
  1106. LogHelper.WriteErrLog("【录屏返回】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  1107. }
  1108. }
  1109. APP.W_XHMicroLessonSystemWindow.InitializeKeyDownEvent();
  1110. APP.W_XHMicroLessonSystemWindow.Show();
  1111. Hide();
  1112. }
  1113. /// <summary>
  1114. /// 批注退出 废弃
  1115. /// </summary>
  1116. public void ReturnPractice()
  1117. {
  1118. new Thread(new ThreadStart(new Action(() =>
  1119. {
  1120. Dispatcher.Invoke(() =>
  1121. {
  1122. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  1123. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  1124. });
  1125. flg = 0;
  1126. Thread.Sleep(500);
  1127. Dispatcher.Invoke(() =>
  1128. {
  1129. Owner = null;
  1130. APP.W_PracticeWindow.Hide();
  1131. });
  1132. }))).Start();
  1133. //Dispatcher.Invoke(() =>
  1134. //{
  1135. // borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  1136. // borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  1137. //});
  1138. //flg = 0;
  1139. //Thread.Sleep(300);
  1140. //APP.W_PracticeWindow.Hide();
  1141. }
  1142. /// <summary>
  1143. /// 修改笔状态
  1144. /// </summary>
  1145. public void ModifyState()
  1146. {
  1147. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  1148. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  1149. }
  1150. /// <summary>
  1151. /// 切换页面
  1152. /// </summary>
  1153. void SwitchPages()
  1154. {
  1155. //SendKeys.SendWait("%{TAB}");
  1156. MouseEventCommon.MouseMiddleClickEvent(0);
  1157. }
  1158. }
  1159. }