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

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