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

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