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

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