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