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

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