星火微课系统客户端
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ScreenRecordingToolbarWindow.xaml.cs 58KB

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