星火微课系统客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ScreenRecordingToolbarWindow.xaml.cs 36KB

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年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960
  1. using Common.system;
  2. using System;
  3. using System.IO;
  4. using System.Threading;
  5. using System.Windows;
  6. using System.Windows.Forms;
  7. using System.Windows.Ink;
  8. using System.Windows.Media.Imaging;
  9. using System.Windows.Threading;
  10. using XHWK.Model;
  11. namespace XHWK.WKTool
  12. {
  13. /// <summary>
  14. /// 录屏工具栏
  15. /// </summary>
  16. public partial class ScreenRecordingToolbarWindow : Window
  17. {
  18. #region 初始变量
  19. /// <summary>
  20. /// 视频保存名称
  21. /// </summary>
  22. private string VideoSavePathName;
  23. /// <summary>
  24. /// 是否首次录屏
  25. /// </summary>
  26. private bool IsFirstRS = true;
  27. /// <summary>
  28. /// 是否暂停
  29. /// </summary>
  30. private bool IsSuspend = true;
  31. /// <summary>
  32. /// 视频信息
  33. /// </summary>
  34. private Model_Video VideoInfo = null;
  35. //声明一个 DrawingAttributes 类型的变量
  36. private DrawingAttributes drawingAttributes;
  37. private DispatcherTimer t = null;
  38. /// <summary>
  39. /// 计时器状态
  40. /// </summary>
  41. private enum State
  42. {
  43. Start,
  44. Pause,
  45. End
  46. }
  47. /// <summary>
  48. /// 状态
  49. /// </summary>
  50. private State _state = State.End;
  51. /// <summary>
  52. /// 计时用
  53. /// </summary>
  54. private TimeSpan _timeSpan = new TimeSpan(0, 0, 0, 0, 0);
  55. private KeyboardHookCommon k_hook;
  56. /// <summary>
  57. /// 🖊状态 0红色 1蓝色 10红色批注内 11蓝色批注内
  58. /// </summary>
  59. public int flg = 0;
  60. private System.Timers.Timer timer = new System.Timers.Timer();
  61. #endregion
  62. #region 初始化
  63. /// <summary>
  64. /// 录屏工具栏
  65. /// </summary>
  66. public ScreenRecordingToolbarWindow()
  67. {
  68. InitializeComponent();
  69. }
  70. /// <summary>
  71. /// 初始化
  72. /// </summary>
  73. public void Initialize()
  74. {
  75. //timer = new System.Timers.Timer(200);
  76. //timer.Interval = 300;
  77. //timer.Elapsed += new System.Timers.ElapsedEventHandler(TimerDealy);
  78. //timer.Enabled = true; //启动计时器
  79. k_hook = new KeyboardHookCommon();
  80. k_hook.KeyDownEvent += K_hook_KeyDownEvent;
  81. //创建 DrawingAttributes 类的一个实例
  82. drawingAttributes = new DrawingAttributes();
  83. //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  84. //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  85. blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  86. drawingAttributes.FitToCurve = true;
  87. //隐藏画笔工具栏
  88. //BtnToolbarDown_Click(null, null);
  89. gridToolbar.Visibility = Visibility.Hidden;
  90. gridColour.Visibility = Visibility.Hidden;
  91. gridThickness.Visibility = Visibility.Hidden;
  92. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar26.png"));//大圆圈三角形
  93. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
  94. BtnStopRecordingScreen.IsEnabled = false; //停止录制按钮不点击
  95. imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  96. btnBlackPenOne.IsEnabled = false;//蓝笔不可点击
  97. imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  98. btnBlackPenTwo.IsEnabled = false;//红笔不可点击
  99. //imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar29.png"));
  100. //btnReturn.IsEnabled = true;//返回主界面可点击
  101. txbTime.Visibility = Visibility.Hidden;//时间不显示
  102. if (t == null)
  103. {
  104. t = new DispatcherTimer();
  105. t.Tick += OnTimer;
  106. t.Interval = new TimeSpan(0, 0, 0, 1);
  107. t.IsEnabled = true;
  108. t.Start();
  109. }
  110. t.Interval = new TimeSpan(0, 0, 0, 1);
  111. //Stack();
  112. //ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar25.png"));
  113. //BtnRecordingScreen_Click(null, null);
  114. }
  115. private void TimerDealy(object o, EventArgs e)
  116. {
  117. Dispatcher.Invoke(() =>
  118. {
  119. if (Left > 1630)
  120. {
  121. return;
  122. }
  123. //获取鼠标在屏幕上的位置
  124. double mouse_x = Form.MousePosition.X; //需要添加引用System.Drawing
  125. double mouse_y = Form.MousePosition.Y;
  126. bool is_in_collasped_range = (mouse_y > Left + Height) || (mouse_x < Left || mouse_x > Left + Width);//缩起的条件
  127. bool is_in_visiable_range = (mouse_y < 1 && mouse_x >= Left && mouse_x <= Left + Width); //展开的条件
  128. if (Left < 1630 && Left >= 0 && is_in_collasped_range)
  129. {
  130. System.Threading.Thread.Sleep(300);
  131. Left += 20 /*-this.ActualWidth - 3*/;
  132. }
  133. else if (Left < 0 && is_in_visiable_range)
  134. {
  135. Left = 1;
  136. }
  137. });
  138. }
  139. private void K_hook_KeyDownEvent(object sender, System.Windows.Forms.KeyEventArgs e)
  140. {
  141. if (e.KeyValue == (int)System.Windows.Forms.Keys.F5 && (int)Control.ModifierKeys == (int)Keys.Control)
  142. {
  143. //开始,暂停
  144. BtnRecordingScreen_Click(null, null);
  145. }
  146. if (e.KeyValue == (int)Keys.S && (int)Control.ModifierKeys == (int)Keys.Control)
  147. {
  148. //结束
  149. BtnStopRecordingScreen_Click(null, null);
  150. }
  151. }
  152. #endregion
  153. #region 事件
  154. /// <summary>
  155. /// 时钟回调
  156. /// </summary>
  157. /// <param name="sender"></param>
  158. /// <param name="e"></param>
  159. private void OnTimer(object sender, EventArgs e)
  160. {
  161. switch (_state)
  162. {
  163. case State.Start:
  164. {
  165. _timeSpan += new TimeSpan(0, 0, 0, 1);
  166. }
  167. break;
  168. case State.Pause:
  169. {
  170. }
  171. break;
  172. case State.End:
  173. {
  174. _timeSpan = new TimeSpan();
  175. //_timeSpan = new TimeSpan(0, 23, 12, 45, 54);
  176. }
  177. break;
  178. }
  179. string time = string.Format("{0:D2}:{1:D2}",/* _timeSpan.Hours,*/ _timeSpan.Minutes, _timeSpan.Seconds);
  180. //char[] times = time.ToCharArray();
  181. txbTime.Text = time;
  182. }
  183. /// <summary>
  184. /// 开始
  185. /// </summary>
  186. /// <param name="sender"></param>
  187. /// <param name="e"></param>
  188. private void Stack()
  189. {
  190. _state = State.Start;
  191. }
  192. /// <summary>
  193. /// 暂停
  194. /// </summary>
  195. private void TimeOut()
  196. {
  197. _state = State.Pause;
  198. }
  199. /// <summary>
  200. /// 结束
  201. /// </summary>
  202. /// <param name="sender"></param>
  203. /// <param name="e"></param>
  204. private void End()
  205. {
  206. _state = State.End;
  207. }
  208. #region 录屏
  209. /// <summary>
  210. /// 设置录屏文件地址
  211. /// </summary>
  212. private void SetUpVideoPathName()
  213. {
  214. //FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  215. FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  216. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temprs/");
  217. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
  218. int num = 1;
  219. while (FileToolsCommon.IsExistFile(VideoSavePathName))
  220. {
  221. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏_" + num + "." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
  222. num++;
  223. }
  224. }
  225. /// <summary>
  226. /// 开始或暂停录制
  227. /// </summary>
  228. /// <param name="sender"></param>
  229. /// <param name="e"></param>
  230. private void BtnRecordingScreen_Click(object sender, RoutedEventArgs e)
  231. {
  232. if (IsSuspend)
  233. {
  234. if (IsFirstRS)
  235. {
  236. #region 检测麦克风扬声器是否可用
  237. string audioSpeakerPath = FileToolsCommon.GetFileAbsolutePath("adoS.m");
  238. string audioMicrophonePath = FileToolsCommon.GetFileAbsolutePath("adoM.m");
  239. try
  240. {
  241. FileToolsCommon.DeleteFile(audioSpeakerPath);
  242. FileToolsCommon.DeleteFile(audioMicrophonePath);
  243. }
  244. catch (Exception)
  245. {
  246. }
  247. //扬声器
  248. if (APP.FFmpeg.StartRecordSpeakerAudio(audioSpeakerPath))
  249. {
  250. APP.FFmpeg.StopRecordAudio(2);
  251. //Thread.Sleep(500);
  252. //麦克风
  253. if (APP.FFmpeg.StartRecordAudio(audioMicrophonePath))
  254. {
  255. }
  256. else
  257. {
  258. //无法录制麦克风
  259. MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制麦克风,是否继续?", "消息提示", MessageBoxButton.OKCancel);
  260. if (Res == MessageBoxResult.Cancel)
  261. {
  262. return;
  263. }
  264. }
  265. APP.FFmpeg.StopRecordAudio(1);
  266. }
  267. else
  268. {
  269. //无法录制扬声器音频
  270. MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制音频,是否继续?", "消息提示", MessageBoxButton.OKCancel);
  271. if (Res == MessageBoxResult.Cancel)
  272. {
  273. return;
  274. }
  275. }
  276. #endregion
  277. VideoInfo = new Model_Video
  278. {
  279. VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType")),
  280. WkType = Enum_WKVidetype.RecordingScreen
  281. };
  282. SetUpVideoPathName();
  283. IsFirstRS = false;
  284. k_hook.Start();//安装键盘钩子
  285. if (APP.W_CountdownWindow == null)
  286. {
  287. APP.W_CountdownWindow = new CountdownWindow();
  288. APP.W_CountdownWindow.Initialize(true, 1800);
  289. //APP.W_CountdownWindow.Topmost = true;
  290. }
  291. else
  292. {
  293. APP.W_CountdownWindow.Initialize(true, 1800);
  294. //APP.W_CountdownWindow.Topmost = true;
  295. }
  296. APP.W_CountdownWindow.Show();
  297. }
  298. IsSuspend = false;
  299. //#region 录像倒计时
  300. //if (APP.W_CountdownWindow == null)
  301. //{
  302. // APP.W_CountdownWindow = new CountdownWindow();
  303. // //APP.W_CountdownWindow.Topmost = true;
  304. //}
  305. //else
  306. //{
  307. // APP.W_CountdownWindow.Initialize();
  308. // //APP.W_CountdownWindow.Topmost = true;
  309. //}
  310. //APP.W_CountdownWindow.Show();
  311. //#endregion
  312. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar25.png"));//播放状态
  313. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar14.png"));
  314. BtnStopRecordingScreen.IsEnabled = true; //停止录制按钮可点击
  315. imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar27.png"));
  316. btnBlackPenOne.IsEnabled = true;//蓝笔可点击
  317. imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar28.png"));
  318. btnBlackPenTwo.IsEnabled = true;//红笔可点击
  319. txbTime.Visibility = Visibility.Visible;//时间显示
  320. imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar30.png"));
  321. //btnReturn.IsEnabled = false;//返回主界面可点击
  322. try
  323. {
  324. #region 4秒内不可点击
  325. new Thread(new ThreadStart(new Action(() =>
  326. {
  327. Dispatcher.Invoke(() =>
  328. {
  329. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
  330. BtnRecordingScreen.IsEnabled = false;
  331. BtnStopRecordingScreen.IsEnabled = false;
  332. });
  333. Thread.Sleep(4000);
  334. Dispatcher.Invoke(() =>
  335. {
  336. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar14.png"));
  337. BtnRecordingScreen.IsEnabled = true;
  338. BtnStopRecordingScreen.IsEnabled = true;
  339. });
  340. }))).Start();
  341. #endregion
  342. new Thread(new ThreadStart(new Action(() =>
  343. {
  344. if (IsFirstRS)
  345. {
  346. Thread.Sleep(1500);
  347. }
  348. if(APP.FFmpeg.myProcess!=null)
  349. {
  350. Thread.Sleep(100);
  351. }
  352. APP.FFmpeg.StartRecordingVideo(VideoSavePathName);
  353. Thread.Sleep(1000);
  354. Dispatcher.Invoke(() =>
  355. {
  356. Stack();
  357. });
  358. }))).Start();
  359. }
  360. catch (Exception ex)
  361. {
  362. MessageWindow.Show(ex.Message);
  363. }
  364. }
  365. else
  366. {
  367. TimeOut();
  368. IsSuspend = true;
  369. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar26.png"));//大圆圈三角形
  370. BtnStopRecordingScreen.IsEnabled = false; //停止录制按钮不点击
  371. imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  372. btnBlackPenOne.IsEnabled = false;//蓝笔不可点击
  373. imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  374. btnBlackPenTwo.IsEnabled = false;//红笔不可点击
  375. txbTime.Visibility = Visibility.Hidden;//时间不显示
  376. imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar29.png"));
  377. //btnReturn.IsEnabled = true;//返回主界面可点击
  378. #region 2秒内不可点击
  379. new Thread(new ThreadStart(new Action(() =>
  380. {
  381. Dispatcher.Invoke(() =>
  382. {
  383. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
  384. BtnRecordingScreen.IsEnabled = false;
  385. BtnStopRecordingScreen.IsEnabled = false;
  386. });
  387. Thread.Sleep(2000);
  388. Dispatcher.Invoke(() =>
  389. {
  390. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar14.png"));
  391. BtnRecordingScreen.IsEnabled = true;
  392. BtnStopRecordingScreen.IsEnabled = true;
  393. });
  394. }))).Start();
  395. #endregion
  396. try
  397. {
  398. APP.FFmpeg.SuspendFFmpeg();
  399. }
  400. catch (Exception ex)
  401. {
  402. MessageWindow.Show(ex.Message);
  403. }
  404. }
  405. }
  406. /// <summary>
  407. /// 停止录像
  408. /// </summary>
  409. /// <param name="sender"></param>
  410. /// <param name="e"></param>
  411. private void BtnStopRecordingScreen_Click(object sender, RoutedEventArgs e)
  412. {
  413. k_hook.Stop();
  414. IsSuspend = true;
  415. txbTime.Text = "00:00";
  416. txbTime.Visibility = Visibility.Hidden;
  417. End();
  418. if (APP.W_PracticeWindow != null)
  419. {
  420. if (APP.W_PracticeWindow.Visibility == Visibility.Visible)
  421. {
  422. APP.W_PracticeWindow.Hide();
  423. }
  424. }
  425. if (gridToolbar.Visibility == Visibility.Visible)
  426. {
  427. gridToolbar.Visibility = Visibility.Hidden;
  428. gridColour.Visibility = Visibility.Hidden;
  429. gridThickness.Visibility = Visibility.Hidden;
  430. }
  431. if (APP.W_XHMicroLessonSystemWindow == null)
  432. {
  433. APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
  434. }
  435. APP.W_XHMicroLessonSystemWindow.Show();
  436. if (!IsFirstRS)
  437. {
  438. try
  439. {
  440. try
  441. {
  442. APP.FFmpeg.StopFFmpeg(VideoSavePathName);
  443. }
  444. catch (Exception ex)
  445. {
  446. LogHelper.WriteErrLog("【停止录屏】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  447. }
  448. IsFirstRS = true;
  449. //生成缩略图
  450. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  451. FileToolsCommon.CreateDirectory(ThumbnailPath);
  452. //缩略图存储位置
  453. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileName(VideoSavePathName).Replace(".", "") + ".JPG";
  454. new Thread(new ThreadStart(new Action(() =>
  455. {
  456. while (!FileToolsCommon.IsExistFile(VideoSavePathName))
  457. {
  458. Thread.Sleep(100);
  459. }
  460. FileToolsCommon.DeleteFile(ThumbnailPathName);
  461. //VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  462. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  463. VideoInfo.VideoPath = VideoSavePathName;
  464. VideoInfo.ThumbnailPath = ThumbnailPathName;
  465. APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName);
  466. VideoInfo.FileGuid = Guid.NewGuid().ToString();
  467. VideoInfo.IsUpload = false;
  468. VideoInfo.Uploaded = 0;
  469. VideoInfo.Savefolder = APP.UserInfo.Schoolid + "/resource";
  470. APP.VideoList.Add(VideoInfo);
  471. //保存数据
  472. APP.SaveWkData();
  473. }))).Start();
  474. Click_stopRecordingScreen();
  475. }
  476. catch (Exception ex)
  477. {
  478. LogHelper.WriteErrLog("【停止录屏】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  479. }
  480. }
  481. Hide();
  482. }
  483. #endregion
  484. #region 画笔相关
  485. /// <summary>
  486. /// 画笔工具栏关闭事件
  487. /// </summary>
  488. /// <param name="sender"></param>
  489. /// <param name="e"></param>
  490. private void BtnToolbarDown_Click(object sender, RoutedEventArgs e)
  491. {
  492. gridToolbar.Visibility = Visibility.Hidden;
  493. gridColour.Visibility = Visibility.Hidden;
  494. gridThickness.Visibility = Visibility.Hidden;
  495. APP.W_PracticeWindow.Hide();
  496. }
  497. /// <summary>
  498. /// 画笔点击事件
  499. /// </summary>
  500. /// <param name="sender"></param>
  501. /// <param name="e"></param>
  502. private void BtnBrush_Click(object sender, RoutedEventArgs e)
  503. {
  504. string time = GetTimeStamp();
  505. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  506. if (!Directory.Exists(tempPath))
  507. {
  508. Directory.CreateDirectory(tempPath);
  509. }
  510. string imagePath = Path.Combine(tempPath, time + ".jpg");
  511. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  512. try
  513. {
  514. if (flg == 11)
  515. {
  516. flg = 1;
  517. APP.W_PracticeWindow.Hide();
  518. }
  519. else if (flg == 10)
  520. {
  521. APP.W_PracticeWindow.Blue();
  522. flg = 11;
  523. }
  524. else
  525. {
  526. if (APP.W_PracticeWindow == null)
  527. {
  528. APP.W_PracticeWindow = new PracticeWindow
  529. {
  530. //APP.W_PracticeWindow.Topmost = true;
  531. Width = pwidth,
  532. Height = pHeight,
  533. Left = 0,
  534. Top = 0
  535. };
  536. //practiceWin.Owner = this;
  537. }
  538. APP.W_PracticeWindow.Initialize(imagePath);
  539. flg = 11;
  540. APP.W_PracticeWindow.Blue();
  541. APP.W_PracticeWindow.Show();
  542. }
  543. }
  544. catch (Exception ex)
  545. {
  546. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  547. }
  548. //imgCanvas.Source = new BitmapImage(new Uri(imagePath));
  549. }
  550. /// <summary>
  551. /// 屏幕宽
  552. /// </summary>
  553. internal double pwidth = SystemParameters.PrimaryScreenWidth;
  554. /// <summary>
  555. /// 屏幕高
  556. /// </summary>
  557. internal double pHeight = SystemParameters.PrimaryScreenHeight;
  558. /// <summary>
  559. /// 获取时间戳
  560. /// </summary>
  561. /// <returns></returns>
  562. public string GetTimeStamp()
  563. {
  564. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  565. return Convert.ToInt64(ts.TotalMilliseconds).ToString();
  566. }
  567. /// <summary>
  568. /// 画笔粗细事件
  569. /// </summary>
  570. /// <param name="sender"></param>
  571. /// <param name="e"></param>
  572. private void BtnThickness_Click(object sender, RoutedEventArgs e)
  573. {
  574. gridThickness.Visibility = Visibility.Visible;
  575. gridColour.Visibility = Visibility.Collapsed;
  576. }
  577. /// <summary>
  578. /// 画笔颜色事件
  579. /// </summary>
  580. /// <param name="sender"></param>
  581. /// <param name="e"></param>
  582. private void BtnColour_Click(object sender, RoutedEventArgs e)
  583. {
  584. gridColour.Visibility = Visibility.Visible;
  585. gridThickness.Visibility = Visibility.Collapsed;
  586. }
  587. /// <summary>
  588. /// 白色
  589. /// </summary>
  590. /// <param name="sender"></param>
  591. /// <param name="e"></param>
  592. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  593. {
  594. //drawingAttributes.Color = Colors.White;
  595. APP.W_PracticeWindow.White();
  596. gridColour.Visibility = Visibility.Collapsed;
  597. gridThickness.Visibility = Visibility.Collapsed;
  598. }
  599. /// <summary>
  600. /// 红色
  601. /// </summary>
  602. /// <param name="sender"></param>
  603. /// <param name="e"></param>
  604. private void BtnRed_Click(object sender, RoutedEventArgs e)
  605. {
  606. //drawingAttributes.Color = Colors.Red;
  607. APP.W_PracticeWindow.Red();
  608. gridColour.Visibility = Visibility.Collapsed;
  609. gridThickness.Visibility = Visibility.Collapsed;
  610. }
  611. /// <summary>
  612. /// 黄色
  613. /// </summary>
  614. /// <param name="sender"></param>
  615. /// <param name="e"></param>
  616. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  617. {
  618. //drawingAttributes.Color = Colors.Gold;
  619. APP.W_PracticeWindow.Yellow();
  620. gridColour.Visibility = Visibility.Collapsed;
  621. gridThickness.Visibility = Visibility.Collapsed;
  622. }
  623. /// <summary>
  624. /// 青色
  625. /// </summary>
  626. /// <param name="sender"></param>
  627. /// <param name="e"></param>
  628. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  629. {
  630. //drawingAttributes.Color = Colors.LimeGreen;
  631. APP.W_PracticeWindow.CyanBlue();
  632. gridColour.Visibility = Visibility.Collapsed;
  633. gridThickness.Visibility = Visibility.Collapsed;
  634. }
  635. /// <summary>
  636. /// 灰色
  637. /// </summary>
  638. /// <param name="sender"></param>
  639. /// <param name="e"></param>
  640. private void BtnGray_Click(object sender, RoutedEventArgs e)
  641. {
  642. //drawingAttributes.Color = Colors.Gray;
  643. APP.W_PracticeWindow.Gray();
  644. gridColour.Visibility = Visibility.Collapsed;
  645. gridThickness.Visibility = Visibility.Collapsed;
  646. }
  647. /// <summary>
  648. /// 蓝色
  649. /// </summary>
  650. /// <param name="sender"></param>
  651. /// <param name="e"></param>
  652. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  653. {
  654. //drawingAttributes.Color = Colors.DeepSkyBlue;
  655. APP.W_PracticeWindow.Blue();
  656. gridColour.Visibility = Visibility.Collapsed;
  657. gridThickness.Visibility = Visibility.Collapsed;
  658. }
  659. /// <summary>
  660. /// 画笔 细
  661. /// </summary>
  662. /// <param name="sender"></param>
  663. /// <param name="e"></param>
  664. private void BtnFine_Click(object sender, RoutedEventArgs e)
  665. {
  666. APP.W_PracticeWindow.Fine();
  667. gridColour.Visibility = Visibility.Collapsed;
  668. gridThickness.Visibility = Visibility.Collapsed;
  669. }
  670. /// <summary>
  671. /// 画笔 中
  672. /// </summary>
  673. /// <param name="sender"></param>
  674. /// <param name="e"></param>
  675. private void BtnIn_Click(object sender, RoutedEventArgs e)
  676. {
  677. APP.W_PracticeWindow.In();
  678. gridColour.Visibility = Visibility.Collapsed;
  679. gridThickness.Visibility = Visibility.Collapsed;
  680. }
  681. /// <summary>
  682. /// 画笔粗
  683. /// </summary>
  684. /// <param name="sender"></param>
  685. /// <param name="e"></param>
  686. private void BtnCrude_Click(object sender, RoutedEventArgs e)
  687. {
  688. APP.W_PracticeWindow.Crude();
  689. gridColour.Visibility = Visibility.Collapsed;
  690. gridThickness.Visibility = Visibility.Collapsed;
  691. }
  692. /// <summary>
  693. /// 橡皮
  694. /// </summary>
  695. /// <param name="sender"></param>
  696. /// <param name="e"></param>
  697. private void BtnEraser_Click(object sender, RoutedEventArgs e)
  698. {
  699. APP.W_PracticeWindow.Eraser();
  700. }
  701. /// <summary>
  702. /// 🖊
  703. /// </summary>
  704. /// <param name="sender"></param>
  705. /// <param name="e"></param>
  706. private void BtnPen_Click(object sender, RoutedEventArgs e)
  707. {
  708. APP.W_PracticeWindow.Pen();
  709. }
  710. /// <summary>
  711. /// ⚪
  712. /// </summary>
  713. /// <param name="sender"></param>
  714. /// <param name="e"></param>
  715. private void BtnRound_Click(object sender, RoutedEventArgs e)
  716. {
  717. APP.W_PracticeWindow.Round();
  718. }
  719. /// <summary>
  720. /// 矩形
  721. /// </summary>
  722. /// <param name="sender"></param>
  723. /// <param name="e"></param>
  724. private void BtnRectangle_Click(object sender, RoutedEventArgs e)
  725. {
  726. APP.W_PracticeWindow.Rectangle();
  727. }
  728. #endregion
  729. #endregion
  730. /// <summary>
  731. /// 停止录屏
  732. /// </summary>
  733. public delegate void StopRecordingScreen();
  734. /// <summary>
  735. /// 停止录屏
  736. /// </summary>
  737. public event StopRecordingScreen Click_stopRecordingScreen;
  738. /// <summary>
  739. /// 黑笔
  740. /// </summary>
  741. /// <param name="sender"></param>
  742. /// <param name="e"></param>
  743. private void BtnBlackPen_Click(object sender, RoutedEventArgs e)
  744. {
  745. }
  746. /// <summary>
  747. /// 移动工具栏
  748. /// </summary>
  749. /// <param name="sender"></param>
  750. /// <param name="e"></param>
  751. private void Grid_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  752. {
  753. DragMove();
  754. }
  755. /// <summary>
  756. /// 红笔
  757. /// </summary>
  758. /// <param name="sender"></param>
  759. /// <param name="e"></param>
  760. private void BtnBlackPenTwo_Click(object sender, RoutedEventArgs e)
  761. {
  762. string time = GetTimeStamp();
  763. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  764. if (!Directory.Exists(tempPath))
  765. {
  766. Directory.CreateDirectory(tempPath);
  767. }
  768. string imagePath = Path.Combine(tempPath, time + ".jpg");
  769. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  770. try
  771. {
  772. if (flg == 10)
  773. {
  774. flg = 0;
  775. APP.W_PracticeWindow.Hide();
  776. }
  777. else if (flg == 11)
  778. {
  779. flg = 10;
  780. APP.W_PracticeWindow.Red();
  781. }
  782. else
  783. {
  784. if (APP.W_PracticeWindow == null)
  785. {
  786. APP.W_PracticeWindow = new PracticeWindow
  787. {
  788. //APP.W_PracticeWindow.Topmost = true;
  789. Width = pwidth,
  790. Height = pHeight,
  791. Left = 0,
  792. Top = 0
  793. };
  794. //practiceWin.Owner = this;
  795. }
  796. APP.W_PracticeWindow.Initialize(imagePath);
  797. flg = 10;
  798. APP.W_PracticeWindow.Red();
  799. APP.W_PracticeWindow.Show();
  800. }
  801. }
  802. catch (Exception ex)
  803. {
  804. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  805. }
  806. }
  807. /// <summary>
  808. /// 鼠标右键按下事件
  809. /// </summary>
  810. /// <param name="sender"></param>
  811. /// <param name="e"></param>
  812. private void RightButtonDown()
  813. {
  814. if (flg > 9)
  815. {
  816. APP.W_PracticeWindow.Hide();
  817. }
  818. else
  819. {
  820. string time = GetTimeStamp();
  821. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  822. if (!Directory.Exists(tempPath))
  823. {
  824. Directory.CreateDirectory(tempPath);
  825. }
  826. string imagePath = Path.Combine(tempPath, time + ".jpg");
  827. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  828. try
  829. {
  830. if (APP.W_PracticeWindow == null)
  831. {
  832. APP.W_PracticeWindow = new PracticeWindow
  833. {
  834. //APP.W_PracticeWindow.Topmost = true;
  835. Width = pwidth,
  836. Height = pHeight,
  837. Left = 0,
  838. Top = 0
  839. };
  840. //practiceWin.Owner = this;
  841. }
  842. APP.W_PracticeWindow.Initialize(imagePath);
  843. if (flg == 0)
  844. {
  845. flg = 10;
  846. APP.W_PracticeWindow.Red();
  847. }
  848. else
  849. {
  850. flg = 11;
  851. APP.W_PracticeWindow.Blue();
  852. }
  853. APP.W_PracticeWindow.Show();
  854. }
  855. catch (Exception ex)
  856. {
  857. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  858. }
  859. }
  860. }
  861. /// <summary>
  862. /// 返回主界面
  863. /// </summary>
  864. /// <param name="sender"></param>
  865. /// <param name="e"></param>
  866. private void BtnReturn_Click(object sender, RoutedEventArgs e)
  867. {
  868. if (!IsFirstRS)
  869. {
  870. MessageBoxResult br = MessageWindow.Show("退出将不保存当前录屏!", "提示", MessageBoxButton.OKCancel);
  871. if (br == MessageBoxResult.Cancel)
  872. {
  873. return;
  874. }
  875. k_hook.Stop();
  876. IsSuspend = true;
  877. txbTime.Text = "00:00";
  878. txbTime.Visibility = Visibility.Hidden;
  879. End();
  880. if (APP.W_PracticeWindow != null)
  881. {
  882. if (APP.W_PracticeWindow.Visibility == Visibility.Visible)
  883. {
  884. APP.W_PracticeWindow.Hide();
  885. }
  886. }
  887. if (gridToolbar.Visibility == Visibility.Visible)
  888. {
  889. gridToolbar.Visibility = Visibility.Hidden;
  890. gridColour.Visibility = Visibility.Hidden;
  891. gridThickness.Visibility = Visibility.Hidden;
  892. }
  893. if (APP.W_XHMicroLessonSystemWindow == null)
  894. {
  895. APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
  896. }
  897. try
  898. {
  899. try
  900. {
  901. APP.FFmpeg.SuspendFFmpeg();
  902. }
  903. catch (Exception ex)
  904. {
  905. LogHelper.WriteErrLog("【录屏返回】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  906. }
  907. IsFirstRS = true;
  908. new Thread(new ThreadStart(new Action(() =>
  909. {
  910. VideoInfo = null;
  911. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temprs/");
  912. }))).Start();
  913. }
  914. catch (Exception ex)
  915. {
  916. LogHelper.WriteErrLog("【录屏返回】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  917. }
  918. }
  919. APP.W_XHMicroLessonSystemWindow.Show();
  920. Hide();
  921. }
  922. }
  923. }