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

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