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

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