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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  1. using Common.system;
  2. using NReco.VideoConverter;
  3. using System;
  4. using System.Drawing;
  5. using System.IO;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Forms;
  10. using System.Windows.Interop;
  11. using System.Windows.Threading;
  12. using XHWK.Model;
  13. using XHWK.WKTool.Utils;
  14. namespace XHWK.WKTool
  15. {
  16. using system;
  17. /// <summary>
  18. /// 录屏工具栏
  19. /// </summary>
  20. public partial class ScreenRecordingToolbarWindow
  21. {
  22. #region 初始变量
  23. /// <summary>
  24. /// 视频保存名称
  25. /// </summary>
  26. private string _videoSavePathName;
  27. /// <summary>
  28. /// 临时视频路径
  29. /// </summary>
  30. private string _tempVideoPathName;
  31. /// <summary>
  32. /// 临时麦克风路径
  33. /// </summary>
  34. private string _tempAudioPathName1;
  35. /// <summary>
  36. /// 临时扬声器路径
  37. /// </summary>
  38. private string _tempAudioPathName2;
  39. private readonly string _temppath = App.WKData.WkPath + "_temppath/";
  40. /// <summary>
  41. /// 视频信息
  42. /// </summary>
  43. private ModelVideo _videoInfo;
  44. //声明一个 DrawingAttributes 类型的变量
  45. private DispatcherTimer _t;
  46. /// <summary>
  47. /// 计时器状态
  48. /// </summary>
  49. private enum State
  50. {
  51. Start,
  52. Pause,
  53. End,
  54. Loading
  55. }
  56. /// <summary>
  57. /// 状态
  58. /// </summary>
  59. private State _state = State.End;
  60. private KeyboardHookCommon _kHook;
  61. /// <summary>
  62. /// 🖊状态 0红色 1蓝色 10红色批注内 11蓝色批注内
  63. /// </summary>
  64. public int flg;
  65. #endregion 初始变量
  66. #region 初始化
  67. /// <summary>
  68. /// 录屏工具栏
  69. /// </summary>
  70. public ScreenRecordingToolbarWindow()
  71. {
  72. InitializeComponent();
  73. ResizeMode = ResizeMode.NoResize;
  74. }
  75. /// <summary>
  76. /// 初始化
  77. /// </summary>
  78. public void Initialize()
  79. {
  80. GridSrToobar.Visibility = Visibility.Visible;
  81. if (App.W_PracticeWindow == null)
  82. {
  83. App.W_PracticeWindow = new PracticeWindow
  84. {
  85. //APP.W_PracticeWindow.Topmost = true;
  86. Width = pwidth,
  87. Height = pHeight,
  88. Left = 0,
  89. Top = 0
  90. };
  91. //practiceWin.Owner = this;
  92. }
  93. App.W_PracticeWindow.InitTqlpPen();
  94. App.W_PracticeWindow.Show();
  95. new Thread
  96. (
  97. () =>
  98. {
  99. Thread.Sleep(100);
  100. Dispatcher.Invoke(() => { Topmost = true; });
  101. }
  102. ).Start();
  103. App.W_PracticeWindow.Hide();
  104. flg = 0;
  105. _kHook = new KeyboardHookCommon();
  106. _kHook.KeyDownEvent += K_hook_KeyDownEvent;
  107. //创建 DrawingAttributes 类的一个实例
  108. //隐藏画笔工具栏
  109. BtnRecordingScreen.Visibility = Visibility.Visible;
  110. BtnRecordingScreenPause.Visibility = Visibility.Collapsed;
  111. BtnStopRecordingScreen.IsEnabled = false; //停止录制按钮不点击
  112. BtnPenBlue.IsEnabled = false; //蓝笔不可点击
  113. BtnPenRed.IsEnabled = false; //红笔不可点击
  114. BtnPenBlue.Visibility = Visibility.Visible;
  115. BtnPenRed.Visibility = Visibility.Visible;
  116. BtnPenBlue_CL.Visibility = Visibility.Collapsed;
  117. BtnPenRed_CL.Visibility = Visibility.Collapsed;
  118. TxbTime.Content = "00:00:00";
  119. }
  120. private void K_hook_KeyDownEvent(object sender, System.Windows.Forms.KeyEventArgs e)
  121. {
  122. if (e.KeyValue == (int)System.Windows.Forms.Keys.F5 && (int)Control.ModifierKeys == (int)Keys.Control)
  123. {
  124. //开始,暂停
  125. BtnRecordingScreen_Click(null, null);
  126. }
  127. if (e.KeyValue == (int)Keys.F6 && (int)Control.ModifierKeys == (int)Keys.Control)
  128. {
  129. //结束
  130. BtnStopRecordingScreen_Click(null, null);
  131. }
  132. }
  133. #endregion 初始化
  134. #region 事件
  135. private DateTime _srTime = Convert.ToDateTime("2020-01-01 00:00:00");
  136. /// <summary>
  137. /// 时钟回调
  138. /// </summary>
  139. /// <param name="sender"></param>
  140. /// <param name="e"></param>
  141. private void OnTimer(object sender, EventArgs e)
  142. {
  143. if (_state == State.Start)
  144. {
  145. _srTime = _srTime.AddMilliseconds(1000);
  146. }
  147. TxbTime.Content = _srTime.ToString("HH:mm:ss");
  148. }
  149. /// <summary>
  150. /// 结束
  151. /// </summary>
  152. private void End()
  153. {
  154. _state = State.End;
  155. }
  156. #region 录屏
  157. /// <summary>
  158. /// 设置录屏文件地址
  159. /// </summary>
  160. private void SetSavePath()
  161. {
  162. string fileType = ((EnumVideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
  163. FileToolsCommon.CreateDirectory(App.WKData.WkPath);
  164. FileToolsCommon.DeleteDirectory(_temppath);
  165. FileToolsCommon.CreateDirectory(_temppath);
  166. _videoSavePathName = App.WKData.WkPath + App.WKData.WkName + "_录屏." + fileType;
  167. int num = 1;
  168. while (FileToolsCommon.IsExistFile(_videoSavePathName))
  169. {
  170. num++;
  171. _videoSavePathName = App.WKData.WkPath + App.WKData.WkName + "_录屏_" + num + "." + fileType;
  172. }
  173. _tempVideoPathName = _temppath + "_录屏_" + num + ".avi";
  174. _tempAudioPathName1 = _temppath + "_麦克风_" + num + "_1.mp3";
  175. _tempAudioPathName2 = _temppath + "_扬声器_" + num + "_2.mp3";
  176. }
  177. /// <summary>
  178. /// 是否已经按下按钮
  179. /// </summary>
  180. private bool _isPressButton;
  181. //录制麦克风的声音
  182. private ZAudioRecordHelper _helper1;
  183. //录制扬声器的声音
  184. private ZAudioRecordHelper _helper2;
  185. //桌面录制
  186. private ZVideoRecordHelper _helper0;
  187. public IntPtr winHandle; // 当前窗体指针
  188. /// <summary>
  189. /// 开始或暂停录制
  190. /// </summary>
  191. /// <param name="sender"></param>
  192. /// <param name="e"></param>
  193. private async void BtnRecordingScreen_Click(object sender, RoutedEventArgs e)
  194. {
  195. #region 防止连击
  196. if (_isPressButton)
  197. {
  198. return;
  199. }
  200. _isPressButton = true;
  201. new Thread
  202. (
  203. () =>
  204. {
  205. Thread.Sleep(500);
  206. _isPressButton = false;
  207. }
  208. ).Start();
  209. #endregion 防止连击
  210. if (_state == State.End)
  211. {
  212. _srTime = Convert.ToDateTime("2020-01-01 00:00:00");
  213. TxbTime.Content = "00:00";
  214. if (_t == null)
  215. {
  216. _t = new DispatcherTimer();
  217. _t.Tick += OnTimer;
  218. _t.Interval = new TimeSpan
  219. (
  220. 0,
  221. 0,
  222. 0,
  223. 0,
  224. 1000
  225. );
  226. _t.IsEnabled = true;
  227. _t.Start();
  228. }
  229. else
  230. {
  231. _t.Interval = new TimeSpan
  232. (
  233. 0,
  234. 0,
  235. 0,
  236. 0,
  237. 1000
  238. );
  239. }
  240. _state = State.Loading;
  241. _videoInfo = new ModelVideo { VideoType = (EnumVideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType")), WkType = EnumWkVidetype.RecordingScreen };
  242. SetSavePath();
  243. if (App.W_CountdownWindow == null)
  244. {
  245. App.W_CountdownWindow = new CountdownWindow();
  246. }
  247. App.W_CountdownWindow.InitAndShow(true);
  248. BtnRecordingScreen.Visibility = Visibility.Collapsed;
  249. BtnRecordingScreenPause.Visibility = Visibility.Visible;
  250. BtnStopRecordingScreen.IsEnabled = true; //停止录制按钮可点击
  251. BtnPenBlue.IsEnabled = true; //蓝笔可点击
  252. BtnPenRed.IsEnabled = true; //红笔可点击
  253. BtnPenBlue.Visibility = Visibility.Visible;
  254. BtnPenRed.Visibility = Visibility.Visible;
  255. BtnPenBlue_CL.Visibility = Visibility.Collapsed;
  256. BtnPenRed_CL.Visibility = Visibility.Collapsed;
  257. TxbTime.Visibility = Visibility.Visible; //时间显示
  258. #region 隐藏工具栏
  259. if (App.IsHideSRTool)
  260. {
  261. if (App.W_MinToolbar == null)
  262. {
  263. App.W_MinToolbar = new MinToolbar();
  264. }
  265. App.W_MinToolbar.Topmost = true;
  266. double minToolTop = Top;
  267. GridSrToobar.Visibility = Visibility.Hidden;
  268. App.W_MinToolbar.Initialize(minToolTop, ActualHeight);
  269. App.W_MinToolbar.Show();
  270. }
  271. #endregion 隐藏工具栏
  272. try
  273. {
  274. // 视频
  275. winHandle = new WindowInteropHelper(this).Handle;
  276. var curScreen = Screen.FromHandle(winHandle);
  277. int recordWidth = curScreen.Bounds.Width;
  278. int recordHeight = curScreen.Bounds.Height;
  279. _helper0 = new ZVideoRecordHelper
  280. (
  281. _tempVideoPathName,
  282. recordWidth,
  283. recordHeight
  284. );
  285. // 麦克风
  286. _helper1 = new ZAudioRecordHelper(_tempAudioPathName1, ZAudioRecordHelper.RecordType.Microphone);
  287. // 扬声器
  288. _helper2 = new ZAudioRecordHelper(_tempAudioPathName2, ZAudioRecordHelper.RecordType.Loudspeaker);
  289. await Task.Delay(3000);
  290. // App.W_CountdownWindow.Hide();
  291. await Task.Delay(100);
  292. _state = State.Start;
  293. _helper1.StartRecordAudio();
  294. _helper2.StartRecordAudio();
  295. _helper0.StartRecordVideo();
  296. _kHook.Start(); //安装键盘钩子
  297. }
  298. catch (Exception)
  299. {
  300. ExitByErr();
  301. }
  302. Console.WriteLine(@"TempVideoPathName:" + _tempVideoPathName);
  303. Console.WriteLine(@"TempAudioPathName1:" + _tempAudioPathName1);
  304. Console.WriteLine(@"TempAudioPathName2:" + _tempAudioPathName2);
  305. }
  306. else if (_state == State.Start)
  307. {
  308. _state = State.Pause;
  309. _helper1.PauseRecordAudio();
  310. _helper2.PauseRecordAudio();
  311. _helper0.PauseRecordVideo();
  312. BtnRecordingScreen.Visibility = Visibility.Visible;
  313. BtnRecordingScreenPause.Visibility = Visibility.Collapsed;
  314. }
  315. else if (_state == State.Pause)
  316. {
  317. _state = State.Start;
  318. _helper1.ResumeRecordAudio();
  319. _helper2.ResumeRecordAudio();
  320. _helper0.ResumeRecordVideo();
  321. BtnRecordingScreen.Visibility = Visibility.Collapsed;
  322. BtnRecordingScreenPause.Visibility = Visibility.Visible;
  323. }
  324. }
  325. private void ExitByErr()
  326. {
  327. BtnRecordingScreen.ToolTip = "开始";
  328. _kHook.Stop();
  329. TxbTime.Content = "00:00";
  330. if (App.W_PracticeWindow != null)
  331. {
  332. if (App.W_PracticeWindow.Visibility == Visibility.Visible)
  333. {
  334. Owner = null;
  335. App.W_PracticeWindow.ReturnPractice();
  336. }
  337. }
  338. if (App.W_XHMicroLessonSystemWindow == null)
  339. {
  340. App.W_XHMicroLessonSystemWindow = new MainWindow();
  341. }
  342. App.W_XHMicroLessonSystemWindow.InitializeKeyDownEvent();
  343. App.W_XHMicroLessonSystemWindow.InitTqlpPen();
  344. App.W_XHMicroLessonSystemWindow.Show();
  345. End();
  346. if (_t != null)
  347. {
  348. _t.Stop();
  349. _t = null;
  350. }
  351. _helper0.StopRecordVideo();
  352. _helper1.StopRecordAudio();
  353. _helper2.StopRecordAudio();
  354. FileToolsCommon.DeleteDirectory(_temppath);
  355. if (ClickStopRecordingScreen != null)
  356. {
  357. ClickStopRecordingScreen();
  358. }
  359. Hide();
  360. }
  361. /// <summary>
  362. /// 停止录像
  363. /// </summary>
  364. /// <param name="sender"></param>
  365. /// <param name="e"></param>
  366. private void BtnStopRecordingScreen_Click(object sender, RoutedEventArgs e)
  367. {
  368. #region 防止连击
  369. if (_isPressButton)
  370. {
  371. return;
  372. }
  373. else
  374. {
  375. _isPressButton = true;
  376. new Thread
  377. (
  378. () =>
  379. {
  380. Thread.Sleep(500);
  381. _isPressButton = false;
  382. }
  383. ).Start();
  384. }
  385. #endregion 防止连击
  386. BtnRecordingScreen.ToolTip = "开始";
  387. _kHook.Stop();
  388. TxbTime.Content = "00:00";
  389. if (App.W_PracticeWindow != null)
  390. {
  391. if (App.W_PracticeWindow.Visibility == Visibility.Visible)
  392. {
  393. Owner = null;
  394. App.W_PracticeWindow.ReturnPractice();
  395. }
  396. }
  397. if (App.W_XHMicroLessonSystemWindow == null)
  398. {
  399. App.W_XHMicroLessonSystemWindow = new MainWindow();
  400. }
  401. App.W_XHMicroLessonSystemWindow.InitializeKeyDownEvent();
  402. App.W_XHMicroLessonSystemWindow.InitTqlpPen();
  403. App.W_XHMicroLessonSystemWindow.Show();
  404. if (_state == State.Pause || _state == State.Start)
  405. {
  406. End();
  407. _t.Stop();
  408. _t = null;
  409. Console.WriteLine(@"停止录制");
  410. _helper0.StopRecordVideo();
  411. _helper1.StopRecordAudio();
  412. _helper2.StopRecordAudio();
  413. new Thread
  414. (
  415. () =>
  416. {
  417. FFMpegConverter ffMpeg = new FFMpegConverter();
  418. FFMpegInput[] input = new FFMpegInput[]
  419. {
  420. new FFMpegInput(_tempVideoPathName),
  421. new FFMpegInput(_tempAudioPathName1),
  422. new FFMpegInput(_tempAudioPathName2),
  423. };
  424. try
  425. {
  426. // 多路音频混音
  427. ffMpeg.ConvertMedia
  428. (
  429. input,
  430. _videoSavePathName,
  431. "mp4",
  432. new OutputSettings() { CustomOutputArgs = "-filter_complex amix=inputs=2:duration=first:dropout_transition=2" }
  433. );
  434. //生成缩略图
  435. string thumbnailPath = FileToolsCommon.GetDirectoryName(_videoSavePathName) + "ThumbnailPath/";
  436. FileToolsCommon.CreateDirectory(thumbnailPath);
  437. //缩略图存储位置
  438. string thumbnailPathName = thumbnailPath + FileToolsCommon.GetIoFileName(_videoSavePathName).Replace(".", "") + ".JPG";
  439. _videoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  440. _videoInfo.VideoPath = _videoSavePathName;
  441. _videoInfo.ThumbnailPath = thumbnailPathName;
  442. ZVideoRecordHelper.GetVideoPic(_tempVideoPathName, thumbnailPathName);
  443. _videoInfo.FileGuid = Guid.NewGuid().ToString();
  444. _videoInfo.IsUpload = false;
  445. _videoInfo.Uploaded = 0;
  446. if (!App.VideoList.Exists(x => x.FileGuid == _videoInfo.FileGuid) || !App.VideoList.Exists(x => x.VideoPath == _videoInfo.VideoPath))
  447. {
  448. App.VideoList.Add(_videoInfo);
  449. //保存数据
  450. App.SaveWkData();
  451. }
  452. }
  453. catch (Exception ex)
  454. {
  455. LogHelper.Logerror.Error("录屏保存" + ex.Message, ex);
  456. }
  457. FileToolsCommon.DeleteDirectory(_temppath);
  458. }
  459. ).Start();
  460. }
  461. if (ClickStopRecordingScreen != null)
  462. {
  463. ClickStopRecordingScreen();
  464. }
  465. Hide();
  466. _srTime = Convert.ToDateTime("2020-01-01 00:00:00");
  467. TxbTime.Content = "00:00";
  468. }
  469. public void MaxToobar()
  470. {
  471. Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);
  472. float dip = graphics.DpiX;
  473. //float DIPY = graphics.DpiY;
  474. App.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.WorkingArea.Width / (dip / 96) - App.W_ScreenRecordingToolbarWindow.Width;
  475. GridSrToobar.Visibility = Visibility.Visible;
  476. App.W_ScreenRecordingToolbarWindow.Topmost = true;
  477. }
  478. #endregion 录屏
  479. #region 画笔相关
  480. /// <summary>
  481. /// 笔调用批注
  482. /// </summary>
  483. public void PenPractice()
  484. {
  485. if (flg != 11 && flg != 10)
  486. {
  487. #region 防止连击
  488. if (_isPressButton)
  489. {
  490. return;
  491. }
  492. else
  493. {
  494. _isPressButton = true;
  495. new Thread
  496. (
  497. () =>
  498. {
  499. Thread.Sleep(500);
  500. _isPressButton = false;
  501. }
  502. ).Start();
  503. }
  504. #endregion 防止连击
  505. GetTimeStamp();
  506. try
  507. {
  508. Dispatcher.Invoke
  509. (
  510. () =>
  511. {
  512. if (App.W_PracticeWindow == null)
  513. {
  514. App.W_PracticeWindow = new PracticeWindow
  515. {
  516. Width = pwidth,
  517. Height = pHeight,
  518. Left = 0,
  519. Top = 0
  520. };
  521. }
  522. App.W_PracticeWindow.Initialize(); // imagePath);
  523. flg = 11;
  524. App.W_PracticeWindow.Blue();
  525. App.W_PracticeWindow.Show();
  526. App.W_PracticeWindow.Topmost = true;
  527. App.W_PracticeWindow.Focus();
  528. }
  529. );
  530. new Thread
  531. (
  532. () =>
  533. {
  534. Dispatcher.Invoke(() => { App.W_PracticeWindow.Topmost = false; });
  535. Thread.Sleep(500);
  536. Dispatcher.Invoke(() => { Topmost = true; });
  537. }
  538. ).Start();
  539. }
  540. catch (Exception ex)
  541. {
  542. LogHelper.Logerror.Error("【批注(PracticeWindow)" + ex.Message, ex);
  543. }
  544. }
  545. }
  546. /// <summary>
  547. /// 画笔点击事件
  548. /// </summary>
  549. /// <param name="sender"></param>
  550. /// <param name="e"></param>
  551. private void BtnBrush_Click(object sender, RoutedEventArgs e)
  552. {
  553. if (BtnPenBlue.Visibility != Visibility.Visible)
  554. {
  555. return;
  556. }
  557. #region 防止连击
  558. if (_isPressButton)
  559. {
  560. return;
  561. }
  562. else
  563. {
  564. _isPressButton = true;
  565. new Thread
  566. (
  567. () =>
  568. {
  569. Thread.Sleep(500);
  570. _isPressButton = false;
  571. }
  572. ).Start();
  573. }
  574. #endregion 防止连击
  575. BtnPenBlue.Visibility = Visibility.Collapsed;
  576. BtnPenRed.Visibility = Visibility.Visible;
  577. BtnPenBlue_CL.Visibility = Visibility.Visible;
  578. BtnPenRed_CL.Visibility = Visibility.Collapsed;
  579. GetTimeStamp();
  580. try
  581. {
  582. if (flg == 11)
  583. {
  584. //Dispatcher.Invoke(() =>
  585. //{
  586. // borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  587. // borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  588. //});
  589. flg = 1;
  590. //this.Owner = null;
  591. App.W_PracticeWindow.ReturnPractice();
  592. }
  593. else if (flg == 10)
  594. {
  595. //Dispatcher.Invoke(() =>
  596. //{
  597. // borOne.Background = new SolidColorBrush(Colors.LightSkyBlue);
  598. // borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  599. //});
  600. App.W_PracticeWindow.Blue();
  601. flg = 11;
  602. }
  603. else
  604. {
  605. //new Thread(new ThreadStart(new Action(() =>
  606. //{
  607. //Dispatcher.Invoke(() =>
  608. //{
  609. // borOne.Background = new SolidColorBrush(Colors.LightSkyBlue);
  610. // borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  611. //});
  612. //}))).Start();
  613. if (App.W_PracticeWindow == null)
  614. {
  615. App.W_PracticeWindow = new PracticeWindow
  616. {
  617. //APP.W_PracticeWindow.Topmost = true;
  618. Width = pwidth,
  619. Height = pHeight,
  620. Left = 0,
  621. Top = 0
  622. };
  623. //practiceWin.Owner = this;
  624. }
  625. App.W_PracticeWindow.InitTqlpPen();
  626. App.W_PracticeWindow.Initialize(); // imagePath);
  627. flg = 11;
  628. App.W_PracticeWindow.Blue();
  629. App.W_PracticeWindow.Show();
  630. new Thread
  631. (
  632. () =>
  633. {
  634. Thread.Sleep(100);
  635. Dispatcher.Invoke
  636. (
  637. () =>
  638. {
  639. //Owner = APP.W_PracticeWindow;
  640. Topmost = true;
  641. }
  642. );
  643. }
  644. ).Start();
  645. }
  646. }
  647. catch (Exception ex)
  648. {
  649. LogHelper.Logerror.Error("【批注(PracticeWindow)" + ex.Message, ex);
  650. }
  651. //imgCanvas.Source = new BitmapImage(new Uri(imagePath));
  652. }
  653. /// <summary>
  654. /// 屏幕宽
  655. /// </summary>
  656. internal double pwidth = SystemParameters.PrimaryScreenWidth;
  657. /// <summary>
  658. /// 屏幕高
  659. /// </summary>
  660. internal double pHeight = SystemParameters.PrimaryScreenHeight;
  661. /// <summary>
  662. /// 获取时间戳
  663. /// </summary>
  664. /// <returns></returns>
  665. public string GetTimeStamp()
  666. {
  667. TimeSpan ts = DateTime.Now
  668. - new DateTime
  669. (
  670. 1970,
  671. 1,
  672. 1,
  673. 0,
  674. 0,
  675. 0,
  676. 0
  677. );
  678. return Convert.ToInt64(ts.TotalMilliseconds).ToString();
  679. }
  680. #endregion 画笔相关
  681. #endregion 事件
  682. /// <summary>
  683. /// 停止录屏
  684. /// </summary>
  685. public delegate void StopRecordingScreen();
  686. /// <summary>
  687. /// 停止录屏
  688. /// </summary>
  689. public event StopRecordingScreen ClickStopRecordingScreen;
  690. /// <summary>
  691. /// 红笔
  692. /// </summary>
  693. /// <param name="sender"></param>
  694. /// <param name="e"></param>
  695. private void BtnBlackPenTwo_Click(object sender, RoutedEventArgs e)
  696. {
  697. if (BtnPenRed.Visibility != Visibility.Visible)
  698. {
  699. return;
  700. }
  701. #region 防止连击
  702. if (_isPressButton)
  703. {
  704. return;
  705. }
  706. else
  707. {
  708. _isPressButton = true;
  709. new Thread
  710. (
  711. () =>
  712. {
  713. Thread.Sleep(500);
  714. _isPressButton = false;
  715. }
  716. ).Start();
  717. }
  718. #endregion 防止连击
  719. BtnPenBlue.Visibility = Visibility.Visible;
  720. BtnPenRed.Visibility = Visibility.Collapsed;
  721. BtnPenBlue_CL.Visibility = Visibility.Collapsed;
  722. BtnPenRed_CL.Visibility = Visibility.Visible;
  723. string time = GetTimeStamp();
  724. #region 录屏批注取消画笔
  725. string imagePath = Path.Combine(_temppath, time + ".jpg");
  726. ImageHelper.GetScreenshot
  727. (
  728. new Rectangle
  729. (
  730. 0,
  731. 0,
  732. 0,
  733. 0
  734. ),
  735. imagePath
  736. );
  737. #endregion 录屏批注取消画笔
  738. try
  739. {
  740. if (flg == 10)
  741. {
  742. flg = 0;
  743. App.W_PracticeWindow.ReturnPractice();
  744. }
  745. else if (flg == 11)
  746. {
  747. flg = 10;
  748. App.W_PracticeWindow.Red();
  749. }
  750. else
  751. {
  752. if (App.W_PracticeWindow == null)
  753. {
  754. App.W_PracticeWindow = new PracticeWindow
  755. {
  756. Width = pwidth,
  757. Height = pHeight,
  758. Left = 0,
  759. Top = 0
  760. };
  761. }
  762. App.W_PracticeWindow.InitTqlpPen();
  763. App.W_PracticeWindow.Initialize(); //imagePath);
  764. flg = 10;
  765. App.W_PracticeWindow.Red();
  766. App.W_PracticeWindow.Show();
  767. new Thread
  768. (
  769. () =>
  770. {
  771. Thread.Sleep(100);
  772. Dispatcher.Invoke
  773. (
  774. () =>
  775. {
  776. //Owner = APP.W_PracticeWindow;
  777. Topmost = true;
  778. }
  779. );
  780. }
  781. ).Start();
  782. }
  783. }
  784. catch (Exception ex)
  785. {
  786. LogHelper.Logerror.Error("【批注(PracticeWindow)" + ex.Message, ex);
  787. }
  788. }
  789. /// <summary>
  790. /// 返回主界面
  791. /// </summary>
  792. /// <param name="sender"></param>
  793. /// <param name="e"></param>
  794. private void BtnReturn_Click(object sender, RoutedEventArgs e)
  795. {
  796. if (_state == State.Pause || _state == State.Start)
  797. {
  798. MessageBoxResult br = MessageWindow.Show
  799. (
  800. "退出将结束并保存录制,是否继续?",
  801. "提示",
  802. MessageBoxButton.OKCancel
  803. );
  804. if (br == MessageBoxResult.Cancel)
  805. {
  806. return;
  807. }
  808. BtnStopRecordingScreen_Click(null, null);
  809. }
  810. App.W_XHMicroLessonSystemWindow.InitializeKeyDownEvent();
  811. //APP.W_XHMicroLessonSystemWindow.InitPen();
  812. App.W_XHMicroLessonSystemWindow.InitTqlpPen();
  813. App.W_XHMicroLessonSystemWindow.Show();
  814. new Thread
  815. (
  816. () =>
  817. {
  818. Thread.Sleep(700);
  819. Dispatcher.Invoke
  820. (
  821. () =>
  822. {
  823. if (App.W_MinToolbar != null)
  824. {
  825. App.W_MinToolbar.Hide();
  826. }
  827. }
  828. );
  829. }
  830. ).Start();
  831. Hide();
  832. }
  833. /// <summary>
  834. /// 修改笔状态
  835. /// </summary>
  836. public void ModifyState()
  837. {
  838. BtnPenBlue.Visibility = Visibility.Visible;
  839. BtnPenRed.Visibility = Visibility.Visible;
  840. BtnPenBlue_CL.Visibility = Visibility.Collapsed;
  841. BtnPenRed_CL.Visibility = Visibility.Collapsed;
  842. }
  843. private void gridToobarTwo_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
  844. {
  845. //if (BtnRecordingScreen.ToolTip.ToString().Equals("暂停") && (gridToobar.Visibility == Visibility.Visible || BorderBlack.Visibility == Visibility.Visible))
  846. if (BtnRecordingScreenPause.Visibility == Visibility.Visible)
  847. {
  848. if (App.IsHideSRTool)
  849. {
  850. if (App.W_MinToolbar == null)
  851. {
  852. App.W_MinToolbar = new MinToolbar();
  853. }
  854. App.W_MinToolbar.Topmost = true;
  855. double minToolTop = Top;
  856. new Thread
  857. (
  858. () =>
  859. {
  860. Thread.Sleep(500);
  861. Dispatcher.Invoke
  862. (
  863. () =>
  864. {
  865. MouseEventCommon.GetCursorPos(out MouseEventCommon.Point pointRecord);
  866. if (pointRecord.X >= this.Left && pointRecord.X < this.Left + this.ActualWidth && pointRecord.Y >= this.Top && pointRecord.Y < this.Top + this.ActualHeight)
  867. {
  868. //LblMessage.Content = "在区域内:("+ pointRecord.X+","+pointRecord.Y+") ("+ Left + ","+Top+")";
  869. }
  870. else
  871. {
  872. //LblMessage.Content = "不在区域内:(" + pointRecord.X + "," + pointRecord.Y + ") (" + Left + "," + Top + ")";
  873. App.W_MinToolbar.Initialize(minToolTop, ActualHeight);
  874. GridSrToobar.Visibility = Visibility.Hidden;
  875. App.W_MinToolbar.Show();
  876. }
  877. }
  878. );
  879. }
  880. ).Start();
  881. }
  882. }
  883. }
  884. }
  885. }