星火微课系统客户端
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 45KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  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. bool SynRes = APP.FFmpeg.StartRecordingVideo(VideoSavePathName, out string ErrMessage);
  401. Thread.Sleep(1300);
  402. Dispatcher.Invoke(() =>
  403. {
  404. if (!SynRes)
  405. {
  406. MessageWindow.Show(ErrMessage);
  407. //隐藏画笔工具栏
  408. //BtnToolbarDown_Click(null, null);
  409. gridToolbar.Visibility = Visibility.Hidden;
  410. gridColour.Visibility = Visibility.Hidden;
  411. gridThickness.Visibility = Visibility.Hidden;
  412. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar26.png"));//大圆圈三角形
  413. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
  414. BtnStopRecordingScreen.IsEnabled = false; //停止录制按钮不点击
  415. imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  416. btnBlackPenOne.IsEnabled = false;//蓝笔不可点击
  417. imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  418. btnBlackPenTwo.IsEnabled = false;//红笔不可点击
  419. txbTime.Visibility = Visibility.Hidden;//时间不显示
  420. BtnRecordingScreen.ToolTip = "开始";
  421. IsSuspend = true;
  422. IsFirstRS = true;
  423. return;
  424. }
  425. Stack();
  426. });
  427. }))).Start();
  428. }
  429. catch (Exception ex)
  430. {
  431. MessageWindow.Show(ex.Message);
  432. }
  433. IsFirstRS = false;
  434. }
  435. else
  436. {
  437. TimeOut();
  438. IsSuspend = true;
  439. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar26.png"));//大圆圈三角形
  440. BtnStopRecordingScreen.IsEnabled = false; //停止录制按钮不点击
  441. BtnRecordingScreen.ToolTip = "开始";
  442. //imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  443. //btnBlackPenOne.IsEnabled = false;//蓝笔不可点击
  444. //imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  445. //btnBlackPenTwo.IsEnabled = false;//红笔不可点击
  446. txbTime.Visibility = Visibility.Hidden;//时间不显示
  447. //imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar29.png"));
  448. //btnReturn.IsEnabled = true;//返回主界面可点击
  449. #region 2秒内不可点击
  450. new Thread(new ThreadStart(new Action(() =>
  451. {
  452. //Dispatcher.Invoke(() =>
  453. //{
  454. // ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
  455. // BtnRecordingScreen.IsEnabled = false;
  456. // BtnStopRecordingScreen.IsEnabled = false;
  457. //});
  458. //Thread.Sleep(2000);
  459. Dispatcher.Invoke(() =>
  460. {
  461. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar14.png"));
  462. BtnRecordingScreen.IsEnabled = true;
  463. BtnStopRecordingScreen.IsEnabled = true;
  464. });
  465. }))).Start();
  466. #endregion
  467. try
  468. {
  469. APP.FFmpeg.SuspendFFmpeg();
  470. }
  471. catch (Exception ex)
  472. {
  473. MessageWindow.Show(ex.Message);
  474. }
  475. }
  476. }
  477. /// <summary>
  478. /// 停止录像
  479. /// </summary>
  480. /// <param name="sender"></param>
  481. /// <param name="e"></param>
  482. private void BtnStopRecordingScreen_Click(object sender, RoutedEventArgs e)
  483. {
  484. #region 防止连击
  485. if (IsPressButton)
  486. {
  487. return;
  488. }
  489. else
  490. {
  491. IsPressButton = true;
  492. new Thread(new ThreadStart(new Action(() =>
  493. {
  494. Thread.Sleep(500);
  495. IsPressButton = false;
  496. }))).Start();
  497. }
  498. #endregion
  499. k_hook.Stop();
  500. IsSuspend = true;
  501. txbTime.Text = "00:00";
  502. txbTime.Visibility = Visibility.Hidden;
  503. End();
  504. if (APP.W_PracticeWindow != null)
  505. {
  506. if (APP.W_PracticeWindow.Visibility == Visibility.Visible)
  507. {
  508. Owner = null;
  509. APP.W_PracticeWindow.ReturnPractice();
  510. }
  511. }
  512. if (gridToolbar.Visibility == Visibility.Visible)
  513. {
  514. gridToolbar.Visibility = Visibility.Hidden;
  515. gridColour.Visibility = Visibility.Hidden;
  516. gridThickness.Visibility = Visibility.Hidden;
  517. }
  518. if (APP.W_XHMicroLessonSystemWindow == null)
  519. {
  520. APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
  521. }
  522. APP.W_XHMicroLessonSystemWindow.InitializeKeyDownEvent();
  523. APP.W_XHMicroLessonSystemWindow.Show();
  524. if (!IsFirstRS)
  525. {
  526. try
  527. {
  528. if (_timeSpan.Minutes > 0 || _timeSpan.Seconds > 3)
  529. {
  530. try
  531. {
  532. APP.FFmpeg.StopFFmpeg(VideoSavePathName);
  533. }
  534. catch (Exception ex)
  535. {
  536. LogHelper.WriteErrLog("【停止录屏】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  537. }
  538. IsFirstRS = true;
  539. //生成缩略图
  540. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  541. FileToolsCommon.CreateDirectory(ThumbnailPath);
  542. //缩略图存储位置
  543. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileName(VideoSavePathName).Replace(".", "") + ".JPG";
  544. new Thread(new ThreadStart(new Action(() =>
  545. {
  546. while (!FileToolsCommon.IsExistFile(VideoSavePathName))
  547. {
  548. Thread.Sleep(100);
  549. }
  550. FileToolsCommon.DeleteFile(ThumbnailPathName);
  551. //VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  552. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  553. VideoInfo.VideoPath = VideoSavePathName;
  554. VideoInfo.ThumbnailPath = ThumbnailPathName;
  555. APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName, 200, 130);
  556. VideoInfo.FileGuid = Guid.NewGuid().ToString();
  557. VideoInfo.IsUpload = false;
  558. VideoInfo.Uploaded = 0;
  559. VideoInfo.Savefolder = APP.UserInfo.Schoolid + "/resource";
  560. APP.VideoList.Add(VideoInfo);
  561. //保存数据
  562. APP.SaveWkData();
  563. }))).Start();
  564. Click_stopRecordingScreen();
  565. }
  566. else
  567. {
  568. //视频过短
  569. APP.FFmpeg.SuspendFFmpeg();
  570. IsFirstRS = true;
  571. MessageWindow.Show("保存失败,录屏时间过短!");
  572. }
  573. }
  574. catch (Exception ex)
  575. {
  576. LogHelper.WriteErrLog("【停止录屏】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  577. }
  578. }
  579. Hide();
  580. }
  581. #endregion
  582. #region 画笔相关
  583. /// <summary>
  584. /// 画笔工具栏关闭事件
  585. /// </summary>
  586. /// <param name="sender"></param>
  587. /// <param name="e"></param>
  588. private void BtnToolbarDown_Click(object sender, RoutedEventArgs e)
  589. {
  590. gridToolbar.Visibility = Visibility.Hidden;
  591. gridColour.Visibility = Visibility.Hidden;
  592. gridThickness.Visibility = Visibility.Hidden;
  593. APP.W_PracticeWindow.Hide();
  594. }
  595. /// <summary>
  596. /// 画笔点击事件
  597. /// </summary>
  598. /// <param name="sender"></param>
  599. /// <param name="e"></param>
  600. private void BtnBrush_Click(object sender, RoutedEventArgs e)
  601. {
  602. #region 防止连击
  603. if (IsPressButton)
  604. {
  605. return;
  606. }
  607. else
  608. {
  609. IsPressButton = true;
  610. new Thread(new ThreadStart(new Action(() =>
  611. {
  612. Thread.Sleep(500);
  613. IsPressButton = false;
  614. }))).Start();
  615. }
  616. #endregion
  617. string time = GetTimeStamp();
  618. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  619. if (!Directory.Exists(tempPath))
  620. {
  621. Directory.CreateDirectory(tempPath);
  622. }
  623. #region 录屏批注取消画笔
  624. //string imagePath = Path.Combine(tempPath, time + ".jpg");
  625. //ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  626. #endregion
  627. try
  628. {
  629. if (flg == 11)
  630. {
  631. Dispatcher.Invoke(() =>
  632. {
  633. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  634. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  635. });
  636. flg = 1;
  637. //this.Owner = null;
  638. APP.W_PracticeWindow.ReturnPractice();
  639. }
  640. else if (flg == 10)
  641. {
  642. Dispatcher.Invoke(() =>
  643. {
  644. borOne.Background = new SolidColorBrush(Colors.LightSkyBlue);
  645. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  646. });
  647. APP.W_PracticeWindow.Blue();
  648. flg = 11;
  649. }
  650. else
  651. {
  652. //new Thread(new ThreadStart(new Action(() =>
  653. //{
  654. Dispatcher.Invoke(() =>
  655. {
  656. borOne.Background = new SolidColorBrush(Colors.LightSkyBlue);
  657. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  658. });
  659. //}))).Start();
  660. if (APP.W_PracticeWindow == null)
  661. {
  662. APP.W_PracticeWindow = new PracticeWindow
  663. {
  664. //APP.W_PracticeWindow.Topmost = true;
  665. Width = pwidth,
  666. Height = pHeight,
  667. Left = 0,
  668. Top = 0
  669. };
  670. //practiceWin.Owner = this;
  671. }
  672. APP.W_PracticeWindow.Initialize();// imagePath);
  673. flg = 11;
  674. APP.W_PracticeWindow.Blue();
  675. APP.W_PracticeWindow.Show();
  676. new Thread(new ThreadStart(new Action(() =>
  677. {
  678. Thread.Sleep(100);
  679. Dispatcher.Invoke(() =>
  680. {
  681. Owner = APP.W_PracticeWindow;
  682. Topmost = true;
  683. });
  684. }))).Start();
  685. }
  686. }
  687. catch (Exception ex)
  688. {
  689. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  690. }
  691. //imgCanvas.Source = new BitmapImage(new Uri(imagePath));
  692. }
  693. /// <summary>
  694. /// 屏幕宽
  695. /// </summary>
  696. internal double pwidth = SystemParameters.PrimaryScreenWidth;
  697. /// <summary>
  698. /// 屏幕高
  699. /// </summary>
  700. internal double pHeight = SystemParameters.PrimaryScreenHeight;
  701. /// <summary>
  702. /// 获取时间戳
  703. /// </summary>
  704. /// <returns></returns>
  705. public string GetTimeStamp()
  706. {
  707. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  708. return Convert.ToInt64(ts.TotalMilliseconds).ToString();
  709. }
  710. /// <summary>
  711. /// 画笔粗细事件
  712. /// </summary>
  713. /// <param name="sender"></param>
  714. /// <param name="e"></param>
  715. private void BtnThickness_Click(object sender, RoutedEventArgs e)
  716. {
  717. gridThickness.Visibility = Visibility.Visible;
  718. gridColour.Visibility = Visibility.Collapsed;
  719. }
  720. /// <summary>
  721. /// 画笔颜色事件
  722. /// </summary>
  723. /// <param name="sender"></param>
  724. /// <param name="e"></param>
  725. private void BtnColour_Click(object sender, RoutedEventArgs e)
  726. {
  727. gridColour.Visibility = Visibility.Visible;
  728. gridThickness.Visibility = Visibility.Collapsed;
  729. }
  730. /// <summary>
  731. /// 白色
  732. /// </summary>
  733. /// <param name="sender"></param>
  734. /// <param name="e"></param>
  735. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  736. {
  737. //drawingAttributes.Color = Colors.White;
  738. APP.W_PracticeWindow.White();
  739. gridColour.Visibility = Visibility.Collapsed;
  740. gridThickness.Visibility = Visibility.Collapsed;
  741. }
  742. /// <summary>
  743. /// 红色
  744. /// </summary>
  745. /// <param name="sender"></param>
  746. /// <param name="e"></param>
  747. private void BtnRed_Click(object sender, RoutedEventArgs e)
  748. {
  749. //drawingAttributes.Color = Colors.Red;
  750. APP.W_PracticeWindow.Red();
  751. gridColour.Visibility = Visibility.Collapsed;
  752. gridThickness.Visibility = Visibility.Collapsed;
  753. }
  754. /// <summary>
  755. /// 黄色
  756. /// </summary>
  757. /// <param name="sender"></param>
  758. /// <param name="e"></param>
  759. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  760. {
  761. //drawingAttributes.Color = Colors.Gold;
  762. APP.W_PracticeWindow.Yellow();
  763. gridColour.Visibility = Visibility.Collapsed;
  764. gridThickness.Visibility = Visibility.Collapsed;
  765. }
  766. /// <summary>
  767. /// 青色
  768. /// </summary>
  769. /// <param name="sender"></param>
  770. /// <param name="e"></param>
  771. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  772. {
  773. //drawingAttributes.Color = Colors.LimeGreen;
  774. APP.W_PracticeWindow.CyanBlue();
  775. gridColour.Visibility = Visibility.Collapsed;
  776. gridThickness.Visibility = Visibility.Collapsed;
  777. }
  778. /// <summary>
  779. /// 灰色
  780. /// </summary>
  781. /// <param name="sender"></param>
  782. /// <param name="e"></param>
  783. private void BtnGray_Click(object sender, RoutedEventArgs e)
  784. {
  785. //drawingAttributes.Color = Colors.Gray;
  786. APP.W_PracticeWindow.Gray();
  787. gridColour.Visibility = Visibility.Collapsed;
  788. gridThickness.Visibility = Visibility.Collapsed;
  789. }
  790. /// <summary>
  791. /// 蓝色
  792. /// </summary>
  793. /// <param name="sender"></param>
  794. /// <param name="e"></param>
  795. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  796. {
  797. //drawingAttributes.Color = Colors.DeepSkyBlue;
  798. APP.W_PracticeWindow.Blue();
  799. gridColour.Visibility = Visibility.Collapsed;
  800. gridThickness.Visibility = Visibility.Collapsed;
  801. }
  802. /// <summary>
  803. /// 画笔 细
  804. /// </summary>
  805. /// <param name="sender"></param>
  806. /// <param name="e"></param>
  807. private void BtnFine_Click(object sender, RoutedEventArgs e)
  808. {
  809. APP.W_PracticeWindow.Fine();
  810. gridColour.Visibility = Visibility.Collapsed;
  811. gridThickness.Visibility = Visibility.Collapsed;
  812. }
  813. /// <summary>
  814. /// 画笔 中
  815. /// </summary>
  816. /// <param name="sender"></param>
  817. /// <param name="e"></param>
  818. private void BtnIn_Click(object sender, RoutedEventArgs e)
  819. {
  820. APP.W_PracticeWindow.In();
  821. gridColour.Visibility = Visibility.Collapsed;
  822. gridThickness.Visibility = Visibility.Collapsed;
  823. }
  824. /// <summary>
  825. /// 画笔粗
  826. /// </summary>
  827. /// <param name="sender"></param>
  828. /// <param name="e"></param>
  829. private void BtnCrude_Click(object sender, RoutedEventArgs e)
  830. {
  831. APP.W_PracticeWindow.Crude();
  832. gridColour.Visibility = Visibility.Collapsed;
  833. gridThickness.Visibility = Visibility.Collapsed;
  834. }
  835. /// <summary>
  836. /// 橡皮
  837. /// </summary>
  838. /// <param name="sender"></param>
  839. /// <param name="e"></param>
  840. private void BtnEraser_Click(object sender, RoutedEventArgs e)
  841. {
  842. APP.W_PracticeWindow.Eraser();
  843. }
  844. /// <summary>
  845. /// 🖊
  846. /// </summary>
  847. /// <param name="sender"></param>
  848. /// <param name="e"></param>
  849. private void BtnPen_Click(object sender, RoutedEventArgs e)
  850. {
  851. APP.W_PracticeWindow.Pen();
  852. }
  853. /// <summary>
  854. /// ⚪
  855. /// </summary>
  856. /// <param name="sender"></param>
  857. /// <param name="e"></param>
  858. private void BtnRound_Click(object sender, RoutedEventArgs e)
  859. {
  860. APP.W_PracticeWindow.Round();
  861. }
  862. /// <summary>
  863. /// 矩形
  864. /// </summary>
  865. /// <param name="sender"></param>
  866. /// <param name="e"></param>
  867. private void BtnRectangle_Click(object sender, RoutedEventArgs e)
  868. {
  869. APP.W_PracticeWindow.Rectangle();
  870. }
  871. #endregion
  872. #endregion
  873. /// <summary>
  874. /// 停止录屏
  875. /// </summary>
  876. public delegate void StopRecordingScreen();
  877. /// <summary>
  878. /// 停止录屏
  879. /// </summary>
  880. public event StopRecordingScreen Click_stopRecordingScreen;
  881. /// <summary>
  882. /// 黑笔
  883. /// </summary>
  884. /// <param name="sender"></param>
  885. /// <param name="e"></param>
  886. private void BtnBlackPen_Click(object sender, RoutedEventArgs e)
  887. {
  888. }
  889. /// <summary>
  890. /// 移动工具栏
  891. /// </summary>
  892. /// <param name="sender"></param>
  893. /// <param name="e"></param>
  894. private void Grid_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  895. {
  896. DragMove();
  897. }
  898. /// <summary>
  899. /// 红笔
  900. /// </summary>
  901. /// <param name="sender"></param>
  902. /// <param name="e"></param>
  903. private void BtnBlackPenTwo_Click(object sender, RoutedEventArgs e)
  904. {
  905. #region 防止连击
  906. if (IsPressButton)
  907. {
  908. return;
  909. }
  910. else
  911. {
  912. IsPressButton = true;
  913. new Thread(new ThreadStart(new Action(() =>
  914. {
  915. Thread.Sleep(500);
  916. IsPressButton = false;
  917. }))).Start();
  918. }
  919. #endregion
  920. string time = GetTimeStamp();
  921. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  922. if (!Directory.Exists(tempPath))
  923. {
  924. Directory.CreateDirectory(tempPath);
  925. }
  926. #region 录屏批注取消画笔
  927. string imagePath = Path.Combine(tempPath, time + ".jpg");
  928. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  929. #endregion
  930. try
  931. {
  932. if (flg == 10)
  933. {
  934. Dispatcher.Invoke(() =>
  935. {
  936. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  937. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  938. });
  939. flg = 0;
  940. //this.Owner = null;
  941. APP.W_PracticeWindow.ReturnPractice();
  942. }
  943. else if (flg == 11)
  944. {
  945. Dispatcher.Invoke(() =>
  946. {
  947. borTwo.Background = new SolidColorBrush(Colors.LightSkyBlue);
  948. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  949. });
  950. flg = 10;
  951. APP.W_PracticeWindow.Red();
  952. }
  953. else
  954. {
  955. Dispatcher.Invoke(() =>
  956. {
  957. borTwo.Background = new SolidColorBrush(Colors.LightSkyBlue);
  958. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  959. });
  960. if (APP.W_PracticeWindow == null)
  961. {
  962. APP.W_PracticeWindow = new PracticeWindow
  963. {
  964. //APP.W_PracticeWindow.Topmost = true;
  965. Width = pwidth,
  966. Height = pHeight,
  967. Left = 0,
  968. Top = 0
  969. };
  970. //practiceWin.Owner = this;
  971. }
  972. APP.W_PracticeWindow.Initialize();//imagePath);
  973. flg = 10;
  974. APP.W_PracticeWindow.Red();
  975. APP.W_PracticeWindow.Show();
  976. new Thread(new ThreadStart(new Action(() =>
  977. {
  978. Thread.Sleep(100);
  979. Dispatcher.Invoke(() =>
  980. {
  981. Owner = APP.W_PracticeWindow;
  982. Topmost = true;
  983. });
  984. }))).Start();
  985. }
  986. }
  987. catch (Exception ex)
  988. {
  989. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  990. }
  991. }
  992. /// <summary>
  993. /// 鼠标右键按下事件 废弃
  994. /// </summary>
  995. /// <param name="sender"></param>
  996. /// <param name="e"></param>
  997. private void RightButtonDown()
  998. {
  999. if (flg > 9)
  1000. {
  1001. Owner = null;
  1002. APP.W_PracticeWindow.Hide();
  1003. }
  1004. else
  1005. {
  1006. //string time = GetTimeStamp();
  1007. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  1008. if (!Directory.Exists(tempPath))
  1009. {
  1010. Directory.CreateDirectory(tempPath);
  1011. }
  1012. #region 录屏批注取消画笔
  1013. //string imagePath = Path.Combine(tempPath, time + ".jpg");
  1014. //ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  1015. #endregion
  1016. try
  1017. {
  1018. if (APP.W_PracticeWindow == null)
  1019. {
  1020. APP.W_PracticeWindow = new PracticeWindow
  1021. {
  1022. //APP.W_PracticeWindow.Topmost = true;
  1023. Width = pwidth,
  1024. Height = pHeight,
  1025. Left = 0,
  1026. Top = 0
  1027. };
  1028. //practiceWin.Owner = this;
  1029. }
  1030. APP.W_PracticeWindow.Initialize();//imagePath);
  1031. if (flg == 0)
  1032. {
  1033. flg = 10;
  1034. APP.W_PracticeWindow.Red();
  1035. }
  1036. else
  1037. {
  1038. flg = 11;
  1039. APP.W_PracticeWindow.Blue();
  1040. }
  1041. APP.W_PracticeWindow.Show();
  1042. }
  1043. catch (Exception ex)
  1044. {
  1045. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  1046. }
  1047. }
  1048. }
  1049. /// <summary>
  1050. /// 返回主界面
  1051. /// </summary>
  1052. /// <param name="sender"></param>
  1053. /// <param name="e"></param>
  1054. private void BtnReturn_Click(object sender, RoutedEventArgs e)
  1055. {
  1056. if (!IsFirstRS)
  1057. {
  1058. MessageBoxResult br = MessageWindow.Show("退出将不保存当前录屏!", "提示", MessageBoxButton.OKCancel);
  1059. if (br == MessageBoxResult.Cancel)
  1060. {
  1061. return;
  1062. }
  1063. k_hook.Stop();
  1064. IsSuspend = true;
  1065. txbTime.Text = "00:00";
  1066. txbTime.Visibility = Visibility.Hidden;
  1067. End();
  1068. APP.W_PracticeWindow.ReturnPractice();
  1069. if (APP.W_PracticeWindow != null)
  1070. {
  1071. if (APP.W_PracticeWindow.Visibility == Visibility.Visible)
  1072. {
  1073. APP.W_PracticeWindow.Hide();
  1074. }
  1075. }
  1076. if (gridToolbar.Visibility == Visibility.Visible)
  1077. {
  1078. gridToolbar.Visibility = Visibility.Hidden;
  1079. gridColour.Visibility = Visibility.Hidden;
  1080. gridThickness.Visibility = Visibility.Hidden;
  1081. }
  1082. if (APP.W_XHMicroLessonSystemWindow == null)
  1083. {
  1084. APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
  1085. }
  1086. try
  1087. {
  1088. try
  1089. {
  1090. APP.FFmpeg.SuspendFFmpeg();
  1091. }
  1092. catch (Exception ex)
  1093. {
  1094. LogHelper.WriteErrLog("【录屏返回】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  1095. }
  1096. IsFirstRS = true;
  1097. new Thread(new ThreadStart(new Action(() =>
  1098. {
  1099. VideoInfo = null;
  1100. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temprs/");
  1101. }))).Start();
  1102. }
  1103. catch (Exception ex)
  1104. {
  1105. LogHelper.WriteErrLog("【录屏返回】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  1106. }
  1107. }
  1108. APP.W_XHMicroLessonSystemWindow.InitializeKeyDownEvent();
  1109. APP.W_XHMicroLessonSystemWindow.Show();
  1110. Hide();
  1111. }
  1112. /// <summary>
  1113. /// 批注退出 废弃
  1114. /// </summary>
  1115. public void ReturnPractice()
  1116. {
  1117. new Thread(new ThreadStart(new Action(() =>
  1118. {
  1119. Dispatcher.Invoke(() =>
  1120. {
  1121. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  1122. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  1123. });
  1124. flg = 0;
  1125. Thread.Sleep(500);
  1126. Dispatcher.Invoke(() =>
  1127. {
  1128. Owner = null;
  1129. APP.W_PracticeWindow.Hide();
  1130. });
  1131. }))).Start();
  1132. //Dispatcher.Invoke(() =>
  1133. //{
  1134. // borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  1135. // borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  1136. //});
  1137. //flg = 0;
  1138. //Thread.Sleep(300);
  1139. //APP.W_PracticeWindow.Hide();
  1140. }
  1141. /// <summary>
  1142. /// 修改笔状态
  1143. /// </summary>
  1144. public void ModifyState()
  1145. {
  1146. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  1147. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  1148. }
  1149. }
  1150. }