星火微课系统客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ScreenRecordingToolbarWindow.xaml.cs 33KB

4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969
  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 Model_Video _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 = ((Enum_VideoType)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 Model_Video
  242. {
  243. VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType")),
  244. WkType = Enum_WKVidetype.RecordingScreen
  245. };
  246. SetSavePath();
  247. if (App.W_CountdownWindow == null)
  248. {
  249. App.W_CountdownWindow = new CountdownWindow();
  250. }
  251. App.W_CountdownWindow.InitAndShow(true);
  252. BtnRecordingScreen.Visibility = Visibility.Collapsed;
  253. BtnRecordingScreenPause.Visibility = Visibility.Visible;
  254. BtnStopRecordingScreen.IsEnabled = true; //停止录制按钮可点击
  255. BtnPenBlue.IsEnabled = true; //蓝笔可点击
  256. BtnPenRed.IsEnabled = true; //红笔可点击
  257. BtnPenBlue.Visibility = Visibility.Visible;
  258. BtnPenRed.Visibility = Visibility.Visible;
  259. BtnPenBlue_CL.Visibility = Visibility.Collapsed;
  260. BtnPenRed_CL.Visibility = Visibility.Collapsed;
  261. TxbTime.Visibility = Visibility.Visible; //时间显示
  262. #region 隐藏工具栏
  263. if (App.IsHideSRTool)
  264. {
  265. if (App.W_MinToolbar == null)
  266. {
  267. App.W_MinToolbar = new MinToolbar();
  268. }
  269. App.W_MinToolbar.Topmost = true;
  270. double minToolTop = Top;
  271. GridSrToobar.Visibility = Visibility.Hidden;
  272. App.W_MinToolbar.Initialize(minToolTop, ActualHeight);
  273. App.W_MinToolbar.Show();
  274. }
  275. #endregion 隐藏工具栏
  276. try
  277. {
  278. // 视频
  279. winHandle = new WindowInteropHelper(this).Handle;
  280. var curScreen = Screen.FromHandle(winHandle);
  281. int recordWidth = curScreen.Bounds.Width;
  282. int recordHeight = curScreen.Bounds.Height;
  283. _helper0 = new ZVideoRecordHelper
  284. (
  285. _tempVideoPathName,
  286. recordWidth,
  287. recordHeight
  288. );
  289. // 麦克风
  290. _helper1 = new ZAudioRecordHelper(_tempAudioPathName1, ZAudioRecordHelper.RecordType.microphone);
  291. // 扬声器
  292. _helper2 = new ZAudioRecordHelper(_tempAudioPathName2, ZAudioRecordHelper.RecordType.loudspeaker);
  293. await Task.Delay(3000);
  294. // App.W_CountdownWindow.Hide();
  295. await Task.Delay(100);
  296. _state = State.Start;
  297. _helper1.StartRecordAudio();
  298. _helper2.StartRecordAudio();
  299. _helper0.StartRecordVideo();
  300. _kHook.Start(); //安装键盘钩子
  301. }
  302. catch (Exception)
  303. {
  304. ExitByErr();
  305. }
  306. Console.WriteLine(@"TempVideoPathName:" + _tempVideoPathName);
  307. Console.WriteLine(@"TempAudioPathName1:" + _tempAudioPathName1);
  308. Console.WriteLine(@"TempAudioPathName2:" + _tempAudioPathName2);
  309. }
  310. else if (_state == State.Start)
  311. {
  312. _state = State.Pause;
  313. _helper1.PauseRecordAudio();
  314. _helper2.PauseRecordAudio();
  315. _helper0.PauseRecordVideo();
  316. BtnRecordingScreen.Visibility = Visibility.Visible;
  317. BtnRecordingScreenPause.Visibility = Visibility.Collapsed;
  318. }
  319. else if (_state == State.Pause)
  320. {
  321. _state = State.Start;
  322. _helper1.ResumeRecordAudio();
  323. _helper2.ResumeRecordAudio();
  324. _helper0.ResumeRecordVideo();
  325. BtnRecordingScreen.Visibility = Visibility.Collapsed;
  326. BtnRecordingScreenPause.Visibility = Visibility.Visible;
  327. }
  328. }
  329. private void ExitByErr()
  330. {
  331. BtnRecordingScreen.ToolTip = "开始";
  332. _kHook.Stop();
  333. TxbTime.Content = "00:00";
  334. if (App.W_PracticeWindow != null)
  335. {
  336. if (App.W_PracticeWindow.Visibility == Visibility.Visible)
  337. {
  338. Owner = null;
  339. App.W_PracticeWindow.ReturnPractice();
  340. }
  341. }
  342. if (App.W_XHMicroLessonSystemWindow == null)
  343. {
  344. App.W_XHMicroLessonSystemWindow = new MainWindow();
  345. }
  346. App.W_XHMicroLessonSystemWindow.InitializeKeyDownEvent();
  347. App.W_XHMicroLessonSystemWindow.InitTqlpPen();
  348. App.W_XHMicroLessonSystemWindow.Show();
  349. End();
  350. if (_t != null)
  351. {
  352. _t.Stop();
  353. _t = null;
  354. }
  355. _helper0.StopRecordVideo();
  356. _helper1.StopRecordAudio();
  357. _helper2.StopRecordAudio();
  358. FileToolsCommon.DeleteDirectory(_temppath);
  359. if (ClickStopRecordingScreen != null)
  360. {
  361. ClickStopRecordingScreen();
  362. }
  363. Hide();
  364. }
  365. /// <summary>
  366. /// 停止录像
  367. /// </summary>
  368. /// <param name="sender"></param>
  369. /// <param name="e"></param>
  370. private void BtnStopRecordingScreen_Click(object sender, RoutedEventArgs e)
  371. {
  372. #region 防止连击
  373. if (_isPressButton)
  374. {
  375. return;
  376. }
  377. else
  378. {
  379. _isPressButton = true;
  380. new Thread
  381. (
  382. () =>
  383. {
  384. Thread.Sleep(500);
  385. _isPressButton = false;
  386. }
  387. ).Start();
  388. }
  389. #endregion 防止连击
  390. BtnRecordingScreen.ToolTip = "开始";
  391. _kHook.Stop();
  392. TxbTime.Content = "00:00";
  393. if (App.W_PracticeWindow != null)
  394. {
  395. if (App.W_PracticeWindow.Visibility == Visibility.Visible)
  396. {
  397. Owner = null;
  398. App.W_PracticeWindow.ReturnPractice();
  399. }
  400. }
  401. if (App.W_XHMicroLessonSystemWindow == null)
  402. {
  403. App.W_XHMicroLessonSystemWindow = new MainWindow();
  404. }
  405. App.W_XHMicroLessonSystemWindow.InitializeKeyDownEvent();
  406. App.W_XHMicroLessonSystemWindow.InitTqlpPen();
  407. App.W_XHMicroLessonSystemWindow.Show();
  408. if (_state == State.Pause || _state == State.Start)
  409. {
  410. End();
  411. _t.Stop();
  412. _t = null;
  413. Console.WriteLine(@"停止录制");
  414. _helper0.StopRecordVideo();
  415. _helper1.StopRecordAudio();
  416. _helper2.StopRecordAudio();
  417. new Thread
  418. (
  419. () =>
  420. {
  421. FFMpegConverter ffMpeg = new FFMpegConverter();
  422. FFMpegInput[] input = new FFMpegInput[]
  423. {
  424. new FFMpegInput(_tempVideoPathName),
  425. new FFMpegInput(_tempAudioPathName1),
  426. new FFMpegInput(_tempAudioPathName2),
  427. };
  428. try
  429. {
  430. // 多路音频混音
  431. ffMpeg.ConvertMedia
  432. (
  433. input,
  434. _videoSavePathName,
  435. "mp4",
  436. new OutputSettings() { CustomOutputArgs = "-filter_complex amix=inputs=2:duration=first:dropout_transition=2" }
  437. );
  438. //生成缩略图
  439. string thumbnailPath = FileToolsCommon.GetDirectoryName(_videoSavePathName) + "ThumbnailPath/";
  440. FileToolsCommon.CreateDirectory(thumbnailPath);
  441. //缩略图存储位置
  442. string thumbnailPathName = thumbnailPath + FileToolsCommon.GetIoFileName(_videoSavePathName).Replace(".", "") + ".JPG";
  443. _videoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  444. _videoInfo.VideoPath = _videoSavePathName;
  445. _videoInfo.ThumbnailPath = thumbnailPathName;
  446. ZVideoRecordHelper.GetVideoPic(_tempVideoPathName, thumbnailPathName);
  447. _videoInfo.FileGuid = Guid.NewGuid().ToString();
  448. _videoInfo.IsUpload = false;
  449. _videoInfo.Uploaded = 0;
  450. if (!App.VideoList.Exists(x => x.FileGuid == _videoInfo.FileGuid) || !App.VideoList.Exists(x => x.VideoPath == _videoInfo.VideoPath))
  451. {
  452. App.VideoList.Add(_videoInfo);
  453. //保存数据
  454. App.SaveWkData();
  455. }
  456. }
  457. catch (Exception ex)
  458. {
  459. LogHelper.WriteErrLog("录屏保存" + ex.Message, ex);
  460. }
  461. FileToolsCommon.DeleteDirectory(_temppath);
  462. }
  463. ).Start();
  464. }
  465. if (ClickStopRecordingScreen != null)
  466. {
  467. ClickStopRecordingScreen();
  468. }
  469. Hide();
  470. _srTime = Convert.ToDateTime("2020-01-01 00:00:00");
  471. TxbTime.Content = "00:00";
  472. }
  473. public void MaxToobar()
  474. {
  475. Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);
  476. float dip = graphics.DpiX;
  477. //float DIPY = graphics.DpiY;
  478. App.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.WorkingArea.Width / (dip / 96) - App.W_ScreenRecordingToolbarWindow.Width;
  479. GridSrToobar.Visibility = Visibility.Visible;
  480. App.W_ScreenRecordingToolbarWindow.Topmost = true;
  481. }
  482. #endregion 录屏
  483. #region 画笔相关
  484. /// <summary>
  485. /// 笔调用批注
  486. /// </summary>
  487. public void PenPractice()
  488. {
  489. if (flg != 11 && flg != 10)
  490. {
  491. #region 防止连击
  492. if (_isPressButton)
  493. {
  494. return;
  495. }
  496. else
  497. {
  498. _isPressButton = true;
  499. new Thread
  500. (
  501. () =>
  502. {
  503. Thread.Sleep(500);
  504. _isPressButton = false;
  505. }
  506. ).Start();
  507. }
  508. #endregion 防止连击
  509. GetTimeStamp();
  510. try
  511. {
  512. Dispatcher.Invoke
  513. (
  514. () =>
  515. {
  516. if (App.W_PracticeWindow == null)
  517. {
  518. App.W_PracticeWindow = new PracticeWindow
  519. {
  520. Width = pwidth,
  521. Height = pHeight,
  522. Left = 0,
  523. Top = 0
  524. };
  525. }
  526. App.W_PracticeWindow.Initialize(); // imagePath);
  527. flg = 11;
  528. App.W_PracticeWindow.Blue();
  529. App.W_PracticeWindow.Show();
  530. App.W_PracticeWindow.Topmost = true;
  531. App.W_PracticeWindow.Focus();
  532. }
  533. );
  534. new Thread
  535. (
  536. () =>
  537. {
  538. Dispatcher.Invoke(() => { App.W_PracticeWindow.Topmost = false; });
  539. Thread.Sleep(500);
  540. Dispatcher.Invoke(() => { Topmost = true; });
  541. }
  542. ).Start();
  543. }
  544. catch (Exception ex)
  545. {
  546. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  547. }
  548. }
  549. }
  550. /// <summary>
  551. /// 画笔点击事件
  552. /// </summary>
  553. /// <param name="sender"></param>
  554. /// <param name="e"></param>
  555. private void BtnBrush_Click(object sender, RoutedEventArgs e)
  556. {
  557. if (BtnPenBlue.Visibility != Visibility.Visible)
  558. {
  559. return;
  560. }
  561. #region 防止连击
  562. if (_isPressButton)
  563. {
  564. return;
  565. }
  566. else
  567. {
  568. _isPressButton = true;
  569. new Thread
  570. (
  571. () =>
  572. {
  573. Thread.Sleep(500);
  574. _isPressButton = false;
  575. }
  576. ).Start();
  577. }
  578. #endregion 防止连击
  579. BtnPenBlue.Visibility = Visibility.Collapsed;
  580. BtnPenRed.Visibility = Visibility.Visible;
  581. BtnPenBlue_CL.Visibility = Visibility.Visible;
  582. BtnPenRed_CL.Visibility = Visibility.Collapsed;
  583. GetTimeStamp();
  584. try
  585. {
  586. if (flg == 11)
  587. {
  588. //Dispatcher.Invoke(() =>
  589. //{
  590. // borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  591. // borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  592. //});
  593. flg = 1;
  594. //this.Owner = null;
  595. App.W_PracticeWindow.ReturnPractice();
  596. }
  597. else if (flg == 10)
  598. {
  599. //Dispatcher.Invoke(() =>
  600. //{
  601. // borOne.Background = new SolidColorBrush(Colors.LightSkyBlue);
  602. // borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  603. //});
  604. App.W_PracticeWindow.Blue();
  605. flg = 11;
  606. }
  607. else
  608. {
  609. //new Thread(new ThreadStart(new Action(() =>
  610. //{
  611. //Dispatcher.Invoke(() =>
  612. //{
  613. // borOne.Background = new SolidColorBrush(Colors.LightSkyBlue);
  614. // borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  615. //});
  616. //}))).Start();
  617. if (App.W_PracticeWindow == null)
  618. {
  619. App.W_PracticeWindow = new PracticeWindow
  620. {
  621. //APP.W_PracticeWindow.Topmost = true;
  622. Width = pwidth,
  623. Height = pHeight,
  624. Left = 0,
  625. Top = 0
  626. };
  627. //practiceWin.Owner = this;
  628. }
  629. App.W_PracticeWindow.InitTqlpPen();
  630. App.W_PracticeWindow.Initialize(); // imagePath);
  631. flg = 11;
  632. App.W_PracticeWindow.Blue();
  633. App.W_PracticeWindow.Show();
  634. new Thread
  635. (
  636. () =>
  637. {
  638. Thread.Sleep(100);
  639. Dispatcher.Invoke
  640. (
  641. () =>
  642. {
  643. //Owner = APP.W_PracticeWindow;
  644. Topmost = true;
  645. }
  646. );
  647. }
  648. ).Start();
  649. }
  650. }
  651. catch (Exception ex)
  652. {
  653. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  654. }
  655. //imgCanvas.Source = new BitmapImage(new Uri(imagePath));
  656. }
  657. /// <summary>
  658. /// 屏幕宽
  659. /// </summary>
  660. internal double pwidth = SystemParameters.PrimaryScreenWidth;
  661. /// <summary>
  662. /// 屏幕高
  663. /// </summary>
  664. internal double pHeight = SystemParameters.PrimaryScreenHeight;
  665. /// <summary>
  666. /// 获取时间戳
  667. /// </summary>
  668. /// <returns></returns>
  669. public string GetTimeStamp()
  670. {
  671. TimeSpan ts = DateTime.Now
  672. - new DateTime
  673. (
  674. 1970,
  675. 1,
  676. 1,
  677. 0,
  678. 0,
  679. 0,
  680. 0
  681. );
  682. return Convert.ToInt64(ts.TotalMilliseconds).ToString();
  683. }
  684. #endregion 画笔相关
  685. #endregion 事件
  686. /// <summary>
  687. /// 停止录屏
  688. /// </summary>
  689. public delegate void StopRecordingScreen();
  690. /// <summary>
  691. /// 停止录屏
  692. /// </summary>
  693. public event StopRecordingScreen ClickStopRecordingScreen;
  694. /// <summary>
  695. /// 红笔
  696. /// </summary>
  697. /// <param name="sender"></param>
  698. /// <param name="e"></param>
  699. private void BtnBlackPenTwo_Click(object sender, RoutedEventArgs e)
  700. {
  701. if (BtnPenRed.Visibility != Visibility.Visible)
  702. {
  703. return;
  704. }
  705. #region 防止连击
  706. if (_isPressButton)
  707. {
  708. return;
  709. }
  710. else
  711. {
  712. _isPressButton = true;
  713. new Thread
  714. (
  715. () =>
  716. {
  717. Thread.Sleep(500);
  718. _isPressButton = false;
  719. }
  720. ).Start();
  721. }
  722. #endregion 防止连击
  723. BtnPenBlue.Visibility = Visibility.Visible;
  724. BtnPenRed.Visibility = Visibility.Collapsed;
  725. BtnPenBlue_CL.Visibility = Visibility.Collapsed;
  726. BtnPenRed_CL.Visibility = Visibility.Visible;
  727. string time = GetTimeStamp();
  728. #region 录屏批注取消画笔
  729. string imagePath = Path.Combine(_temppath, time + ".jpg");
  730. ImageHelper.GetScreenshot
  731. (
  732. new Rectangle
  733. (
  734. 0,
  735. 0,
  736. 0,
  737. 0
  738. ),
  739. imagePath
  740. );
  741. #endregion 录屏批注取消画笔
  742. try
  743. {
  744. if (flg == 10)
  745. {
  746. flg = 0;
  747. App.W_PracticeWindow.ReturnPractice();
  748. }
  749. else if (flg == 11)
  750. {
  751. flg = 10;
  752. App.W_PracticeWindow.Red();
  753. }
  754. else
  755. {
  756. if (App.W_PracticeWindow == null)
  757. {
  758. App.W_PracticeWindow = new PracticeWindow
  759. {
  760. Width = pwidth,
  761. Height = pHeight,
  762. Left = 0,
  763. Top = 0
  764. };
  765. }
  766. App.W_PracticeWindow.InitTqlpPen();
  767. App.W_PracticeWindow.Initialize(); //imagePath);
  768. flg = 10;
  769. App.W_PracticeWindow.Red();
  770. App.W_PracticeWindow.Show();
  771. new Thread
  772. (
  773. () =>
  774. {
  775. Thread.Sleep(100);
  776. Dispatcher.Invoke
  777. (
  778. () =>
  779. {
  780. //Owner = APP.W_PracticeWindow;
  781. Topmost = true;
  782. }
  783. );
  784. }
  785. ).Start();
  786. }
  787. }
  788. catch (Exception ex)
  789. {
  790. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  791. }
  792. }
  793. /// <summary>
  794. /// 返回主界面
  795. /// </summary>
  796. /// <param name="sender"></param>
  797. /// <param name="e"></param>
  798. private void BtnReturn_Click(object sender, RoutedEventArgs e)
  799. {
  800. if (_state == State.Pause || _state == State.Start)
  801. {
  802. MessageBoxResult br = MessageWindow.Show
  803. (
  804. "退出将结束并保存录制,是否继续?",
  805. "提示",
  806. MessageBoxButton.OKCancel
  807. );
  808. if (br == MessageBoxResult.Cancel)
  809. {
  810. return;
  811. }
  812. BtnStopRecordingScreen_Click(null, null);
  813. }
  814. App.W_XHMicroLessonSystemWindow.InitializeKeyDownEvent();
  815. //APP.W_XHMicroLessonSystemWindow.InitPen();
  816. App.W_XHMicroLessonSystemWindow.InitTqlpPen();
  817. App.W_XHMicroLessonSystemWindow.Show();
  818. new Thread
  819. (
  820. () =>
  821. {
  822. Thread.Sleep(700);
  823. Dispatcher.Invoke
  824. (
  825. () =>
  826. {
  827. if (App.W_MinToolbar != null)
  828. {
  829. App.W_MinToolbar.Hide();
  830. }
  831. }
  832. );
  833. }
  834. ).Start();
  835. Hide();
  836. }
  837. /// <summary>
  838. /// 修改笔状态
  839. /// </summary>
  840. public void ModifyState()
  841. {
  842. BtnPenBlue.Visibility = Visibility.Visible;
  843. BtnPenRed.Visibility = Visibility.Visible;
  844. BtnPenBlue_CL.Visibility = Visibility.Collapsed;
  845. BtnPenRed_CL.Visibility = Visibility.Collapsed;
  846. }
  847. private void gridToobarTwo_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
  848. {
  849. //if (BtnRecordingScreen.ToolTip.ToString().Equals("暂停") && (gridToobar.Visibility == Visibility.Visible || BorderBlack.Visibility == Visibility.Visible))
  850. if (BtnRecordingScreenPause.Visibility == Visibility.Visible)
  851. {
  852. if (App.IsHideSRTool)
  853. {
  854. if (App.W_MinToolbar == null)
  855. {
  856. App.W_MinToolbar = new MinToolbar();
  857. }
  858. App.W_MinToolbar.Topmost = true;
  859. double minToolTop = Top;
  860. new Thread
  861. (
  862. () =>
  863. {
  864. Thread.Sleep(500);
  865. Dispatcher.Invoke
  866. (
  867. () =>
  868. {
  869. MouseEventCommon.GetCursorPos(out MouseEventCommon.POINT pointRecord);
  870. if (pointRecord.X >= this.Left && pointRecord.X < this.Left + this.ActualWidth && pointRecord.Y >= this.Top && pointRecord.Y < this.Top + this.ActualHeight)
  871. {
  872. //LblMessage.Content = "在区域内:("+ pointRecord.X+","+pointRecord.Y+") ("+ Left + ","+Top+")";
  873. }
  874. else
  875. {
  876. //LblMessage.Content = "不在区域内:(" + pointRecord.X + "," + pointRecord.Y + ") (" + Left + "," + Top + ")";
  877. App.W_MinToolbar.Initialize(minToolTop, ActualHeight);
  878. GridSrToobar.Visibility = Visibility.Hidden;
  879. App.W_MinToolbar.Show();
  880. }
  881. }
  882. );
  883. }
  884. ).Start();
  885. }
  886. }
  887. }
  888. }
  889. }