星火微课系统客户端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ScreenRecordingToolbarWindow.xaml.cs 39KB

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