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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404
  1. using Common.system;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.IO;
  6. using System.Threading;
  7. using System.Windows;
  8. using System.Windows.Forms;
  9. using System.Windows.Ink;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Threading;
  13. using TStudyDigitalPen.HID;
  14. using XHWK.Model;
  15. namespace XHWK.WKTool
  16. {
  17. /// <summary>
  18. /// 录屏工具栏
  19. /// </summary>
  20. public partial class ScreenRecordingToolbarWindow : Window
  21. {
  22. #region 初始变量
  23. /// <summary>
  24. /// 视频保存名称
  25. /// </summary>
  26. private string VideoSavePathName;
  27. /// <summary>
  28. /// 是否首次录屏
  29. /// </summary>
  30. private bool IsFirstRS = true;
  31. /// <summary>
  32. /// 是否暂停
  33. /// </summary>
  34. private bool IsSuspend = true;
  35. /// <summary>
  36. /// 视频信息
  37. /// </summary>
  38. private Model_Video VideoInfo = null;
  39. //声明一个 DrawingAttributes 类型的变量
  40. private DrawingAttributes drawingAttributes;
  41. private DispatcherTimer t = null;
  42. /// <summary>
  43. /// 计时器状态
  44. /// </summary>
  45. private enum State
  46. {
  47. Start,
  48. Pause,
  49. End
  50. }
  51. /// <summary>
  52. /// 状态
  53. /// </summary>
  54. private State _state = State.End;
  55. private KeyboardHookCommon k_hook;
  56. /// <summary>
  57. /// 🖊状态 0红色 1蓝色 10红色批注内 11蓝色批注内
  58. /// </summary>
  59. public int flg = 0;
  60. private System.Timers.Timer timer = new System.Timers.Timer();
  61. #endregion
  62. #region 初始化
  63. /// <summary>
  64. /// 录屏工具栏
  65. /// </summary>
  66. public ScreenRecordingToolbarWindow()
  67. {
  68. InitializeComponent();
  69. ResizeMode = ResizeMode.NoResize;
  70. }
  71. /// <summary>
  72. /// 初始化
  73. /// </summary>
  74. public void Initialize()
  75. {
  76. gridToobar.Visibility = Visibility.Visible;
  77. if (APP.W_PracticeWindow == null)
  78. {
  79. APP.W_PracticeWindow = new PracticeWindow
  80. {
  81. //APP.W_PracticeWindow.Topmost = true;
  82. Width = pwidth,
  83. Height = pHeight,
  84. Left = 0,
  85. Top = 0
  86. };
  87. //practiceWin.Owner = this;
  88. }
  89. APP.W_PracticeWindow.InitPen();
  90. APP.W_PracticeWindow.InitTQLPPen();
  91. APP.W_PracticeWindow.Show();
  92. new Thread(new ThreadStart(new Action(() =>
  93. {
  94. Thread.Sleep(100);
  95. Dispatcher.Invoke(() =>
  96. {
  97. Owner = APP.W_PracticeWindow;
  98. Topmost = true;
  99. });
  100. }))).Start();
  101. APP.W_PracticeWindow.Hide();
  102. //timer = new System.Timers.Timer(200);
  103. //timer.Interval = 300;
  104. //timer.Elapsed += new System.Timers.ElapsedEventHandler(TimerDealy);
  105. //timer.Enabled = true; //启动计时器
  106. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  107. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  108. flg = 0;
  109. k_hook = new KeyboardHookCommon();
  110. k_hook.KeyDownEvent += K_hook_KeyDownEvent;
  111. //创建 DrawingAttributes 类的一个实例
  112. drawingAttributes = new DrawingAttributes();
  113. //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  114. //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  115. blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  116. drawingAttributes.FitToCurve = true;
  117. //隐藏画笔工具栏
  118. //BtnToolbarDown_Click(null, null);
  119. gridToolbar.Visibility = Visibility.Hidden;
  120. gridColour.Visibility = Visibility.Hidden;
  121. gridThickness.Visibility = Visibility.Hidden;
  122. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar26.png"));//大圆圈三角形
  123. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
  124. BtnStopRecordingScreen.IsEnabled = false; //停止录制按钮不点击
  125. imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  126. btnBlackPenOne.IsEnabled = false;//蓝笔不可点击
  127. imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  128. btnBlackPenTwo.IsEnabled = false;//红笔不可点击
  129. //imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar29.png"));
  130. //btnReturn.IsEnabled = true;//返回主界面可点击
  131. txbTime.Visibility = Visibility.Hidden;//时间不显示
  132. BtnRecordingScreen.ToolTip = "开始";
  133. if (t == null)
  134. {
  135. t = new DispatcherTimer();
  136. t.Tick += OnTimer;
  137. t.Interval = new TimeSpan(0, 0, 0, 0, 300);
  138. t.IsEnabled = true;
  139. t.Start();
  140. }
  141. t.Interval = new TimeSpan(0, 0, 0, 0, 300);
  142. //Stack();
  143. //ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar25.png"));
  144. //BtnRecordingScreen_Click(null, null);
  145. }
  146. private void TimerDealy(object o, EventArgs e)
  147. {
  148. Dispatcher.Invoke(() =>
  149. {
  150. if (Left > 1630)
  151. {
  152. return;
  153. }
  154. //获取鼠标在屏幕上的位置
  155. double mouse_x = Form.MousePosition.X; //需要添加引用System.Drawing
  156. double mouse_y = Form.MousePosition.Y;
  157. bool is_in_collasped_range = (mouse_y > Left + Height) || (mouse_x < Left || mouse_x > Left + Width);//缩起的条件
  158. bool is_in_visiable_range = (mouse_y < 1 && mouse_x >= Left && mouse_x <= Left + Width); //展开的条件
  159. if (Left < 1630 && Left >= 0 && is_in_collasped_range)
  160. {
  161. System.Threading.Thread.Sleep(300);
  162. Left += 20 /*-this.ActualWidth - 3*/;
  163. }
  164. else if (Left < 0 && is_in_visiable_range)
  165. {
  166. Left = 1;
  167. }
  168. });
  169. }
  170. private void K_hook_KeyDownEvent(object sender, System.Windows.Forms.KeyEventArgs e)
  171. {
  172. if (e.KeyValue == (int)System.Windows.Forms.Keys.F5 && (int)Control.ModifierKeys == (int)Keys.Control)
  173. {
  174. //开始,暂停
  175. BtnRecordingScreen_Click(null, null);
  176. }
  177. if (e.KeyValue == (int)Keys.S && (int)Control.ModifierKeys == (int)Keys.Control)
  178. {
  179. //结束
  180. BtnStopRecordingScreen_Click(null, null);
  181. }
  182. }
  183. #endregion
  184. #region 事件
  185. /// <summary>
  186. /// 记录上次执行时间
  187. /// </summary>
  188. private DateTime Recorddt = DateTime.Now;
  189. DateTime SRTime = Convert.ToDateTime("2020-01-01 00:00:00");
  190. /// <summary>
  191. /// 时钟回调
  192. /// </summary>
  193. /// <param name="sender"></param>
  194. /// <param name="e"></param>
  195. private void OnTimer(object sender, EventArgs e)
  196. {
  197. switch (_state)
  198. {
  199. case State.Start:
  200. {
  201. DateTime dt = DateTime.Now;
  202. TimeSpan ts = dt.Subtract(Recorddt);//时间差
  203. double tsmi = ts.TotalMilliseconds;
  204. if (tsmi > 500.0)
  205. {
  206. Recorddt = Recorddt.AddMilliseconds(500);
  207. SRTime = SRTime.AddMilliseconds(500);
  208. }
  209. }
  210. break;
  211. case State.Pause:
  212. {
  213. }
  214. break;
  215. case State.End:
  216. {
  217. SRTime = Convert.ToDateTime("2020-01-01 00:00:00");
  218. //_timeSpan = new TimeSpan();
  219. ////_timeSpan = new TimeSpan(0, 23, 12, 45, 54);
  220. }
  221. break;
  222. }
  223. //string time = string.Format("{0:D2}:{1:D2}",/* _timeSpan.Hours,*/ _timeSpan.Minutes, _timeSpan.Seconds);
  224. //char[] times = time.ToCharArray();
  225. if (SRTime.Hour > 0)
  226. {
  227. //Dispatcher.Invoke(() =>
  228. //{
  229. txbTime.Text = SRTime.ToString("HH:mm:ss");
  230. //});
  231. }
  232. else
  233. {
  234. //Dispatcher.Invoke(() =>
  235. //{
  236. txbTime.Text = SRTime.ToString("mm:ss");
  237. //});
  238. }
  239. }
  240. /// <summary>
  241. /// 开始
  242. /// </summary>
  243. /// <param name="sender"></param>
  244. /// <param name="e"></param>
  245. private void Stack()
  246. {
  247. Recorddt = DateTime.Now;
  248. _state = State.Start;
  249. }
  250. /// <summary>
  251. /// 暂停
  252. /// </summary>
  253. private void TimeOut()
  254. {
  255. _state = State.Pause;
  256. }
  257. /// <summary>
  258. /// 结束
  259. /// </summary>
  260. /// <param name="sender"></param>
  261. /// <param name="e"></param>
  262. private void End()
  263. {
  264. _state = State.End;
  265. }
  266. #region 录屏
  267. /// <summary>
  268. /// 设置录屏文件地址
  269. /// </summary>
  270. private void SetUpVideoPathName()
  271. {
  272. //FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  273. FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  274. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temprs/");
  275. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
  276. int num = 1;
  277. while (FileToolsCommon.IsExistFile(VideoSavePathName))
  278. {
  279. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏_" + num + "." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
  280. num++;
  281. }
  282. }
  283. /// <summary>
  284. /// 是否已经按下按钮
  285. /// </summary>
  286. private bool IsPressButton = false;
  287. /// <summary>
  288. /// 开始或暂停录制
  289. /// </summary>
  290. /// <param name="sender"></param>
  291. /// <param name="e"></param>
  292. private void BtnRecordingScreen_Click(object sender, RoutedEventArgs e)
  293. {
  294. #region 防止连击
  295. if (IsPressButton)
  296. {
  297. return;
  298. }
  299. else
  300. {
  301. IsPressButton = true;
  302. new Thread(new ThreadStart(new Action(() =>
  303. {
  304. Thread.Sleep(500);
  305. IsPressButton = false;
  306. }))).Start();
  307. }
  308. #endregion
  309. if (IsSuspend)
  310. {
  311. if (IsFirstRS)
  312. {
  313. #region 检测麦克风扬声器是否可用
  314. string AudioPath = FileToolsCommon.GetFileAbsolutePath("/temp/audio/");
  315. FileToolsCommon.CreateDirectory(AudioPath);
  316. string audioSpeakerPath = AudioPath + "adoS" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".m";
  317. string audioMicrophonePath = AudioPath + "adoM" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".m";
  318. try
  319. {
  320. FileToolsCommon.DeleteFile(audioSpeakerPath);
  321. FileToolsCommon.DeleteFile(audioMicrophonePath);
  322. }
  323. catch (Exception)
  324. {
  325. }
  326. //扬声器
  327. if (APP.FFmpeg.StartRecordSpeakerAudio(audioSpeakerPath))
  328. {
  329. APP.FFmpeg.StopRecordAudio(2);
  330. //Thread.Sleep(500);
  331. //麦克风
  332. if (APP.FFmpeg.StartRecordAudio(audioMicrophonePath))
  333. {
  334. }
  335. else
  336. {
  337. //无法录制麦克风
  338. MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制麦克风,是否继续?", "消息提示", MessageBoxButton.OKCancel);
  339. if (Res == MessageBoxResult.Cancel)
  340. {
  341. return;
  342. }
  343. }
  344. APP.FFmpeg.StopRecordAudio(1);
  345. }
  346. else
  347. {
  348. //无法录制扬声器音频
  349. MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制音频,是否继续?", "消息提示", MessageBoxButton.OKCancel);
  350. if (Res == MessageBoxResult.Cancel)
  351. {
  352. return;
  353. }
  354. }
  355. #endregion
  356. VideoInfo = new Model_Video
  357. {
  358. VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType")),
  359. WkType = Enum_WKVidetype.RecordingScreen
  360. };
  361. SetUpVideoPathName();
  362. k_hook.Start();//安装键盘钩子
  363. if (APP.W_CountdownWindow == null)
  364. {
  365. APP.W_CountdownWindow = new CountdownWindow();
  366. APP.W_CountdownWindow.Initialize(true, 1800);
  367. //APP.W_CountdownWindow.Topmost = true;
  368. }
  369. else
  370. {
  371. APP.W_CountdownWindow.Initialize(true, 1800);
  372. //APP.W_CountdownWindow.Topmost = true;
  373. }
  374. APP.W_CountdownWindow.Show();
  375. }
  376. IsSuspend = false;
  377. //#region 录像倒计时
  378. //if (APP.W_CountdownWindow == null)
  379. //{
  380. // APP.W_CountdownWindow = new CountdownWindow();
  381. // //APP.W_CountdownWindow.Topmost = true;
  382. //}
  383. //else
  384. //{
  385. // APP.W_CountdownWindow.Initialize();
  386. // //APP.W_CountdownWindow.Topmost = true;
  387. //}
  388. //APP.W_CountdownWindow.Show();
  389. //#endregion
  390. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar25.png"));//播放状态
  391. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar14.png"));
  392. BtnStopRecordingScreen.IsEnabled = true; //停止录制按钮可点击
  393. imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar27.png"));
  394. btnBlackPenOne.IsEnabled = true;//蓝笔可点击
  395. imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar28.png"));
  396. btnBlackPenTwo.IsEnabled = true;//红笔可点击
  397. txbTime.Visibility = Visibility.Visible;//时间显示
  398. //imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar30.png"));
  399. //borOne.Background = new SolidColorBrush(Colors.LightBlue);
  400. BtnRecordingScreen.ToolTip = "暂停";
  401. #region 隐藏工具栏
  402. if (APP.IsHideSRTool)
  403. {
  404. if (APP.W_MinToolbar == null)
  405. {
  406. APP.W_MinToolbar = new MinToolbar();
  407. }
  408. APP.W_MinToolbar.Topmost = true;
  409. APP.W_MinToolbar.Initialize(this.Top);
  410. gridToobar.Visibility = Visibility.Hidden;
  411. APP.W_MinToolbar.Show();
  412. }
  413. #endregion
  414. try
  415. {
  416. #region 4秒内不可点击
  417. new Thread(new ThreadStart(new Action(() =>
  418. {
  419. //Dispatcher.Invoke(() =>
  420. //{
  421. // ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
  422. // BtnRecordingScreen.IsEnabled = false;
  423. // BtnStopRecordingScreen.IsEnabled = false;
  424. //});
  425. //Thread.Sleep(4000);
  426. Dispatcher.Invoke(() =>
  427. {
  428. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar14.png"));
  429. BtnRecordingScreen.IsEnabled = true;
  430. BtnStopRecordingScreen.IsEnabled = true;
  431. });
  432. }))).Start();
  433. #endregion
  434. new Thread(new ThreadStart(new Action(() =>
  435. {
  436. if (IsFirstRS)
  437. {
  438. Thread.Sleep(800);
  439. }
  440. if (APP.FFmpeg.myProcess != null)
  441. {
  442. Thread.Sleep(100);
  443. }
  444. System.Drawing.Size DesktopSize = PrimaryScreen.DESKTOP;
  445. bool SynRes = APP.FFmpeg.StartRecordingVideo(VideoSavePathName, DesktopSize, out string ErrMessage);
  446. Thread.Sleep(1300);
  447. Dispatcher.Invoke(() =>
  448. {
  449. if (!SynRes)
  450. {
  451. MessageWindow.Show(ErrMessage);
  452. //隐藏画笔工具栏
  453. //BtnToolbarDown_Click(null, null);
  454. gridToolbar.Visibility = Visibility.Hidden;
  455. gridColour.Visibility = Visibility.Hidden;
  456. gridThickness.Visibility = Visibility.Hidden;
  457. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar26.png"));//大圆圈三角形
  458. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
  459. BtnStopRecordingScreen.IsEnabled = false; //停止录制按钮不点击
  460. imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  461. btnBlackPenOne.IsEnabled = false;//蓝笔不可点击
  462. imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  463. btnBlackPenTwo.IsEnabled = false;//红笔不可点击
  464. txbTime.Visibility = Visibility.Hidden;//时间不显示
  465. BtnRecordingScreen.ToolTip = "开始";
  466. IsSuspend = true;
  467. IsFirstRS = true;
  468. return;
  469. }
  470. Stack();
  471. });
  472. }))).Start();
  473. }
  474. catch (Exception ex)
  475. {
  476. MessageWindow.Show(ex.Message);
  477. }
  478. IsFirstRS = false;
  479. }
  480. else
  481. {
  482. TimeOut();
  483. IsSuspend = true;
  484. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar26.png"));//大圆圈三角形
  485. BtnStopRecordingScreen.IsEnabled = false; //停止录制按钮不点击
  486. BtnRecordingScreen.ToolTip = "开始";
  487. //imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  488. //btnBlackPenOne.IsEnabled = false;//蓝笔不可点击
  489. //imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  490. //btnBlackPenTwo.IsEnabled = false;//红笔不可点击
  491. txbTime.Visibility = Visibility.Hidden;//时间不显示
  492. //imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar29.png"));
  493. //btnReturn.IsEnabled = true;//返回主界面可点击
  494. #region 2秒内不可点击
  495. new Thread(new ThreadStart(new Action(() =>
  496. {
  497. //Dispatcher.Invoke(() =>
  498. //{
  499. // ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
  500. // BtnRecordingScreen.IsEnabled = false;
  501. // BtnStopRecordingScreen.IsEnabled = false;
  502. //});
  503. //Thread.Sleep(2000);
  504. Dispatcher.Invoke(() =>
  505. {
  506. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar14.png"));
  507. BtnRecordingScreen.IsEnabled = true;
  508. BtnStopRecordingScreen.IsEnabled = true;
  509. });
  510. }))).Start();
  511. #endregion
  512. try
  513. {
  514. APP.FFmpeg.SuspendFFmpeg();
  515. }
  516. catch (Exception ex)
  517. {
  518. MessageWindow.Show(ex.Message);
  519. }
  520. }
  521. }
  522. /// <summary>
  523. /// 停止录像
  524. /// </summary>
  525. /// <param name="sender"></param>
  526. /// <param name="e"></param>
  527. private void BtnStopRecordingScreen_Click(object sender, RoutedEventArgs e)
  528. {
  529. #region 防止连击
  530. if (IsPressButton)
  531. {
  532. return;
  533. }
  534. else
  535. {
  536. IsPressButton = true;
  537. new Thread(new ThreadStart(new Action(() =>
  538. {
  539. Thread.Sleep(500);
  540. IsPressButton = false;
  541. }))).Start();
  542. }
  543. #endregion
  544. if (APP.W_MinToolbar != null)
  545. {
  546. APP.W_MinToolbar.Hide();
  547. }
  548. BtnRecordingScreen.ToolTip = "开始";
  549. k_hook.Stop();
  550. IsSuspend = true;
  551. txbTime.Text = "00:00";
  552. txbTime.Visibility = Visibility.Hidden;
  553. End();
  554. if (APP.W_PracticeWindow != null)
  555. {
  556. if (APP.W_PracticeWindow.Visibility == Visibility.Visible)
  557. {
  558. Owner = null;
  559. APP.W_PracticeWindow.ReturnPractice();
  560. }
  561. }
  562. if (gridToolbar.Visibility == Visibility.Visible)
  563. {
  564. gridToolbar.Visibility = Visibility.Hidden;
  565. gridColour.Visibility = Visibility.Hidden;
  566. gridThickness.Visibility = Visibility.Hidden;
  567. }
  568. if (APP.W_XHMicroLessonSystemWindow == null)
  569. {
  570. APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
  571. }
  572. APP.W_XHMicroLessonSystemWindow.InitializeKeyDownEvent();
  573. APP.W_XHMicroLessonSystemWindow.InitPen();
  574. APP.W_XHMicroLessonSystemWindow.InitTQLPPen();
  575. APP.W_XHMicroLessonSystemWindow.Show();
  576. if (!IsFirstRS)
  577. {
  578. try
  579. {
  580. if (SRTime.Hour > 0 || SRTime.Minute > 0 || SRTime.Second > 3)
  581. {
  582. try
  583. {
  584. APP.FFmpeg.StopFFmpeg(VideoSavePathName);
  585. }
  586. catch (Exception ex)
  587. {
  588. LogHelper.WriteErrLog("【停止录屏】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  589. }
  590. IsFirstRS = true;
  591. //生成缩略图
  592. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  593. FileToolsCommon.CreateDirectory(ThumbnailPath);
  594. //缩略图存储位置
  595. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileName(VideoSavePathName).Replace(".", "") + ".JPG";
  596. new Thread(new ThreadStart(new Action(() =>
  597. {
  598. while (!FileToolsCommon.IsExistFile(VideoSavePathName))
  599. {
  600. Thread.Sleep(100);
  601. }
  602. FileToolsCommon.DeleteFile(ThumbnailPathName);
  603. //VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  604. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  605. VideoInfo.VideoPath = VideoSavePathName;
  606. VideoInfo.ThumbnailPath = ThumbnailPathName;
  607. APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName, 200, 130);
  608. VideoInfo.FileGuid = Guid.NewGuid().ToString();
  609. VideoInfo.IsUpload = false;
  610. VideoInfo.Uploaded = 0;
  611. //VideoInfo.Savefolder = APP.UserInfo.Schoolid + "/resource";
  612. APP.VideoList.Add(VideoInfo);
  613. //保存数据
  614. APP.SaveWkData();
  615. }))).Start();
  616. Click_stopRecordingScreen();
  617. }
  618. else
  619. {
  620. //视频过短
  621. APP.FFmpeg.SuspendFFmpeg();
  622. IsFirstRS = true;
  623. MessageWindow.Show("录屏时间过短,请重新录制!");
  624. }
  625. }
  626. catch (Exception ex)
  627. {
  628. LogHelper.WriteErrLog("【停止录屏】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  629. }
  630. }
  631. Hide();
  632. }
  633. public void MaxToobar()
  634. {
  635. Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);
  636. float DIP = graphics.DpiX;
  637. float DIPY = graphics.DpiY;
  638. APP.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.WorkingArea.Width / (DIP / 96) - APP.W_ScreenRecordingToolbarWindow.Width + 10;
  639. gridToobar.Visibility = Visibility.Visible;
  640. }
  641. #endregion
  642. #region 画笔相关
  643. /// <summary>
  644. /// 画笔工具栏关闭事件
  645. /// </summary>
  646. /// <param name="sender"></param>
  647. /// <param name="e"></param>
  648. private void BtnToolbarDown_Click(object sender, RoutedEventArgs e)
  649. {
  650. gridToolbar.Visibility = Visibility.Hidden;
  651. gridColour.Visibility = Visibility.Hidden;
  652. gridThickness.Visibility = Visibility.Hidden;
  653. APP.W_PracticeWindow.Hide();
  654. }
  655. /// <summary>
  656. /// 笔调用批注
  657. /// </summary>
  658. public void PenPractice()
  659. {
  660. if (!IsFirstRS)
  661. {
  662. if (flg != 11 && flg != 10)
  663. {
  664. #region 防止连击
  665. if (IsPressButton)
  666. {
  667. return;
  668. }
  669. else
  670. {
  671. IsPressButton = true;
  672. new Thread(new ThreadStart(new Action(() =>
  673. {
  674. Thread.Sleep(500);
  675. IsPressButton = false;
  676. }))).Start();
  677. }
  678. #endregion
  679. string time = GetTimeStamp();
  680. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  681. if (!Directory.Exists(tempPath))
  682. {
  683. Directory.CreateDirectory(tempPath);
  684. }
  685. try
  686. {
  687. Dispatcher.Invoke(() =>
  688. {
  689. borOne.Background = new SolidColorBrush(Colors.LightSkyBlue);
  690. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  691. if (APP.W_PracticeWindow == null)
  692. {
  693. APP.W_PracticeWindow = new PracticeWindow
  694. {
  695. Width = pwidth,
  696. Height = pHeight,
  697. Left = 0,
  698. Top = 0
  699. };
  700. //practiceWin.Owner = this;
  701. }
  702. //APP.W_PracticeWindow.InitPen();
  703. //APP.W_PracticeWindow.InitTQLPPen();
  704. APP.W_PracticeWindow.Initialize();// imagePath);
  705. APP.W_PracticeWindow.Focus();
  706. flg = 11;
  707. APP.W_PracticeWindow.Blue();
  708. APP.W_PracticeWindow.Show();
  709. });
  710. new Thread(new ThreadStart(new Action(() =>
  711. {
  712. Dispatcher.Invoke(() =>
  713. {
  714. APP.W_PracticeWindow.Topmost = true;
  715. });
  716. Thread.Sleep(100);
  717. Dispatcher.Invoke(() =>
  718. {
  719. APP.W_PracticeWindow.Topmost = false;
  720. //Owner = APP.W_PracticeWindow;
  721. Topmost = true;
  722. });
  723. }))).Start();
  724. }
  725. catch (Exception ex)
  726. {
  727. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  728. }
  729. }
  730. }
  731. }
  732. /// <summary>
  733. /// 画笔点击事件
  734. /// </summary>
  735. /// <param name="sender"></param>
  736. /// <param name="e"></param>
  737. private void BtnBrush_Click(object sender, RoutedEventArgs e)
  738. {
  739. #region 防止连击
  740. if (IsPressButton)
  741. {
  742. return;
  743. }
  744. else
  745. {
  746. IsPressButton = true;
  747. new Thread(new ThreadStart(new Action(() =>
  748. {
  749. Thread.Sleep(500);
  750. IsPressButton = false;
  751. }))).Start();
  752. }
  753. #endregion
  754. string time = GetTimeStamp();
  755. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  756. if (!Directory.Exists(tempPath))
  757. {
  758. Directory.CreateDirectory(tempPath);
  759. }
  760. #region 录屏批注取消画笔
  761. //string imagePath = Path.Combine(tempPath, time + ".jpg");
  762. //ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  763. #endregion
  764. try
  765. {
  766. if (flg == 11)
  767. {
  768. Dispatcher.Invoke(() =>
  769. {
  770. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  771. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  772. });
  773. flg = 1;
  774. //this.Owner = null;
  775. APP.W_PracticeWindow.ReturnPractice();
  776. }
  777. else if (flg == 10)
  778. {
  779. Dispatcher.Invoke(() =>
  780. {
  781. borOne.Background = new SolidColorBrush(Colors.LightSkyBlue);
  782. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  783. });
  784. APP.W_PracticeWindow.Blue();
  785. flg = 11;
  786. }
  787. else
  788. {
  789. //new Thread(new ThreadStart(new Action(() =>
  790. //{
  791. Dispatcher.Invoke(() =>
  792. {
  793. borOne.Background = new SolidColorBrush(Colors.LightSkyBlue);
  794. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  795. });
  796. //}))).Start();
  797. if (APP.W_PracticeWindow == null)
  798. {
  799. APP.W_PracticeWindow = new PracticeWindow
  800. {
  801. //APP.W_PracticeWindow.Topmost = true;
  802. Width = pwidth,
  803. Height = pHeight,
  804. Left = 0,
  805. Top = 0
  806. };
  807. //practiceWin.Owner = this;
  808. }
  809. APP.W_PracticeWindow.InitPen();
  810. APP.W_PracticeWindow.InitTQLPPen();
  811. APP.W_PracticeWindow.Initialize();// imagePath);
  812. flg = 11;
  813. APP.W_PracticeWindow.Blue();
  814. APP.W_PracticeWindow.Show();
  815. new Thread(new ThreadStart(new Action(() =>
  816. {
  817. Thread.Sleep(100);
  818. Dispatcher.Invoke(() =>
  819. {
  820. Owner = APP.W_PracticeWindow;
  821. Topmost = true;
  822. });
  823. }))).Start();
  824. }
  825. }
  826. catch (Exception ex)
  827. {
  828. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  829. }
  830. //imgCanvas.Source = new BitmapImage(new Uri(imagePath));
  831. }
  832. /// <summary>
  833. /// 屏幕宽
  834. /// </summary>
  835. internal double pwidth = SystemParameters.PrimaryScreenWidth;
  836. /// <summary>
  837. /// 屏幕高
  838. /// </summary>
  839. internal double pHeight = SystemParameters.PrimaryScreenHeight;
  840. /// <summary>
  841. /// 获取时间戳
  842. /// </summary>
  843. /// <returns></returns>
  844. public string GetTimeStamp()
  845. {
  846. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  847. return Convert.ToInt64(ts.TotalMilliseconds).ToString();
  848. }
  849. /// <summary>
  850. /// 画笔粗细事件
  851. /// </summary>
  852. /// <param name="sender"></param>
  853. /// <param name="e"></param>
  854. private void BtnThickness_Click(object sender, RoutedEventArgs e)
  855. {
  856. gridThickness.Visibility = Visibility.Visible;
  857. gridColour.Visibility = Visibility.Collapsed;
  858. }
  859. /// <summary>
  860. /// 画笔颜色事件
  861. /// </summary>
  862. /// <param name="sender"></param>
  863. /// <param name="e"></param>
  864. private void BtnColour_Click(object sender, RoutedEventArgs e)
  865. {
  866. gridColour.Visibility = Visibility.Visible;
  867. gridThickness.Visibility = Visibility.Collapsed;
  868. }
  869. /// <summary>
  870. /// 白色
  871. /// </summary>
  872. /// <param name="sender"></param>
  873. /// <param name="e"></param>
  874. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  875. {
  876. //drawingAttributes.Color = Colors.White;
  877. APP.W_PracticeWindow.White();
  878. gridColour.Visibility = Visibility.Collapsed;
  879. gridThickness.Visibility = Visibility.Collapsed;
  880. }
  881. /// <summary>
  882. /// 红色
  883. /// </summary>
  884. /// <param name="sender"></param>
  885. /// <param name="e"></param>
  886. private void BtnRed_Click(object sender, RoutedEventArgs e)
  887. {
  888. //drawingAttributes.Color = Colors.Red;
  889. APP.W_PracticeWindow.Red();
  890. gridColour.Visibility = Visibility.Collapsed;
  891. gridThickness.Visibility = Visibility.Collapsed;
  892. }
  893. /// <summary>
  894. /// 黄色
  895. /// </summary>
  896. /// <param name="sender"></param>
  897. /// <param name="e"></param>
  898. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  899. {
  900. //drawingAttributes.Color = Colors.Gold;
  901. APP.W_PracticeWindow.Yellow();
  902. gridColour.Visibility = Visibility.Collapsed;
  903. gridThickness.Visibility = Visibility.Collapsed;
  904. }
  905. /// <summary>
  906. /// 青色
  907. /// </summary>
  908. /// <param name="sender"></param>
  909. /// <param name="e"></param>
  910. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  911. {
  912. //drawingAttributes.Color = Colors.LimeGreen;
  913. APP.W_PracticeWindow.CyanBlue();
  914. gridColour.Visibility = Visibility.Collapsed;
  915. gridThickness.Visibility = Visibility.Collapsed;
  916. }
  917. /// <summary>
  918. /// 灰色
  919. /// </summary>
  920. /// <param name="sender"></param>
  921. /// <param name="e"></param>
  922. private void BtnGray_Click(object sender, RoutedEventArgs e)
  923. {
  924. //drawingAttributes.Color = Colors.Gray;
  925. APP.W_PracticeWindow.Gray();
  926. gridColour.Visibility = Visibility.Collapsed;
  927. gridThickness.Visibility = Visibility.Collapsed;
  928. }
  929. /// <summary>
  930. /// 蓝色
  931. /// </summary>
  932. /// <param name="sender"></param>
  933. /// <param name="e"></param>
  934. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  935. {
  936. //drawingAttributes.Color = Colors.DeepSkyBlue;
  937. APP.W_PracticeWindow.Blue();
  938. gridColour.Visibility = Visibility.Collapsed;
  939. gridThickness.Visibility = Visibility.Collapsed;
  940. }
  941. /// <summary>
  942. /// 画笔 细
  943. /// </summary>
  944. /// <param name="sender"></param>
  945. /// <param name="e"></param>
  946. private void BtnFine_Click(object sender, RoutedEventArgs e)
  947. {
  948. APP.W_PracticeWindow.Fine();
  949. gridColour.Visibility = Visibility.Collapsed;
  950. gridThickness.Visibility = Visibility.Collapsed;
  951. }
  952. /// <summary>
  953. /// 画笔 中
  954. /// </summary>
  955. /// <param name="sender"></param>
  956. /// <param name="e"></param>
  957. private void BtnIn_Click(object sender, RoutedEventArgs e)
  958. {
  959. APP.W_PracticeWindow.In();
  960. gridColour.Visibility = Visibility.Collapsed;
  961. gridThickness.Visibility = Visibility.Collapsed;
  962. }
  963. /// <summary>
  964. /// 画笔粗
  965. /// </summary>
  966. /// <param name="sender"></param>
  967. /// <param name="e"></param>
  968. private void BtnCrude_Click(object sender, RoutedEventArgs e)
  969. {
  970. APP.W_PracticeWindow.Crude();
  971. gridColour.Visibility = Visibility.Collapsed;
  972. gridThickness.Visibility = Visibility.Collapsed;
  973. }
  974. /// <summary>
  975. /// 橡皮
  976. /// </summary>
  977. /// <param name="sender"></param>
  978. /// <param name="e"></param>
  979. private void BtnEraser_Click(object sender, RoutedEventArgs e)
  980. {
  981. APP.W_PracticeWindow.Eraser();
  982. }
  983. /// <summary>
  984. /// 🖊
  985. /// </summary>
  986. /// <param name="sender"></param>
  987. /// <param name="e"></param>
  988. private void BtnPen_Click(object sender, RoutedEventArgs e)
  989. {
  990. APP.W_PracticeWindow.Pen();
  991. }
  992. /// <summary>
  993. /// ⚪
  994. /// </summary>
  995. /// <param name="sender"></param>
  996. /// <param name="e"></param>
  997. private void BtnRound_Click(object sender, RoutedEventArgs e)
  998. {
  999. APP.W_PracticeWindow.Round();
  1000. }
  1001. /// <summary>
  1002. /// 矩形
  1003. /// </summary>
  1004. /// <param name="sender"></param>
  1005. /// <param name="e"></param>
  1006. private void BtnRectangle_Click(object sender, RoutedEventArgs e)
  1007. {
  1008. APP.W_PracticeWindow.Rectangle();
  1009. }
  1010. #endregion
  1011. #endregion
  1012. /// <summary>
  1013. /// 停止录屏
  1014. /// </summary>
  1015. public delegate void StopRecordingScreen();
  1016. /// <summary>
  1017. /// 停止录屏
  1018. /// </summary>
  1019. public event StopRecordingScreen Click_stopRecordingScreen;
  1020. /// <summary>
  1021. /// 黑笔
  1022. /// </summary>
  1023. /// <param name="sender"></param>
  1024. /// <param name="e"></param>
  1025. private void BtnBlackPen_Click(object sender, RoutedEventArgs e)
  1026. {
  1027. }
  1028. /// <summary>
  1029. /// 移动工具栏
  1030. /// </summary>
  1031. /// <param name="sender"></param>
  1032. /// <param name="e"></param>
  1033. private void Grid_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  1034. {
  1035. DragMove();
  1036. }
  1037. /// <summary>
  1038. /// 红笔
  1039. /// </summary>
  1040. /// <param name="sender"></param>
  1041. /// <param name="e"></param>
  1042. private void BtnBlackPenTwo_Click(object sender, RoutedEventArgs e)
  1043. {
  1044. #region 防止连击
  1045. if (IsPressButton)
  1046. {
  1047. return;
  1048. }
  1049. else
  1050. {
  1051. IsPressButton = true;
  1052. new Thread(new ThreadStart(new Action(() =>
  1053. {
  1054. Thread.Sleep(500);
  1055. IsPressButton = false;
  1056. }))).Start();
  1057. }
  1058. #endregion
  1059. string time = GetTimeStamp();
  1060. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  1061. if (!Directory.Exists(tempPath))
  1062. {
  1063. Directory.CreateDirectory(tempPath);
  1064. }
  1065. #region 录屏批注取消画笔
  1066. string imagePath = Path.Combine(tempPath, time + ".jpg");
  1067. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  1068. #endregion
  1069. try
  1070. {
  1071. if (flg == 10)
  1072. {
  1073. Dispatcher.Invoke(() =>
  1074. {
  1075. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  1076. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  1077. });
  1078. flg = 0;
  1079. //this.Owner = null;
  1080. APP.W_PracticeWindow.ReturnPractice();
  1081. }
  1082. else if (flg == 11)
  1083. {
  1084. Dispatcher.Invoke(() =>
  1085. {
  1086. borTwo.Background = new SolidColorBrush(Colors.LightSkyBlue);
  1087. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  1088. });
  1089. flg = 10;
  1090. APP.W_PracticeWindow.Red();
  1091. }
  1092. else
  1093. {
  1094. Dispatcher.Invoke(() =>
  1095. {
  1096. borTwo.Background = new SolidColorBrush(Colors.LightSkyBlue);
  1097. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  1098. });
  1099. if (APP.W_PracticeWindow == null)
  1100. {
  1101. APP.W_PracticeWindow = new PracticeWindow
  1102. {
  1103. //APP.W_PracticeWindow.Topmost = true;
  1104. Width = pwidth,
  1105. Height = pHeight,
  1106. Left = 0,
  1107. Top = 0
  1108. };
  1109. //practiceWin.Owner = this;
  1110. }
  1111. APP.W_PracticeWindow.InitPen();
  1112. APP.W_PracticeWindow.InitTQLPPen();
  1113. APP.W_PracticeWindow.Initialize();//imagePath);
  1114. flg = 10;
  1115. APP.W_PracticeWindow.Red();
  1116. APP.W_PracticeWindow.Show();
  1117. new Thread(new ThreadStart(new Action(() =>
  1118. {
  1119. Thread.Sleep(100);
  1120. Dispatcher.Invoke(() =>
  1121. {
  1122. Owner = APP.W_PracticeWindow;
  1123. Topmost = true;
  1124. });
  1125. }))).Start();
  1126. }
  1127. }
  1128. catch (Exception ex)
  1129. {
  1130. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  1131. }
  1132. }
  1133. /// <summary>
  1134. /// 鼠标右键按下事件 废弃
  1135. /// </summary>
  1136. /// <param name="sender"></param>
  1137. /// <param name="e"></param>
  1138. private void RightButtonDown()
  1139. {
  1140. if (flg > 9)
  1141. {
  1142. Owner = null;
  1143. APP.W_PracticeWindow.Hide();
  1144. }
  1145. else
  1146. {
  1147. //string time = GetTimeStamp();
  1148. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  1149. if (!Directory.Exists(tempPath))
  1150. {
  1151. Directory.CreateDirectory(tempPath);
  1152. }
  1153. #region 录屏批注取消画笔
  1154. //string imagePath = Path.Combine(tempPath, time + ".jpg");
  1155. //ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  1156. #endregion
  1157. try
  1158. {
  1159. if (APP.W_PracticeWindow == null)
  1160. {
  1161. APP.W_PracticeWindow = new PracticeWindow
  1162. {
  1163. //APP.W_PracticeWindow.Topmost = true;
  1164. Width = pwidth,
  1165. Height = pHeight,
  1166. Left = 0,
  1167. Top = 0
  1168. };
  1169. //practiceWin.Owner = this;
  1170. }
  1171. APP.W_PracticeWindow.InitPen();
  1172. APP.W_PracticeWindow.InitTQLPPen();
  1173. APP.W_PracticeWindow.Initialize();//imagePath);
  1174. if (flg == 0)
  1175. {
  1176. flg = 10;
  1177. APP.W_PracticeWindow.Red();
  1178. }
  1179. else
  1180. {
  1181. flg = 11;
  1182. APP.W_PracticeWindow.Blue();
  1183. }
  1184. APP.W_PracticeWindow.Show();
  1185. }
  1186. catch (Exception ex)
  1187. {
  1188. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  1189. }
  1190. }
  1191. }
  1192. /// <summary>
  1193. /// 返回主界面
  1194. /// </summary>
  1195. /// <param name="sender"></param>
  1196. /// <param name="e"></param>
  1197. private void BtnReturn_Click(object sender, RoutedEventArgs e)
  1198. {
  1199. if (!IsFirstRS)
  1200. {
  1201. MessageBoxResult br = MessageWindow.Show("退出将取消保存当前录屏,是否继续?", "提示", MessageBoxButton.OKCancel);
  1202. if (br == MessageBoxResult.Cancel)
  1203. {
  1204. return;
  1205. }
  1206. k_hook.Stop();
  1207. BtnRecordingScreen.ToolTip = "开始";
  1208. if (APP.W_MinToolbar != null)
  1209. {
  1210. APP.W_MinToolbar.Hide();
  1211. }
  1212. IsSuspend = true;
  1213. txbTime.Text = "00:00";
  1214. txbTime.Visibility = Visibility.Hidden;
  1215. End();
  1216. APP.W_PracticeWindow.ReturnPractice();
  1217. if (APP.W_PracticeWindow != null)
  1218. {
  1219. if (APP.W_PracticeWindow.Visibility == Visibility.Visible)
  1220. {
  1221. APP.W_PracticeWindow.Hide();
  1222. }
  1223. }
  1224. if (gridToolbar.Visibility == Visibility.Visible)
  1225. {
  1226. gridToolbar.Visibility = Visibility.Hidden;
  1227. gridColour.Visibility = Visibility.Hidden;
  1228. gridThickness.Visibility = Visibility.Hidden;
  1229. }
  1230. if (APP.W_XHMicroLessonSystemWindow == null)
  1231. {
  1232. APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
  1233. }
  1234. try
  1235. {
  1236. try
  1237. {
  1238. APP.FFmpeg.SuspendFFmpeg();
  1239. }
  1240. catch (Exception ex)
  1241. {
  1242. LogHelper.WriteErrLog("【录屏返回】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  1243. }
  1244. IsFirstRS = true;
  1245. new Thread(new ThreadStart(new Action(() =>
  1246. {
  1247. VideoInfo = null;
  1248. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temprs/");
  1249. }))).Start();
  1250. }
  1251. catch (Exception ex)
  1252. {
  1253. LogHelper.WriteErrLog("【录屏返回】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  1254. }
  1255. }
  1256. APP.W_XHMicroLessonSystemWindow.InitializeKeyDownEvent();
  1257. APP.W_XHMicroLessonSystemWindow.InitPen();
  1258. APP.W_XHMicroLessonSystemWindow.InitTQLPPen();
  1259. APP.W_XHMicroLessonSystemWindow.Show();
  1260. Hide();
  1261. }
  1262. /// <summary>
  1263. /// 批注退出 废弃
  1264. /// </summary>
  1265. public void ReturnPractice()
  1266. {
  1267. new Thread(new ThreadStart(new Action(() =>
  1268. {
  1269. Dispatcher.Invoke(() =>
  1270. {
  1271. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  1272. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  1273. });
  1274. flg = 0;
  1275. Thread.Sleep(500);
  1276. Dispatcher.Invoke(() =>
  1277. {
  1278. Owner = null;
  1279. APP.W_PracticeWindow.Hide();
  1280. });
  1281. }))).Start();
  1282. //Dispatcher.Invoke(() =>
  1283. //{
  1284. // borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  1285. // borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  1286. //});
  1287. //flg = 0;
  1288. //Thread.Sleep(300);
  1289. //APP.W_PracticeWindow.Hide();
  1290. }
  1291. /// <summary>
  1292. /// 修改笔状态
  1293. /// </summary>
  1294. public void ModifyState()
  1295. {
  1296. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  1297. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  1298. }
  1299. /// <summary>
  1300. /// 切换页面
  1301. /// </summary>
  1302. void SwitchPages()
  1303. {
  1304. //SendKeys.SendWait("%{TAB}");
  1305. MouseEventCommon.MouseMiddleClickEvent(0);
  1306. }
  1307. bool isToobar = false;
  1308. /// <summary>
  1309. /// 在工具条区域内
  1310. /// </summary>
  1311. /// <param name="sender"></param>
  1312. /// <param name="e"></param>
  1313. private void gridToobarTwo_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
  1314. {
  1315. isToobar = true;
  1316. }
  1317. private void gridToobarTwo_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
  1318. {
  1319. if (BtnRecordingScreen.ToolTip.ToString().Equals("暂停") && gridToobar.Visibility == Visibility.Visible)
  1320. {
  1321. if (APP.IsHideSRTool)
  1322. {
  1323. if (APP.W_MinToolbar == null)
  1324. {
  1325. APP.W_MinToolbar = new MinToolbar();
  1326. }
  1327. APP.W_MinToolbar.Topmost = true;
  1328. APP.W_MinToolbar.Initialize(this.Top);
  1329. //else
  1330. //{
  1331. // APP.W_CountdownWindow.Initialize(true, 1800);
  1332. //}
  1333. new Thread(new ThreadStart(new Action(() =>
  1334. {
  1335. Thread.Sleep(500);
  1336. Dispatcher.Invoke(() =>
  1337. {
  1338. gridToobar.Visibility = Visibility.Hidden;
  1339. APP.W_MinToolbar.Show();
  1340. });
  1341. }))).Start();
  1342. //Console.WriteLine(this.Top+"max");
  1343. }
  1344. }
  1345. }
  1346. }
  1347. }