星火微课系统客户端
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

ScreenRecordingToolbarWindow.xaml.cs 41KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192
  1. using Common.system;
  2. using NAudio.Wave;
  3. using NReco.VideoConverter;
  4. using System;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Threading;
  8. using System.Windows;
  9. using System.Windows.Forms;
  10. using System.Windows.Ink;
  11. using System.Windows.Interop;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Threading;
  15. using XHWK.Model;
  16. using XHWK.WKTool.Utils;
  17. namespace XHWK.WKTool
  18. {
  19. /// <summary>
  20. /// 录屏工具栏
  21. /// </summary>
  22. public partial class ScreenRecordingToolbarWindow : Window
  23. {
  24. #region 初始变量
  25. /// <summary>
  26. /// 视频保存名称
  27. /// </summary>
  28. private string VideoSavePathName;
  29. /// <summary>
  30. /// 临时视频路径
  31. /// </summary>
  32. private string TempVideoPathName;
  33. /// <summary>
  34. /// 临时麦克风路径
  35. /// </summary>
  36. private string TempAudioPathName1;
  37. /// <summary>
  38. /// 临时扬声器路径
  39. /// </summary>
  40. private string TempAudioPathName2;
  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. blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  115. drawingAttributes.FitToCurve = true;
  116. //隐藏画笔工具栏
  117. BtnRecordingScreen.Visibility = Visibility.Visible;
  118. BtnRecordingScreenPause.Visibility = Visibility.Collapsed;
  119. BtnStopRecordingScreen.IsEnabled = false; //停止录制按钮不点击
  120. BtnPenBlue.IsEnabled = false;//蓝笔不可点击
  121. BtnPenRed.IsEnabled = false;//红笔不可点击
  122. BtnPenBlue.Visibility = Visibility.Visible;
  123. BtnPenRed.Visibility = Visibility.Visible;
  124. BtnPenBlue_CL.Visibility = Visibility.Collapsed;
  125. BtnPenRed_CL.Visibility = Visibility.Collapsed;
  126. TxbTime.Content = "00:00";
  127. }
  128. private void K_hook_KeyDownEvent(object sender, System.Windows.Forms.KeyEventArgs e)
  129. {
  130. if (e.KeyValue == (int)System.Windows.Forms.Keys.F5 && (int)Control.ModifierKeys == (int)Keys.Control)
  131. {
  132. //开始,暂停
  133. BtnRecordingScreen_Click(null, null);
  134. }
  135. if (e.KeyValue == (int)Keys.S && (int)Control.ModifierKeys == (int)Keys.Control)
  136. {
  137. //结束
  138. BtnStopRecordingScreen_Click(null, null);
  139. }
  140. }
  141. #endregion 初始化
  142. #region 事件
  143. private DateTime SRTime = Convert.ToDateTime("2020-01-01 00:00:00");
  144. /// <summary>
  145. /// 时钟回调
  146. /// </summary>
  147. /// <param name="sender"></param>
  148. /// <param name="e"></param>
  149. private void OnTimer(object sender, EventArgs e)
  150. {
  151. if (_state == State.Start)
  152. {
  153. SRTime = SRTime.AddMilliseconds(1000);
  154. }
  155. if (SRTime.Hour > 0)
  156. {
  157. TxbTime.Content = SRTime.ToString("HH:mm:ss");
  158. }
  159. else
  160. {
  161. TxbTime.Content = SRTime.ToString("mm:ss");
  162. }
  163. }
  164. /// <summary>
  165. /// 结束
  166. /// </summary>
  167. /// <param name="sender"></param>
  168. /// <param name="e"></param>
  169. private void End()
  170. {
  171. _state = State.End;
  172. }
  173. #region 录屏
  174. /// <summary>
  175. /// 设置录屏文件地址
  176. /// </summary>
  177. private void SetUpVideoPathName()
  178. {
  179. string fileType = ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
  180. FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  181. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temprs/");
  182. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏." + fileType;
  183. int num = 1;
  184. while (FileToolsCommon.IsExistFile(VideoSavePathName))
  185. {
  186. num++;
  187. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏_" + num + "." + fileType;
  188. }
  189. TempVideoPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏_" + num + ".avi";
  190. TempAudioPathName1 = APP.WKData.WkPath + APP.WKData.WkName + "_录屏_" + num + "_1.mp3" ;
  191. TempAudioPathName2 = APP.WKData.WkPath + APP.WKData.WkName + "_录屏_" + num + "_2.mp3";
  192. }
  193. /// <summary>
  194. /// 是否已经按下按钮
  195. /// </summary>
  196. private bool IsPressButton = false;
  197. //录制麦克风的声音
  198. ZAudioRecordHelper helper1 = null;
  199. //录制扬声器的声音
  200. ZAudioRecordHelper helper2 = null;
  201. //桌面录制
  202. ZVideoRecordHelper helper3 = null;
  203. public IntPtr winHandle;// 当前窗体指针
  204. /// <summary>
  205. /// 开始或暂停录制
  206. /// </summary>
  207. /// <param name="sender"></param>
  208. /// <param name="e"></param>
  209. private void BtnRecordingScreen_Click(object sender, RoutedEventArgs e)
  210. {
  211. #region 防止连击
  212. if (IsPressButton)
  213. {
  214. return;
  215. }
  216. else
  217. {
  218. IsPressButton = true;
  219. new Thread(new ThreadStart(new Action(() =>
  220. {
  221. Thread.Sleep(500);
  222. IsPressButton = false;
  223. }))).Start();
  224. }
  225. #endregion 防止连击
  226. if (_state == State.End)
  227. {
  228. SRTime = Convert.ToDateTime("2020-01-01 00:00:00");
  229. TxbTime.Content = "00:00";
  230. if (t == null)
  231. {
  232. t = new DispatcherTimer();
  233. t.Tick += OnTimer;
  234. t.Interval = new TimeSpan(0, 0, 0, 0, 1000);
  235. t.IsEnabled = true;
  236. t.Start();
  237. }
  238. else {
  239. t.Interval = new TimeSpan(0, 0, 0, 0, 1000);
  240. }
  241. _state = State.Loading;
  242. #region 检测麦克风扬声器是否可用
  243. //string AudioPath = FileToolsCommon.GetFileAbsolutePath("/temp/audio/");
  244. //FileToolsCommon.CreateDirectory(AudioPath);
  245. //string audioSpeakerPath = AudioPath + "adoS" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".m";
  246. //string audioMicrophonePath = AudioPath + "adoM" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".m";
  247. //try
  248. //{
  249. // FileToolsCommon.DeleteFile(audioSpeakerPath);
  250. // FileToolsCommon.DeleteFile(audioMicrophonePath);
  251. //}
  252. //catch (Exception)
  253. //{
  254. //}
  255. //扬声器
  256. //if (APP.FFmpeg.StartRecordSpeakerAudio(audioSpeakerPath))
  257. //{
  258. // APP.FFmpeg.StopRecordAudio(2);
  259. // //麦克风
  260. // if (APP.FFmpeg.StartRecordAudio(audioMicrophonePath))
  261. // {
  262. // }
  263. // else
  264. // {
  265. // //无法录制麦克风
  266. // MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制麦克风,是否继续?", "消息提示", MessageBoxButton.OKCancel);
  267. // if (Res == MessageBoxResult.Cancel)
  268. // {
  269. // return;
  270. // }
  271. // }
  272. // APP.FFmpeg.StopRecordAudio(1);
  273. //}
  274. //else
  275. //{
  276. // //无法录制扬声器音频
  277. // MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制音频,是否继续?", "消息提示", MessageBoxButton.OKCancel);
  278. // if (Res == MessageBoxResult.Cancel)
  279. // {
  280. // return;
  281. // }
  282. //}
  283. #endregion 检测麦克风扬声器是否可用
  284. VideoInfo = new Model_Video
  285. {
  286. VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType")),
  287. WkType = Enum_WKVidetype.RecordingScreen
  288. };
  289. SetUpVideoPathName();
  290. k_hook.Start();//安装键盘钩子
  291. //if (APP.W_CountdownWindow == null)
  292. //{
  293. // APP.W_CountdownWindow = new CountdownWindow();
  294. // APP.W_CountdownWindow.Initialize(true, 1800);
  295. //}
  296. //else
  297. //{
  298. // APP.W_CountdownWindow.Initialize(true, 1800);
  299. //}
  300. //APP.W_CountdownWindow.Show();
  301. BtnRecordingScreen.Visibility = Visibility.Collapsed;
  302. BtnRecordingScreenPause.Visibility = Visibility.Visible;
  303. BtnStopRecordingScreen.IsEnabled = true; //停止录制按钮可点击
  304. BtnPenBlue.IsEnabled = true;//蓝笔可点击
  305. BtnPenRed.IsEnabled = true;//红笔可点击
  306. BtnPenBlue.Visibility = Visibility.Visible;
  307. BtnPenRed.Visibility = Visibility.Visible;
  308. BtnPenBlue_CL.Visibility = Visibility.Collapsed;
  309. BtnPenRed_CL.Visibility = Visibility.Collapsed;
  310. TxbTime.Visibility = Visibility.Visible;//时间显示
  311. #region 隐藏工具栏
  312. if (APP.IsHideSRTool)
  313. {
  314. if (APP.W_MinToolbar == null)
  315. {
  316. APP.W_MinToolbar = new MinToolbar();
  317. }
  318. APP.W_MinToolbar.Topmost = true;
  319. double MinToolTop = Top;
  320. GridSrToobar.Visibility = Visibility.Hidden;
  321. APP.W_MinToolbar.Initialize(MinToolTop, ActualHeight);
  322. APP.W_MinToolbar.Show();
  323. }
  324. #endregion 隐藏工具栏
  325. helper1 = new ZAudioRecordHelper(TempAudioPathName1, ZAudioRecordHelper.RecordType.microphone);
  326. helper2 = new ZAudioRecordHelper(TempAudioPathName2, ZAudioRecordHelper.RecordType.loudspeaker);
  327. helper1.StartRecordAudio();
  328. helper2.StartRecordAudio();
  329. winHandle = new WindowInteropHelper(this).Handle;
  330. var curScreen = Screen.FromHandle(winHandle);
  331. int RecordWidth = curScreen.Bounds.Width;
  332. int RecordHeight = curScreen.Bounds.Height;
  333. helper3 = new ZVideoRecordHelper(TempVideoPathName, RecordWidth, RecordHeight);
  334. helper3.StartRecordVideo();
  335. _state = State.Start;
  336. Console.WriteLine("TempAudioPathName1:"+ TempAudioPathName1);
  337. Console.WriteLine("TempAudioPathName2:" + TempAudioPathName2);
  338. Console.WriteLine("TempVideoPathName:" + TempVideoPathName);
  339. }
  340. else if (_state == State.Start)
  341. {
  342. _state = State.Pause;
  343. helper1.PauseRecordAudio();
  344. helper2.PauseRecordAudio();
  345. helper3.PauseRecordVideo();
  346. }
  347. else if (_state == State.Pause) {
  348. _state = State.Start;
  349. helper1.ResumeRecordAudio();
  350. helper2.ResumeRecordAudio();
  351. helper3.ResumeRecordVideo();
  352. }
  353. }
  354. /// <summary>
  355. /// 停止录像
  356. /// </summary>
  357. /// <param name="sender"></param>
  358. /// <param name="e"></param>
  359. private void BtnStopRecordingScreen_Click(object sender, RoutedEventArgs e)
  360. {
  361. #region 防止连击
  362. if (IsPressButton)
  363. {
  364. return;
  365. }
  366. else
  367. {
  368. IsPressButton = true;
  369. new Thread(new ThreadStart(new Action(() =>
  370. {
  371. Thread.Sleep(500);
  372. IsPressButton = false;
  373. }))).Start();
  374. }
  375. #endregion 防止连击
  376. BtnRecordingScreen.ToolTip = "开始";
  377. k_hook.Stop();
  378. TxbTime.Content = "00:00";
  379. if (APP.W_PracticeWindow != null)
  380. {
  381. if (APP.W_PracticeWindow.Visibility == Visibility.Visible)
  382. {
  383. Owner = null;
  384. APP.W_PracticeWindow.ReturnPractice();
  385. }
  386. }
  387. if (APP.W_XHMicroLessonSystemWindow == null)
  388. {
  389. APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
  390. }
  391. APP.W_XHMicroLessonSystemWindow.InitializeKeyDownEvent();
  392. APP.W_XHMicroLessonSystemWindow.InitPen();
  393. APP.W_XHMicroLessonSystemWindow.InitTQLPPen();
  394. APP.W_XHMicroLessonSystemWindow.Show();
  395. if (_state == State.Pause || _state == State.Start) {
  396. t.Stop();
  397. t = null;
  398. Console.WriteLine("停止录制");
  399. helper1.StopRecordAudio();
  400. helper2.StopRecordAudio();
  401. helper3.StopRecordVideo();
  402. FFMpegConverter ffMpeg = new FFMpegConverter();
  403. FFMpegInput[] input = new FFMpegInput[] {
  404. new FFMpegInput(TempVideoPathName),
  405. new FFMpegInput(TempAudioPathName1),
  406. new FFMpegInput(TempAudioPathName1),
  407. };
  408. // 多路音频混音
  409. ffMpeg.ConvertMedia(
  410. input,
  411. VideoSavePathName,
  412. "mp4",
  413. new OutputSettings()
  414. {
  415. CustomOutputArgs = "-filter_complex amix=inputs=2:duration=first:dropout_transition=2"
  416. }
  417. );
  418. //生成缩略图
  419. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  420. FileToolsCommon.CreateDirectory(ThumbnailPath);
  421. //缩略图存储位置
  422. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileName(VideoSavePathName).Replace(".", "") + ".JPG";
  423. new Thread(new ThreadStart(new Action(() =>
  424. {
  425. FileToolsCommon.DeleteFile(ThumbnailPathName);
  426. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  427. VideoInfo.VideoPath = VideoSavePathName;
  428. VideoInfo.ThumbnailPath = ThumbnailPathName;
  429. APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName, 200, 130);
  430. VideoInfo.FileGuid = Guid.NewGuid().ToString();
  431. VideoInfo.IsUpload = false;
  432. VideoInfo.Uploaded = 0;
  433. if (!APP.VideoList.Exists(x => x.FileGuid == VideoInfo.FileGuid) || !APP.VideoList.Exists(x => x.VideoPath == VideoInfo.VideoPath))
  434. {
  435. APP.VideoList.Add(VideoInfo);
  436. //保存数据
  437. APP.SaveWkData();
  438. }
  439. FileToolsCommon.DeleteFile(TempAudioPathName1);
  440. FileToolsCommon.DeleteFile(TempAudioPathName2);
  441. FileToolsCommon.DeleteFile(TempVideoPathName);
  442. }))).Start();
  443. Click_stopRecordingScreen();
  444. }
  445. Hide();
  446. End();
  447. }
  448. public void MaxToobar()
  449. {
  450. Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);
  451. float DIP = graphics.DpiX;
  452. //float DIPY = graphics.DpiY;
  453. APP.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.WorkingArea.Width / (DIP / 96) - APP.W_ScreenRecordingToolbarWindow.Width;
  454. GridSrToobar.Visibility = Visibility.Visible;
  455. APP.W_ScreenRecordingToolbarWindow.Topmost = true;
  456. }
  457. #endregion 录屏
  458. #region 画笔相关
  459. /// <summary>
  460. /// 画笔工具栏关闭事件
  461. /// </summary>
  462. /// <param name="sender"></param>
  463. /// <param name="e"></param>
  464. private void BtnToolbarDown_Click(object sender, RoutedEventArgs e)
  465. {
  466. gridToolbar.Visibility = Visibility.Hidden;
  467. gridColour.Visibility = Visibility.Hidden;
  468. gridThickness.Visibility = Visibility.Hidden;
  469. APP.W_PracticeWindow.Hide();
  470. }
  471. /// <summary>
  472. /// 笔调用批注
  473. /// </summary>
  474. public void PenPractice()
  475. {
  476. if (flg != 11 && flg != 10)
  477. {
  478. #region 防止连击
  479. if (IsPressButton)
  480. {
  481. return;
  482. }
  483. else
  484. {
  485. IsPressButton = true;
  486. new Thread(new ThreadStart(new Action(() =>
  487. {
  488. Thread.Sleep(500);
  489. IsPressButton = false;
  490. }))).Start();
  491. }
  492. #endregion 防止连击
  493. string time = GetTimeStamp();
  494. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  495. if (!Directory.Exists(tempPath))
  496. {
  497. Directory.CreateDirectory(tempPath);
  498. }
  499. try
  500. {
  501. Dispatcher.Invoke(() =>
  502. {
  503. //borOne.Background = new SolidColorBrush(Colors.LightSkyBlue);
  504. //borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  505. if (APP.W_PracticeWindow == null)
  506. {
  507. APP.W_PracticeWindow = new PracticeWindow
  508. {
  509. Width = pwidth,
  510. Height = pHeight,
  511. Left = 0,
  512. Top = 0
  513. };
  514. //practiceWin.Owner = this;
  515. }
  516. //APP.W_PracticeWindow.InitPen();
  517. //APP.W_PracticeWindow.InitTQLPPen();
  518. APP.W_PracticeWindow.Initialize();// imagePath);
  519. flg = 11;
  520. APP.W_PracticeWindow.Blue();
  521. APP.W_PracticeWindow.Show();
  522. APP.W_PracticeWindow.Topmost = true;
  523. APP.W_PracticeWindow.Focus();
  524. });
  525. new Thread(new ThreadStart(new Action(() =>
  526. {
  527. Dispatcher.Invoke(() =>
  528. {
  529. APP.W_PracticeWindow.Topmost = false;
  530. });
  531. Thread.Sleep(500);
  532. Dispatcher.Invoke(() =>
  533. {
  534. //Owner = APP.W_PracticeWindow;
  535. Topmost = true;
  536. });
  537. }))).Start();
  538. }
  539. catch (Exception ex)
  540. {
  541. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  542. }
  543. }
  544. }
  545. /// <summary>
  546. /// 画笔点击事件
  547. /// </summary>
  548. /// <param name="sender"></param>
  549. /// <param name="e"></param>
  550. private void BtnBrush_Click(object sender, RoutedEventArgs e)
  551. {
  552. if (BtnPenBlue.Visibility != Visibility.Visible)
  553. {
  554. return;
  555. }
  556. #region 防止连击
  557. if (IsPressButton)
  558. {
  559. return;
  560. }
  561. else
  562. {
  563. IsPressButton = true;
  564. new Thread(new ThreadStart(new Action(() =>
  565. {
  566. Thread.Sleep(500);
  567. IsPressButton = false;
  568. }))).Start();
  569. }
  570. #endregion 防止连击
  571. BtnPenBlue.Visibility = Visibility.Collapsed;
  572. BtnPenRed.Visibility = Visibility.Visible;
  573. BtnPenBlue_CL.Visibility = Visibility.Visible;
  574. BtnPenRed_CL.Visibility = Visibility.Collapsed;
  575. string time = GetTimeStamp();
  576. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  577. if (!Directory.Exists(tempPath))
  578. {
  579. Directory.CreateDirectory(tempPath);
  580. }
  581. #region 录屏批注取消画笔
  582. //string imagePath = Path.Combine(tempPath, time + ".jpg");
  583. //ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  584. #endregion 录屏批注取消画笔
  585. try
  586. {
  587. if (flg == 11)
  588. {
  589. //Dispatcher.Invoke(() =>
  590. //{
  591. // borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  592. // borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  593. //});
  594. flg = 1;
  595. //this.Owner = null;
  596. APP.W_PracticeWindow.ReturnPractice();
  597. }
  598. else if (flg == 10)
  599. {
  600. //Dispatcher.Invoke(() =>
  601. //{
  602. // borOne.Background = new SolidColorBrush(Colors.LightSkyBlue);
  603. // borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  604. //});
  605. APP.W_PracticeWindow.Blue();
  606. flg = 11;
  607. }
  608. else
  609. {
  610. //new Thread(new ThreadStart(new Action(() =>
  611. //{
  612. //Dispatcher.Invoke(() =>
  613. //{
  614. // borOne.Background = new SolidColorBrush(Colors.LightSkyBlue);
  615. // borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  616. //});
  617. //}))).Start();
  618. if (APP.W_PracticeWindow == null)
  619. {
  620. APP.W_PracticeWindow = new PracticeWindow
  621. {
  622. //APP.W_PracticeWindow.Topmost = true;
  623. Width = pwidth,
  624. Height = pHeight,
  625. Left = 0,
  626. Top = 0
  627. };
  628. //practiceWin.Owner = this;
  629. }
  630. APP.W_PracticeWindow.InitPen();
  631. APP.W_PracticeWindow.InitTQLPPen();
  632. APP.W_PracticeWindow.Initialize();// imagePath);
  633. flg = 11;
  634. APP.W_PracticeWindow.Blue();
  635. APP.W_PracticeWindow.Show();
  636. new Thread(new ThreadStart(new Action(() =>
  637. {
  638. Thread.Sleep(100);
  639. Dispatcher.Invoke(() =>
  640. {
  641. //Owner = APP.W_PracticeWindow;
  642. Topmost = true;
  643. });
  644. }))).Start();
  645. }
  646. }
  647. catch (Exception ex)
  648. {
  649. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  650. }
  651. //imgCanvas.Source = new BitmapImage(new Uri(imagePath));
  652. }
  653. /// <summary>
  654. /// 屏幕宽
  655. /// </summary>
  656. internal double pwidth = SystemParameters.PrimaryScreenWidth;
  657. /// <summary>
  658. /// 屏幕高
  659. /// </summary>
  660. internal double pHeight = SystemParameters.PrimaryScreenHeight;
  661. /// <summary>
  662. /// 获取时间戳
  663. /// </summary>
  664. /// <returns></returns>
  665. public string GetTimeStamp()
  666. {
  667. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  668. return Convert.ToInt64(ts.TotalMilliseconds).ToString();
  669. }
  670. /// <summary>
  671. /// 画笔粗细事件
  672. /// </summary>
  673. /// <param name="sender"></param>
  674. /// <param name="e"></param>
  675. private void BtnThickness_Click(object sender, RoutedEventArgs e)
  676. {
  677. gridThickness.Visibility = Visibility.Visible;
  678. gridColour.Visibility = Visibility.Collapsed;
  679. }
  680. /// <summary>
  681. /// 画笔颜色事件
  682. /// </summary>
  683. /// <param name="sender"></param>
  684. /// <param name="e"></param>
  685. private void BtnColour_Click(object sender, RoutedEventArgs e)
  686. {
  687. gridColour.Visibility = Visibility.Visible;
  688. gridThickness.Visibility = Visibility.Collapsed;
  689. }
  690. /// <summary>
  691. /// 白色
  692. /// </summary>
  693. /// <param name="sender"></param>
  694. /// <param name="e"></param>
  695. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  696. {
  697. //drawingAttributes.Color = Colors.White;
  698. APP.W_PracticeWindow.White();
  699. gridColour.Visibility = Visibility.Collapsed;
  700. gridThickness.Visibility = Visibility.Collapsed;
  701. }
  702. /// <summary>
  703. /// 红色
  704. /// </summary>
  705. /// <param name="sender"></param>
  706. /// <param name="e"></param>
  707. private void BtnRed_Click(object sender, RoutedEventArgs e)
  708. {
  709. //drawingAttributes.Color = Colors.Red;
  710. APP.W_PracticeWindow.Red();
  711. gridColour.Visibility = Visibility.Collapsed;
  712. gridThickness.Visibility = Visibility.Collapsed;
  713. }
  714. /// <summary>
  715. /// 黄色
  716. /// </summary>
  717. /// <param name="sender"></param>
  718. /// <param name="e"></param>
  719. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  720. {
  721. //drawingAttributes.Color = Colors.Gold;
  722. APP.W_PracticeWindow.Yellow();
  723. gridColour.Visibility = Visibility.Collapsed;
  724. gridThickness.Visibility = Visibility.Collapsed;
  725. }
  726. /// <summary>
  727. /// 青色
  728. /// </summary>
  729. /// <param name="sender"></param>
  730. /// <param name="e"></param>
  731. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  732. {
  733. //drawingAttributes.Color = Colors.LimeGreen;
  734. APP.W_PracticeWindow.CyanBlue();
  735. gridColour.Visibility = Visibility.Collapsed;
  736. gridThickness.Visibility = Visibility.Collapsed;
  737. }
  738. /// <summary>
  739. /// 灰色
  740. /// </summary>
  741. /// <param name="sender"></param>
  742. /// <param name="e"></param>
  743. private void BtnGray_Click(object sender, RoutedEventArgs e)
  744. {
  745. //drawingAttributes.Color = Colors.Gray;
  746. APP.W_PracticeWindow.Gray();
  747. gridColour.Visibility = Visibility.Collapsed;
  748. gridThickness.Visibility = Visibility.Collapsed;
  749. }
  750. /// <summary>
  751. /// 蓝色
  752. /// </summary>
  753. /// <param name="sender"></param>
  754. /// <param name="e"></param>
  755. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  756. {
  757. //drawingAttributes.Color = Colors.DeepSkyBlue;
  758. APP.W_PracticeWindow.Blue();
  759. gridColour.Visibility = Visibility.Collapsed;
  760. gridThickness.Visibility = Visibility.Collapsed;
  761. }
  762. /// <summary>
  763. /// 画笔 细
  764. /// </summary>
  765. /// <param name="sender"></param>
  766. /// <param name="e"></param>
  767. private void BtnFine_Click(object sender, RoutedEventArgs e)
  768. {
  769. APP.W_PracticeWindow.Fine();
  770. gridColour.Visibility = Visibility.Collapsed;
  771. gridThickness.Visibility = Visibility.Collapsed;
  772. }
  773. /// <summary>
  774. /// 画笔 中
  775. /// </summary>
  776. /// <param name="sender"></param>
  777. /// <param name="e"></param>
  778. private void BtnIn_Click(object sender, RoutedEventArgs e)
  779. {
  780. APP.W_PracticeWindow.In();
  781. gridColour.Visibility = Visibility.Collapsed;
  782. gridThickness.Visibility = Visibility.Collapsed;
  783. }
  784. /// <summary>
  785. /// 画笔粗
  786. /// </summary>
  787. /// <param name="sender"></param>
  788. /// <param name="e"></param>
  789. private void BtnCrude_Click(object sender, RoutedEventArgs e)
  790. {
  791. APP.W_PracticeWindow.Crude();
  792. gridColour.Visibility = Visibility.Collapsed;
  793. gridThickness.Visibility = Visibility.Collapsed;
  794. }
  795. /// <summary>
  796. /// 橡皮
  797. /// </summary>
  798. /// <param name="sender"></param>
  799. /// <param name="e"></param>
  800. private void BtnEraser_Click(object sender, RoutedEventArgs e)
  801. {
  802. APP.W_PracticeWindow.Eraser();
  803. }
  804. /// <summary>
  805. /// 🖊
  806. /// </summary>
  807. /// <param name="sender"></param>
  808. /// <param name="e"></param>
  809. private void BtnPen_Click(object sender, RoutedEventArgs e)
  810. {
  811. APP.W_PracticeWindow.Pen();
  812. }
  813. /// <summary>
  814. /// ⚪
  815. /// </summary>
  816. /// <param name="sender"></param>
  817. /// <param name="e"></param>
  818. private void BtnRound_Click(object sender, RoutedEventArgs e)
  819. {
  820. APP.W_PracticeWindow.Round();
  821. }
  822. /// <summary>
  823. /// 矩形
  824. /// </summary>
  825. /// <param name="sender"></param>
  826. /// <param name="e"></param>
  827. private void BtnRectangle_Click(object sender, RoutedEventArgs e)
  828. {
  829. APP.W_PracticeWindow.Rectangle();
  830. }
  831. #endregion 画笔相关
  832. #endregion 事件
  833. /// <summary>
  834. /// 停止录屏
  835. /// </summary>
  836. public delegate void StopRecordingScreen();
  837. /// <summary>
  838. /// 停止录屏
  839. /// </summary>
  840. public event StopRecordingScreen Click_stopRecordingScreen;
  841. /// <summary>
  842. /// 移动工具栏
  843. /// </summary>
  844. /// <param name="sender"></param>
  845. /// <param name="e"></param>
  846. private void Grid_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  847. {
  848. DragMove();
  849. }
  850. /// <summary>
  851. /// 红笔
  852. /// </summary>
  853. /// <param name="sender"></param>
  854. /// <param name="e"></param>
  855. private void BtnBlackPenTwo_Click(object sender, RoutedEventArgs e)
  856. {
  857. if (BtnPenRed.Visibility != Visibility.Visible)
  858. {
  859. return;
  860. }
  861. #region 防止连击
  862. if (IsPressButton)
  863. {
  864. return;
  865. }
  866. else
  867. {
  868. IsPressButton = true;
  869. new Thread(new ThreadStart(new Action(() =>
  870. {
  871. Thread.Sleep(500);
  872. IsPressButton = false;
  873. }))).Start();
  874. }
  875. #endregion 防止连击
  876. BtnPenBlue.Visibility = Visibility.Visible;
  877. BtnPenRed.Visibility = Visibility.Collapsed;
  878. BtnPenBlue_CL.Visibility = Visibility.Collapsed;
  879. BtnPenRed_CL.Visibility = Visibility.Visible;
  880. string time = GetTimeStamp();
  881. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  882. if (!Directory.Exists(tempPath))
  883. {
  884. Directory.CreateDirectory(tempPath);
  885. }
  886. #region 录屏批注取消画笔
  887. string imagePath = Path.Combine(tempPath, time + ".jpg");
  888. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  889. #endregion 录屏批注取消画笔
  890. try
  891. {
  892. if (flg == 10)
  893. {
  894. flg = 0;
  895. APP.W_PracticeWindow.ReturnPractice();
  896. }
  897. else if (flg == 11)
  898. {
  899. flg = 10;
  900. APP.W_PracticeWindow.Red();
  901. }
  902. else
  903. {
  904. if (APP.W_PracticeWindow == null)
  905. {
  906. APP.W_PracticeWindow = new PracticeWindow
  907. {
  908. Width = pwidth,
  909. Height = pHeight,
  910. Left = 0,
  911. Top = 0
  912. };
  913. }
  914. APP.W_PracticeWindow.InitPen();
  915. APP.W_PracticeWindow.InitTQLPPen();
  916. APP.W_PracticeWindow.Initialize();//imagePath);
  917. flg = 10;
  918. APP.W_PracticeWindow.Red();
  919. APP.W_PracticeWindow.Show();
  920. new Thread(new ThreadStart(new Action(() =>
  921. {
  922. Thread.Sleep(100);
  923. Dispatcher.Invoke(() =>
  924. {
  925. //Owner = APP.W_PracticeWindow;
  926. Topmost = true;
  927. });
  928. }))).Start();
  929. }
  930. }
  931. catch (Exception ex)
  932. {
  933. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  934. }
  935. }
  936. /// <summary>
  937. /// 返回主界面
  938. /// </summary>
  939. /// <param name="sender"></param>
  940. /// <param name="e"></param>
  941. private void BtnReturn_Click(object sender, RoutedEventArgs e)
  942. {
  943. if (_state==State.Pause || _state == State.Start)
  944. {
  945. MessageBoxResult br = MessageWindow.Show("退出将取消保存当前录屏,是否继续?", "提示", MessageBoxButton.OKCancel);
  946. if (br == MessageBoxResult.Cancel)
  947. {
  948. return;
  949. }
  950. k_hook.Stop();
  951. BtnRecordingScreen.ToolTip = "开始";
  952. TxbTime.Content = "00:00";
  953. End();
  954. APP.W_PracticeWindow.ReturnPractice();
  955. if (APP.W_PracticeWindow != null)
  956. {
  957. if (APP.W_PracticeWindow.Visibility == Visibility.Visible)
  958. {
  959. APP.W_PracticeWindow.Hide();
  960. }
  961. }
  962. if (gridToolbar.Visibility == Visibility.Visible)
  963. {
  964. gridToolbar.Visibility = Visibility.Hidden;
  965. gridColour.Visibility = Visibility.Hidden;
  966. gridThickness.Visibility = Visibility.Hidden;
  967. }
  968. if (APP.W_XHMicroLessonSystemWindow == null)
  969. {
  970. APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
  971. }
  972. try
  973. {
  974. try
  975. {
  976. APP.FFmpeg.SuspendFFmpeg();
  977. }
  978. catch (Exception ex)
  979. {
  980. LogHelper.WriteErrLog("【录屏返回】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  981. }
  982. new Thread(new ThreadStart(new Action(() =>
  983. {
  984. VideoInfo = null;
  985. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temprs/");
  986. }))).Start();
  987. }
  988. catch (Exception ex)
  989. {
  990. LogHelper.WriteErrLog("【录屏返回】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  991. }
  992. }
  993. APP.W_XHMicroLessonSystemWindow.InitializeKeyDownEvent();
  994. APP.W_XHMicroLessonSystemWindow.InitPen();
  995. APP.W_XHMicroLessonSystemWindow.InitTQLPPen();
  996. APP.W_XHMicroLessonSystemWindow.Show();
  997. new Thread(new ThreadStart(new Action(() =>
  998. {
  999. Thread.Sleep(700);
  1000. Dispatcher.Invoke(() =>
  1001. {
  1002. if (APP.W_MinToolbar != null)
  1003. {
  1004. APP.W_MinToolbar.Hide();
  1005. }
  1006. });
  1007. }))).Start();
  1008. Hide();
  1009. }
  1010. /// <summary>
  1011. /// 修改笔状态
  1012. /// </summary>
  1013. public void ModifyState()
  1014. {
  1015. BtnPenBlue.Visibility = Visibility.Visible;
  1016. BtnPenRed.Visibility = Visibility.Visible;
  1017. BtnPenBlue_CL.Visibility = Visibility.Collapsed;
  1018. BtnPenRed_CL.Visibility = Visibility.Collapsed;
  1019. }
  1020. private void gridToobarTwo_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
  1021. {
  1022. //if (BtnRecordingScreen.ToolTip.ToString().Equals("暂停") && (gridToobar.Visibility == Visibility.Visible || BorderBlack.Visibility == Visibility.Visible))
  1023. if (BtnRecordingScreenPause.Visibility == Visibility.Visible)
  1024. {
  1025. if (APP.IsHideSRTool)
  1026. {
  1027. if (APP.W_MinToolbar == null)
  1028. {
  1029. APP.W_MinToolbar = new MinToolbar();
  1030. }
  1031. APP.W_MinToolbar.Topmost = true;
  1032. double MinToolTop = Top;
  1033. new Thread(new ThreadStart(new Action(() =>
  1034. {
  1035. Thread.Sleep(500);
  1036. Dispatcher.Invoke(() =>
  1037. {
  1038. MouseEventCommon.GetCursorPos(out MouseEventCommon.POINT pointRecord);
  1039. if (pointRecord.X >= this.Left && pointRecord.X < this.Left + this.ActualWidth && pointRecord.Y >= this.Top && pointRecord.Y < this.Top + this.ActualHeight)
  1040. {
  1041. //LblMessage.Content = "在区域内:("+ pointRecord.X+","+pointRecord.Y+") ("+ Left + ","+Top+")";
  1042. }
  1043. else
  1044. {
  1045. //LblMessage.Content = "不在区域内:(" + pointRecord.X + "," + pointRecord.Y + ") (" + Left + "," + Top + ")";
  1046. APP.W_MinToolbar.Initialize(MinToolTop, ActualHeight);
  1047. GridSrToobar.Visibility = Visibility.Hidden;
  1048. APP.W_MinToolbar.Show();
  1049. }
  1050. });
  1051. }))).Start();
  1052. }
  1053. }
  1054. }
  1055. }
  1056. }