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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017
  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. this.Hide();
  517. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  518. this.Show();
  519. try
  520. {
  521. if (flg == 11)
  522. {
  523. Dispatcher.Invoke(() =>
  524. {
  525. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  526. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  527. });
  528. flg = 1;
  529. APP.W_PracticeWindow.Hide();
  530. }
  531. else if (flg == 10)
  532. {
  533. Dispatcher.Invoke(() =>
  534. {
  535. borOne.Background = new SolidColorBrush(Colors.LightSkyBlue);
  536. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  537. });
  538. APP.W_PracticeWindow.Blue();
  539. flg = 11;
  540. }
  541. else
  542. {
  543. //new Thread(new ThreadStart(new Action(() =>
  544. //{
  545. Dispatcher.Invoke(() =>
  546. {
  547. borOne.Background = new SolidColorBrush(Colors.LightSkyBlue);
  548. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  549. });
  550. //}))).Start();
  551. if (APP.W_PracticeWindow == null)
  552. {
  553. APP.W_PracticeWindow = new PracticeWindow
  554. {
  555. //APP.W_PracticeWindow.Topmost = true;
  556. Width = pwidth,
  557. Height = pHeight,
  558. Left = 0,
  559. Top = 0
  560. };
  561. //practiceWin.Owner = this;
  562. }
  563. APP.W_PracticeWindow.Initialize(imagePath);
  564. flg = 11;
  565. APP.W_PracticeWindow.Blue();
  566. APP.W_PracticeWindow.Show();
  567. }
  568. }
  569. catch (Exception ex)
  570. {
  571. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  572. }
  573. //imgCanvas.Source = new BitmapImage(new Uri(imagePath));
  574. }
  575. /// <summary>
  576. /// 屏幕宽
  577. /// </summary>
  578. internal double pwidth = SystemParameters.PrimaryScreenWidth;
  579. /// <summary>
  580. /// 屏幕高
  581. /// </summary>
  582. internal double pHeight = SystemParameters.PrimaryScreenHeight;
  583. /// <summary>
  584. /// 获取时间戳
  585. /// </summary>
  586. /// <returns></returns>
  587. public string GetTimeStamp()
  588. {
  589. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  590. return Convert.ToInt64(ts.TotalMilliseconds).ToString();
  591. }
  592. /// <summary>
  593. /// 画笔粗细事件
  594. /// </summary>
  595. /// <param name="sender"></param>
  596. /// <param name="e"></param>
  597. private void BtnThickness_Click(object sender, RoutedEventArgs e)
  598. {
  599. gridThickness.Visibility = Visibility.Visible;
  600. gridColour.Visibility = Visibility.Collapsed;
  601. }
  602. /// <summary>
  603. /// 画笔颜色事件
  604. /// </summary>
  605. /// <param name="sender"></param>
  606. /// <param name="e"></param>
  607. private void BtnColour_Click(object sender, RoutedEventArgs e)
  608. {
  609. gridColour.Visibility = Visibility.Visible;
  610. gridThickness.Visibility = Visibility.Collapsed;
  611. }
  612. /// <summary>
  613. /// 白色
  614. /// </summary>
  615. /// <param name="sender"></param>
  616. /// <param name="e"></param>
  617. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  618. {
  619. //drawingAttributes.Color = Colors.White;
  620. APP.W_PracticeWindow.White();
  621. gridColour.Visibility = Visibility.Collapsed;
  622. gridThickness.Visibility = Visibility.Collapsed;
  623. }
  624. /// <summary>
  625. /// 红色
  626. /// </summary>
  627. /// <param name="sender"></param>
  628. /// <param name="e"></param>
  629. private void BtnRed_Click(object sender, RoutedEventArgs e)
  630. {
  631. //drawingAttributes.Color = Colors.Red;
  632. APP.W_PracticeWindow.Red();
  633. gridColour.Visibility = Visibility.Collapsed;
  634. gridThickness.Visibility = Visibility.Collapsed;
  635. }
  636. /// <summary>
  637. /// 黄色
  638. /// </summary>
  639. /// <param name="sender"></param>
  640. /// <param name="e"></param>
  641. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  642. {
  643. //drawingAttributes.Color = Colors.Gold;
  644. APP.W_PracticeWindow.Yellow();
  645. gridColour.Visibility = Visibility.Collapsed;
  646. gridThickness.Visibility = Visibility.Collapsed;
  647. }
  648. /// <summary>
  649. /// 青色
  650. /// </summary>
  651. /// <param name="sender"></param>
  652. /// <param name="e"></param>
  653. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  654. {
  655. //drawingAttributes.Color = Colors.LimeGreen;
  656. APP.W_PracticeWindow.CyanBlue();
  657. gridColour.Visibility = Visibility.Collapsed;
  658. gridThickness.Visibility = Visibility.Collapsed;
  659. }
  660. /// <summary>
  661. /// 灰色
  662. /// </summary>
  663. /// <param name="sender"></param>
  664. /// <param name="e"></param>
  665. private void BtnGray_Click(object sender, RoutedEventArgs e)
  666. {
  667. //drawingAttributes.Color = Colors.Gray;
  668. APP.W_PracticeWindow.Gray();
  669. gridColour.Visibility = Visibility.Collapsed;
  670. gridThickness.Visibility = Visibility.Collapsed;
  671. }
  672. /// <summary>
  673. /// 蓝色
  674. /// </summary>
  675. /// <param name="sender"></param>
  676. /// <param name="e"></param>
  677. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  678. {
  679. //drawingAttributes.Color = Colors.DeepSkyBlue;
  680. APP.W_PracticeWindow.Blue();
  681. gridColour.Visibility = Visibility.Collapsed;
  682. gridThickness.Visibility = Visibility.Collapsed;
  683. }
  684. /// <summary>
  685. /// 画笔 细
  686. /// </summary>
  687. /// <param name="sender"></param>
  688. /// <param name="e"></param>
  689. private void BtnFine_Click(object sender, RoutedEventArgs e)
  690. {
  691. APP.W_PracticeWindow.Fine();
  692. gridColour.Visibility = Visibility.Collapsed;
  693. gridThickness.Visibility = Visibility.Collapsed;
  694. }
  695. /// <summary>
  696. /// 画笔 中
  697. /// </summary>
  698. /// <param name="sender"></param>
  699. /// <param name="e"></param>
  700. private void BtnIn_Click(object sender, RoutedEventArgs e)
  701. {
  702. APP.W_PracticeWindow.In();
  703. gridColour.Visibility = Visibility.Collapsed;
  704. gridThickness.Visibility = Visibility.Collapsed;
  705. }
  706. /// <summary>
  707. /// 画笔粗
  708. /// </summary>
  709. /// <param name="sender"></param>
  710. /// <param name="e"></param>
  711. private void BtnCrude_Click(object sender, RoutedEventArgs e)
  712. {
  713. APP.W_PracticeWindow.Crude();
  714. gridColour.Visibility = Visibility.Collapsed;
  715. gridThickness.Visibility = Visibility.Collapsed;
  716. }
  717. /// <summary>
  718. /// 橡皮
  719. /// </summary>
  720. /// <param name="sender"></param>
  721. /// <param name="e"></param>
  722. private void BtnEraser_Click(object sender, RoutedEventArgs e)
  723. {
  724. APP.W_PracticeWindow.Eraser();
  725. }
  726. /// <summary>
  727. /// 🖊
  728. /// </summary>
  729. /// <param name="sender"></param>
  730. /// <param name="e"></param>
  731. private void BtnPen_Click(object sender, RoutedEventArgs e)
  732. {
  733. APP.W_PracticeWindow.Pen();
  734. }
  735. /// <summary>
  736. /// ⚪
  737. /// </summary>
  738. /// <param name="sender"></param>
  739. /// <param name="e"></param>
  740. private void BtnRound_Click(object sender, RoutedEventArgs e)
  741. {
  742. APP.W_PracticeWindow.Round();
  743. }
  744. /// <summary>
  745. /// 矩形
  746. /// </summary>
  747. /// <param name="sender"></param>
  748. /// <param name="e"></param>
  749. private void BtnRectangle_Click(object sender, RoutedEventArgs e)
  750. {
  751. APP.W_PracticeWindow.Rectangle();
  752. }
  753. #endregion
  754. #endregion
  755. /// <summary>
  756. /// 停止录屏
  757. /// </summary>
  758. public delegate void StopRecordingScreen();
  759. /// <summary>
  760. /// 停止录屏
  761. /// </summary>
  762. public event StopRecordingScreen Click_stopRecordingScreen;
  763. /// <summary>
  764. /// 黑笔
  765. /// </summary>
  766. /// <param name="sender"></param>
  767. /// <param name="e"></param>
  768. private void BtnBlackPen_Click(object sender, RoutedEventArgs e)
  769. {
  770. }
  771. /// <summary>
  772. /// 移动工具栏
  773. /// </summary>
  774. /// <param name="sender"></param>
  775. /// <param name="e"></param>
  776. private void Grid_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  777. {
  778. DragMove();
  779. }
  780. /// <summary>
  781. /// 红笔
  782. /// </summary>
  783. /// <param name="sender"></param>
  784. /// <param name="e"></param>
  785. private void BtnBlackPenTwo_Click(object sender, RoutedEventArgs e)
  786. {
  787. string time = GetTimeStamp();
  788. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  789. if (!Directory.Exists(tempPath))
  790. {
  791. Directory.CreateDirectory(tempPath);
  792. }
  793. string imagePath = Path.Combine(tempPath, time + ".jpg");
  794. this.Hide();
  795. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  796. this.Show();
  797. try
  798. {
  799. if (flg == 10)
  800. {
  801. Dispatcher.Invoke(() =>
  802. {
  803. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  804. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  805. });
  806. flg = 0;
  807. APP.W_PracticeWindow.Hide();
  808. }
  809. else if (flg == 11)
  810. {
  811. Dispatcher.Invoke(() =>
  812. {
  813. borTwo.Background = new SolidColorBrush(Colors.LightSkyBlue);
  814. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  815. });
  816. flg = 10;
  817. APP.W_PracticeWindow.Red();
  818. }
  819. else
  820. {
  821. Dispatcher.Invoke(() =>
  822. {
  823. borTwo.Background = new SolidColorBrush(Colors.LightSkyBlue);
  824. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  825. });
  826. if (APP.W_PracticeWindow == null)
  827. {
  828. APP.W_PracticeWindow = new PracticeWindow
  829. {
  830. //APP.W_PracticeWindow.Topmost = true;
  831. Width = pwidth,
  832. Height = pHeight,
  833. Left = 0,
  834. Top = 0
  835. };
  836. //practiceWin.Owner = this;
  837. }
  838. APP.W_PracticeWindow.Initialize(imagePath);
  839. flg = 10;
  840. APP.W_PracticeWindow.Red();
  841. APP.W_PracticeWindow.Show();
  842. }
  843. }
  844. catch (Exception ex)
  845. {
  846. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  847. }
  848. }
  849. /// <summary>
  850. /// 鼠标右键按下事件
  851. /// </summary>
  852. /// <param name="sender"></param>
  853. /// <param name="e"></param>
  854. private void RightButtonDown()
  855. {
  856. if (flg > 9)
  857. {
  858. APP.W_PracticeWindow.Hide();
  859. }
  860. else
  861. {
  862. string time = GetTimeStamp();
  863. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  864. if (!Directory.Exists(tempPath))
  865. {
  866. Directory.CreateDirectory(tempPath);
  867. }
  868. string imagePath = Path.Combine(tempPath, time + ".jpg");
  869. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  870. try
  871. {
  872. if (APP.W_PracticeWindow == null)
  873. {
  874. APP.W_PracticeWindow = new PracticeWindow
  875. {
  876. //APP.W_PracticeWindow.Topmost = true;
  877. Width = pwidth,
  878. Height = pHeight,
  879. Left = 0,
  880. Top = 0
  881. };
  882. //practiceWin.Owner = this;
  883. }
  884. APP.W_PracticeWindow.Initialize(imagePath);
  885. if (flg == 0)
  886. {
  887. flg = 10;
  888. APP.W_PracticeWindow.Red();
  889. }
  890. else
  891. {
  892. flg = 11;
  893. APP.W_PracticeWindow.Blue();
  894. }
  895. APP.W_PracticeWindow.Show();
  896. }
  897. catch (Exception ex)
  898. {
  899. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  900. }
  901. }
  902. }
  903. /// <summary>
  904. /// 返回主界面
  905. /// </summary>
  906. /// <param name="sender"></param>
  907. /// <param name="e"></param>
  908. private void BtnReturn_Click(object sender, RoutedEventArgs e)
  909. {
  910. if (!IsFirstRS)
  911. {
  912. MessageBoxResult br = MessageWindow.Show("退出将不保存当前录屏!", "提示", MessageBoxButton.OKCancel);
  913. if (br == MessageBoxResult.Cancel)
  914. {
  915. return;
  916. }
  917. k_hook.Stop();
  918. IsSuspend = true;
  919. txbTime.Text = "00:00";
  920. txbTime.Visibility = Visibility.Hidden;
  921. End();
  922. if (APP.W_PracticeWindow != null)
  923. {
  924. if (APP.W_PracticeWindow.Visibility == Visibility.Visible)
  925. {
  926. APP.W_PracticeWindow.Hide();
  927. }
  928. }
  929. if (gridToolbar.Visibility == Visibility.Visible)
  930. {
  931. gridToolbar.Visibility = Visibility.Hidden;
  932. gridColour.Visibility = Visibility.Hidden;
  933. gridThickness.Visibility = Visibility.Hidden;
  934. }
  935. if (APP.W_XHMicroLessonSystemWindow == null)
  936. {
  937. APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
  938. }
  939. try
  940. {
  941. try
  942. {
  943. APP.FFmpeg.SuspendFFmpeg();
  944. }
  945. catch (Exception ex)
  946. {
  947. LogHelper.WriteErrLog("【录屏返回】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  948. }
  949. IsFirstRS = true;
  950. new Thread(new ThreadStart(new Action(() =>
  951. {
  952. VideoInfo = null;
  953. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temprs/");
  954. }))).Start();
  955. }
  956. catch (Exception ex)
  957. {
  958. LogHelper.WriteErrLog("【录屏返回】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  959. }
  960. }
  961. APP.W_XHMicroLessonSystemWindow.Show();
  962. Hide();
  963. }
  964. /// <summary>
  965. /// 批注退出
  966. /// </summary>
  967. public void ReturnPractice()
  968. {
  969. Dispatcher.Invoke(() =>
  970. {
  971. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  972. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  973. });
  974. flg = 0;
  975. APP.W_PracticeWindow.Hide();
  976. }
  977. }
  978. }