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