12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286 |
- using Common.system;
-
- using System;
- using System.Drawing;
- using System.IO;
- using System.Threading;
- using System.Windows;
- using System.Windows.Forms;
- using System.Windows.Ink;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Threading;
-
- using XHWK.Model;
-
- namespace XHWK.WKTool
- {
- /// <summary>
- /// 录屏工具栏
- /// </summary>
- public partial class ScreenRecordingToolbarWindow : Window
- {
- #region 初始变量
- /// <summary>
- /// 视频保存名称
- /// </summary>
- private string VideoSavePathName;
-
- /// <summary>
- /// 是否首次录屏
- /// </summary>
- private bool IsFirstRS = true;
-
- /// <summary>
- /// 是否暂停
- /// </summary>
- private bool IsSuspend = true;
-
- /// <summary>
- /// 视频信息
- /// </summary>
- private Model_Video VideoInfo = null;
-
- //声明一个 DrawingAttributes 类型的变量
- private DrawingAttributes drawingAttributes;
- private DispatcherTimer t = null;
- /// <summary>
- /// 计时器状态
- /// </summary>
- private enum State
- {
- Start,
- Pause,
- End
- }
- /// <summary>
- /// 状态
- /// </summary>
- private State _state = State.End;
-
- private KeyboardHookCommon k_hook;
- /// <summary>
- /// 🖊状态 0红色 1蓝色 10红色批注内 11蓝色批注内
- /// </summary>
- public int flg = 0;
- private System.Timers.Timer timer = new System.Timers.Timer();
- #endregion
-
- #region 初始化
- /// <summary>
- /// 录屏工具栏
- /// </summary>
- public ScreenRecordingToolbarWindow()
- {
- InitializeComponent();
- ResizeMode = ResizeMode.NoResize;
- }
- /// <summary>
- /// 初始化
- /// </summary>
- public void Initialize()
- {
- gridToobar.Visibility = Visibility.Visible;
- if (APP.W_PracticeWindow == null)
- {
- APP.W_PracticeWindow = new PracticeWindow
- {
- //APP.W_PracticeWindow.Topmost = true;
- Width = pwidth,
- Height = pHeight,
- Left = 0,
- Top = 0
- };
- //practiceWin.Owner = this;
- }
- APP.W_PracticeWindow.Show();
- new Thread(new ThreadStart(new Action(() =>
- {
- Thread.Sleep(100);
- Dispatcher.Invoke(() =>
- {
- Owner = APP.W_PracticeWindow;
- Topmost = true;
- });
- }))).Start();
- APP.W_PracticeWindow.Hide();
-
- //timer = new System.Timers.Timer(200);
- //timer.Interval = 300;
- //timer.Elapsed += new System.Timers.ElapsedEventHandler(TimerDealy);
- //timer.Enabled = true; //启动计时器
-
- borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
- borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
- flg = 0;
-
-
- k_hook = new KeyboardHookCommon();
- k_hook.KeyDownEvent += K_hook_KeyDownEvent;
-
- //创建 DrawingAttributes 类的一个实例
- drawingAttributes = new DrawingAttributes();
- //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
- //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
- blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
- drawingAttributes.FitToCurve = true;
- //隐藏画笔工具栏
- //BtnToolbarDown_Click(null, null);
- gridToolbar.Visibility = Visibility.Hidden;
- gridColour.Visibility = Visibility.Hidden;
- gridThickness.Visibility = Visibility.Hidden;
- ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar26.png"));//大圆圈三角形
- ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
- BtnStopRecordingScreen.IsEnabled = false; //停止录制按钮不点击
- imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
- btnBlackPenOne.IsEnabled = false;//蓝笔不可点击
- imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
- btnBlackPenTwo.IsEnabled = false;//红笔不可点击
- //imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar29.png"));
- //btnReturn.IsEnabled = true;//返回主界面可点击
- txbTime.Visibility = Visibility.Hidden;//时间不显示
- BtnRecordingScreen.ToolTip = "开始";
- if (t == null)
- {
- t = new DispatcherTimer();
- t.Tick += OnTimer;
- t.Interval = new TimeSpan(0, 0, 0, 0, 300);
- t.IsEnabled = true;
- t.Start();
- }
- t.Interval = new TimeSpan(0, 0, 0, 0, 300);
- //Stack();
- //ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar25.png"));
- //BtnRecordingScreen_Click(null, null);
- }
-
- private void TimerDealy(object o, EventArgs e)
- {
- Dispatcher.Invoke(() =>
- {
- if (Left > 1630)
- {
- return;
- }
- //获取鼠标在屏幕上的位置
- double mouse_x = Form.MousePosition.X; //需要添加引用System.Drawing
- double mouse_y = Form.MousePosition.Y;
-
- bool is_in_collasped_range = (mouse_y > Left + Height) || (mouse_x < Left || mouse_x > Left + Width);//缩起的条件
- bool is_in_visiable_range = (mouse_y < 1 && mouse_x >= Left && mouse_x <= Left + Width); //展开的条件
-
- if (Left < 1630 && Left >= 0 && is_in_collasped_range)
- {
- System.Threading.Thread.Sleep(300);
- Left += 20 /*-this.ActualWidth - 3*/;
- }
- else if (Left < 0 && is_in_visiable_range)
- {
- Left = 1;
- }
- });
- }
- private void K_hook_KeyDownEvent(object sender, System.Windows.Forms.KeyEventArgs e)
- {
- if (e.KeyValue == (int)System.Windows.Forms.Keys.F5 && (int)Control.ModifierKeys == (int)Keys.Control)
- {
- //开始,暂停
- BtnRecordingScreen_Click(null, null);
- }
- if (e.KeyValue == (int)Keys.S && (int)Control.ModifierKeys == (int)Keys.Control)
- {
- //结束
- BtnStopRecordingScreen_Click(null, null);
- }
-
- }
- #endregion
-
- #region 事件
- /// <summary>
- /// 记录上次执行时间
- /// </summary>
- private DateTime Recorddt = DateTime.Now;
- DateTime SRTime = Convert.ToDateTime("2020-01-01 00:00:00");
- /// <summary>
- /// 时钟回调
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OnTimer(object sender, EventArgs e)
- {
- switch (_state)
- {
- case State.Start:
- {
- DateTime dt = DateTime.Now;
- TimeSpan ts = dt.Subtract(Recorddt);//时间差
- double tsmi = ts.TotalMilliseconds;
- if (tsmi > 500.0)
- {
- Recorddt = Recorddt.AddMilliseconds(500);
- SRTime = SRTime.AddMilliseconds(500);
- }
- }
- break;
-
- case State.Pause:
- {
- }
- break;
-
- case State.End:
- {
- SRTime = Convert.ToDateTime("2020-01-01 00:00:00");
- //_timeSpan = new TimeSpan();
- ////_timeSpan = new TimeSpan(0, 23, 12, 45, 54);
- }
- break;
- }
-
- //string time = string.Format("{0:D2}:{1:D2}",/* _timeSpan.Hours,*/ _timeSpan.Minutes, _timeSpan.Seconds);
- //char[] times = time.ToCharArray();
- if (SRTime.Hour > 0)
- {
- //Dispatcher.Invoke(() =>
- //{
- txbTime.Text = SRTime.ToString("HH:mm:ss");
- //});
- }
- else
- {
- //Dispatcher.Invoke(() =>
- //{
- txbTime.Text = SRTime.ToString("mm:ss");
- //});
- }
- }
-
- /// <summary>
- /// 开始
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Stack()
- {
- Recorddt = DateTime.Now;
- _state = State.Start;
- }
- /// <summary>
- /// 暂停
- /// </summary>
- private void TimeOut()
- {
- _state = State.Pause;
- }
- /// <summary>
- /// 结束
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void End()
- {
- _state = State.End;
- }
- #region 录屏
- /// <summary>
- /// 设置录屏文件地址
- /// </summary>
- private void SetUpVideoPathName()
- {
- //FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
- FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
- FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temprs/");
- VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
- int num = 1;
- while (FileToolsCommon.IsExistFile(VideoSavePathName))
- {
- VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏_" + num + "." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
- num++;
- }
- }
-
- /// <summary>
- /// 是否已经按下按钮
- /// </summary>
- private bool IsPressButton = false;
- /// <summary>
- /// 开始或暂停录制
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnRecordingScreen_Click(object sender, RoutedEventArgs e)
- {
- #region 防止连击
- if (IsPressButton)
- {
- return;
- }
- else
- {
- IsPressButton = true;
- new Thread(new ThreadStart(new Action(() =>
- {
- Thread.Sleep(500);
- IsPressButton = false;
- }))).Start();
- }
- #endregion
- if (IsSuspend)
- {
- if (IsFirstRS)
- {
- #region 检测麦克风扬声器是否可用
- string audioSpeakerPath = FileToolsCommon.GetFileAbsolutePath("adoS.m");
- string audioMicrophonePath = FileToolsCommon.GetFileAbsolutePath("adoM.m");
- try
- {
- FileToolsCommon.DeleteFile(audioSpeakerPath);
- FileToolsCommon.DeleteFile(audioMicrophonePath);
- }
- catch (Exception)
- {
-
- }
- //扬声器
- if (APP.FFmpeg.StartRecordSpeakerAudio(audioSpeakerPath))
- {
- APP.FFmpeg.StopRecordAudio(2);
- //Thread.Sleep(500);
- //麦克风
- if (APP.FFmpeg.StartRecordAudio(audioMicrophonePath))
- {
- }
- else
- {
- //无法录制麦克风
- MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制麦克风,是否继续?", "消息提示", MessageBoxButton.OKCancel);
- if (Res == MessageBoxResult.Cancel)
- {
- return;
- }
- }
- APP.FFmpeg.StopRecordAudio(1);
- }
- else
- {
- //无法录制扬声器音频
- MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制音频,是否继续?", "消息提示", MessageBoxButton.OKCancel);
- if (Res == MessageBoxResult.Cancel)
- {
- return;
- }
- }
- #endregion
-
- VideoInfo = new Model_Video
- {
- VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType")),
- WkType = Enum_WKVidetype.RecordingScreen
- };
- SetUpVideoPathName();
- k_hook.Start();//安装键盘钩子
-
- if (APP.W_CountdownWindow == null)
- {
- APP.W_CountdownWindow = new CountdownWindow();
- APP.W_CountdownWindow.Initialize(true, 1800);
- //APP.W_CountdownWindow.Topmost = true;
- }
- else
- {
- APP.W_CountdownWindow.Initialize(true, 1800);
- //APP.W_CountdownWindow.Topmost = true;
- }
- APP.W_CountdownWindow.Show();
- }
- IsSuspend = false;
-
- //#region 录像倒计时
- //if (APP.W_CountdownWindow == null)
- //{
- // APP.W_CountdownWindow = new CountdownWindow();
- // //APP.W_CountdownWindow.Topmost = true;
- //}
- //else
- //{
- // APP.W_CountdownWindow.Initialize();
- // //APP.W_CountdownWindow.Topmost = true;
- //}
- //APP.W_CountdownWindow.Show();
- //#endregion
-
-
- ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar25.png"));//播放状态
- ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar14.png"));
- BtnStopRecordingScreen.IsEnabled = true; //停止录制按钮可点击
- imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar27.png"));
- btnBlackPenOne.IsEnabled = true;//蓝笔可点击
- imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar28.png"));
- btnBlackPenTwo.IsEnabled = true;//红笔可点击
- txbTime.Visibility = Visibility.Visible;//时间显示
- //imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar30.png"));
- //borOne.Background = new SolidColorBrush(Colors.LightBlue);
- BtnRecordingScreen.ToolTip = "暂停";
-
- if (APP.W_MinToolbar == null)
- {
- APP.W_MinToolbar = new MinToolbar();
-
- }
- APP.W_MinToolbar.Initialize(this.Top);
- gridToobar.Visibility = Visibility.Hidden;
- APP.W_MinToolbar.Show();
- try
- {
- #region 4秒内不可点击
- new Thread(new ThreadStart(new Action(() =>
- {
- //Dispatcher.Invoke(() =>
- //{
- // ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
- // BtnRecordingScreen.IsEnabled = false;
- // BtnStopRecordingScreen.IsEnabled = false;
- //});
- //Thread.Sleep(4000);
- Dispatcher.Invoke(() =>
- {
- ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar14.png"));
- BtnRecordingScreen.IsEnabled = true;
- BtnStopRecordingScreen.IsEnabled = true;
- });
- }))).Start();
- #endregion
- new Thread(new ThreadStart(new Action(() =>
- {
- if (IsFirstRS)
- {
- Thread.Sleep(800);
- }
- if (APP.FFmpeg.myProcess != null)
- {
- Thread.Sleep(100);
- }
- System.Drawing.Size DesktopSize = PrimaryScreen.DESKTOP;
- bool SynRes = APP.FFmpeg.StartRecordingVideo(VideoSavePathName, DesktopSize, out string ErrMessage);
-
- Thread.Sleep(1300);
- Dispatcher.Invoke(() =>
- {
- if (!SynRes)
- {
- MessageWindow.Show(ErrMessage);
- //隐藏画笔工具栏
- //BtnToolbarDown_Click(null, null);
- gridToolbar.Visibility = Visibility.Hidden;
- gridColour.Visibility = Visibility.Hidden;
- gridThickness.Visibility = Visibility.Hidden;
- ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar26.png"));//大圆圈三角形
- ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
- BtnStopRecordingScreen.IsEnabled = false; //停止录制按钮不点击
- imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
- btnBlackPenOne.IsEnabled = false;//蓝笔不可点击
- imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
- btnBlackPenTwo.IsEnabled = false;//红笔不可点击
- txbTime.Visibility = Visibility.Hidden;//时间不显示
- BtnRecordingScreen.ToolTip = "开始";
- IsSuspend = true;
- IsFirstRS = true;
- return;
- }
- Stack();
- });
- }))).Start();
- }
- catch (Exception ex)
- {
- MessageWindow.Show(ex.Message);
- }
- IsFirstRS = false;
- }
- else
- {
- TimeOut();
- IsSuspend = true;
- ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar26.png"));//大圆圈三角形
- BtnStopRecordingScreen.IsEnabled = false; //停止录制按钮不点击
- BtnRecordingScreen.ToolTip = "开始";
- //imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
- //btnBlackPenOne.IsEnabled = false;//蓝笔不可点击
- //imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
- //btnBlackPenTwo.IsEnabled = false;//红笔不可点击
- txbTime.Visibility = Visibility.Hidden;//时间不显示
- //imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar29.png"));
- //btnReturn.IsEnabled = true;//返回主界面可点击
-
- #region 2秒内不可点击
- new Thread(new ThreadStart(new Action(() =>
- {
- //Dispatcher.Invoke(() =>
- //{
- // ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
- // BtnRecordingScreen.IsEnabled = false;
- // BtnStopRecordingScreen.IsEnabled = false;
- //});
- //Thread.Sleep(2000);
- Dispatcher.Invoke(() =>
- {
- ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar14.png"));
- BtnRecordingScreen.IsEnabled = true;
- BtnStopRecordingScreen.IsEnabled = true;
- });
- }))).Start();
- #endregion
- try
- {
- APP.FFmpeg.SuspendFFmpeg();
- }
- catch (Exception ex)
- {
- MessageWindow.Show(ex.Message);
- }
- }
- }
- /// <summary>
- /// 停止录像
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnStopRecordingScreen_Click(object sender, RoutedEventArgs e)
- {
- #region 防止连击
- if (IsPressButton)
- {
- return;
- }
- else
- {
- IsPressButton = true;
- new Thread(new ThreadStart(new Action(() =>
- {
- Thread.Sleep(500);
- IsPressButton = false;
- }))).Start();
- }
- #endregion
- APP.W_MinToolbar.Hide();
- BtnRecordingScreen.ToolTip = "开始";
- k_hook.Stop();
- IsSuspend = true;
- txbTime.Text = "00:00";
- txbTime.Visibility = Visibility.Hidden;
- End();
- if (APP.W_PracticeWindow != null)
- {
- if (APP.W_PracticeWindow.Visibility == Visibility.Visible)
- {
- Owner = null;
- APP.W_PracticeWindow.ReturnPractice();
- }
- }
- if (gridToolbar.Visibility == Visibility.Visible)
- {
- gridToolbar.Visibility = Visibility.Hidden;
- gridColour.Visibility = Visibility.Hidden;
- gridThickness.Visibility = Visibility.Hidden;
- }
- if (APP.W_XHMicroLessonSystemWindow == null)
- {
- APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
- }
- APP.W_XHMicroLessonSystemWindow.InitializeKeyDownEvent();
- APP.W_XHMicroLessonSystemWindow.Show();
- if (!IsFirstRS)
- {
- try
- {
- if (SRTime.Hour > 0 || SRTime.Minute > 0 || SRTime.Second > 3)
- {
- try
- {
- APP.FFmpeg.StopFFmpeg(VideoSavePathName);
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【停止录屏】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
- }
- IsFirstRS = true;
- //生成缩略图
- string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
- FileToolsCommon.CreateDirectory(ThumbnailPath);
- //缩略图存储位置
- string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileName(VideoSavePathName).Replace(".", "") + ".JPG";
- new Thread(new ThreadStart(new Action(() =>
- {
- while (!FileToolsCommon.IsExistFile(VideoSavePathName))
- {
- Thread.Sleep(100);
- }
- FileToolsCommon.DeleteFile(ThumbnailPathName);
- //VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
- VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- VideoInfo.VideoPath = VideoSavePathName;
- VideoInfo.ThumbnailPath = ThumbnailPathName;
- APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName, 200, 130);
- VideoInfo.FileGuid = Guid.NewGuid().ToString();
- VideoInfo.IsUpload = false;
- VideoInfo.Uploaded = 0;
- VideoInfo.Savefolder = APP.UserInfo.Schoolid + "/resource";
- APP.VideoList.Add(VideoInfo);
- //保存数据
- APP.SaveWkData();
- }))).Start();
- Click_stopRecordingScreen();
- }
- else
- {
- //视频过短
- APP.FFmpeg.SuspendFFmpeg();
- IsFirstRS = true;
- MessageWindow.Show("录屏时间过短,请重新录制!");
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【停止录屏】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
- }
- }
- Hide();
- }
- public void MaxToobar()
- {
- Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);
- float DIP = graphics.DpiX;
- float DIPY = graphics.DpiY;
- APP.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.WorkingArea.Width / (DIP / 96) - APP.W_ScreenRecordingToolbarWindow.Width + 10;
- gridToobar.Visibility = Visibility.Visible;
- }
- #endregion
-
- #region 画笔相关
- /// <summary>
- /// 画笔工具栏关闭事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnToolbarDown_Click(object sender, RoutedEventArgs e)
- {
- gridToolbar.Visibility = Visibility.Hidden;
- gridColour.Visibility = Visibility.Hidden;
- gridThickness.Visibility = Visibility.Hidden;
- APP.W_PracticeWindow.Hide();
- }
- /// <summary>
- /// 画笔点击事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnBrush_Click(object sender, RoutedEventArgs e)
- {
- #region 防止连击
- if (IsPressButton)
- {
- return;
- }
- else
- {
- IsPressButton = true;
- new Thread(new ThreadStart(new Action(() =>
- {
- Thread.Sleep(500);
- IsPressButton = false;
- }))).Start();
- }
- #endregion
- string time = GetTimeStamp();
- string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
- if (!Directory.Exists(tempPath))
- {
- Directory.CreateDirectory(tempPath);
- }
-
- #region 录屏批注取消画笔
- //string imagePath = Path.Combine(tempPath, time + ".jpg");
- //ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
- #endregion
-
- try
- {
- if (flg == 11)
- {
- Dispatcher.Invoke(() =>
- {
- borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
- borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
- });
- flg = 1;
- //this.Owner = null;
- APP.W_PracticeWindow.ReturnPractice();
- }
- else if (flg == 10)
- {
- Dispatcher.Invoke(() =>
- {
- borOne.Background = new SolidColorBrush(Colors.LightSkyBlue);
- borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
- });
- APP.W_PracticeWindow.Blue();
- flg = 11;
- }
- else
- {
- //new Thread(new ThreadStart(new Action(() =>
- //{
- Dispatcher.Invoke(() =>
- {
- borOne.Background = new SolidColorBrush(Colors.LightSkyBlue);
- borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
- });
-
- //}))).Start();
- if (APP.W_PracticeWindow == null)
- {
- APP.W_PracticeWindow = new PracticeWindow
- {
- //APP.W_PracticeWindow.Topmost = true;
- Width = pwidth,
- Height = pHeight,
- Left = 0,
- Top = 0
- };
- //practiceWin.Owner = this;
- }
- APP.W_PracticeWindow.Initialize();// imagePath);
- flg = 11;
- APP.W_PracticeWindow.Blue();
- APP.W_PracticeWindow.Show();
- new Thread(new ThreadStart(new Action(() =>
- {
- Thread.Sleep(100);
- Dispatcher.Invoke(() =>
- {
- Owner = APP.W_PracticeWindow;
- Topmost = true;
- });
- }))).Start();
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
- }
-
- //imgCanvas.Source = new BitmapImage(new Uri(imagePath));
-
- }
- /// <summary>
- /// 屏幕宽
- /// </summary>
- internal double pwidth = SystemParameters.PrimaryScreenWidth;
- /// <summary>
- /// 屏幕高
- /// </summary>
- internal double pHeight = SystemParameters.PrimaryScreenHeight;
- /// <summary>
- /// 获取时间戳
- /// </summary>
- /// <returns></returns>
- public string GetTimeStamp()
- {
- TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
- return Convert.ToInt64(ts.TotalMilliseconds).ToString();
- }
- /// <summary>
- /// 画笔粗细事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnThickness_Click(object sender, RoutedEventArgs e)
- {
- gridThickness.Visibility = Visibility.Visible;
- gridColour.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 画笔颜色事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnColour_Click(object sender, RoutedEventArgs e)
- {
- gridColour.Visibility = Visibility.Visible;
- gridThickness.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 白色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnWhite_Click(object sender, RoutedEventArgs e)
- {
- //drawingAttributes.Color = Colors.White;
- APP.W_PracticeWindow.White();
- gridColour.Visibility = Visibility.Collapsed;
- gridThickness.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 红色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnRed_Click(object sender, RoutedEventArgs e)
- {
- //drawingAttributes.Color = Colors.Red;
- APP.W_PracticeWindow.Red();
- gridColour.Visibility = Visibility.Collapsed;
- gridThickness.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 黄色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnYellow_Click(object sender, RoutedEventArgs e)
- {
- //drawingAttributes.Color = Colors.Gold;
- APP.W_PracticeWindow.Yellow();
- gridColour.Visibility = Visibility.Collapsed;
- gridThickness.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 青色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
- {
- //drawingAttributes.Color = Colors.LimeGreen;
- APP.W_PracticeWindow.CyanBlue();
- gridColour.Visibility = Visibility.Collapsed;
- gridThickness.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 灰色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnGray_Click(object sender, RoutedEventArgs e)
- {
- //drawingAttributes.Color = Colors.Gray;
- APP.W_PracticeWindow.Gray();
- gridColour.Visibility = Visibility.Collapsed;
- gridThickness.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 蓝色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnBlue_Click(object sender, RoutedEventArgs e)
- {
- //drawingAttributes.Color = Colors.DeepSkyBlue;
- APP.W_PracticeWindow.Blue();
- gridColour.Visibility = Visibility.Collapsed;
- gridThickness.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 画笔 细
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnFine_Click(object sender, RoutedEventArgs e)
- {
- APP.W_PracticeWindow.Fine();
- gridColour.Visibility = Visibility.Collapsed;
- gridThickness.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 画笔 中
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnIn_Click(object sender, RoutedEventArgs e)
- {
- APP.W_PracticeWindow.In();
- gridColour.Visibility = Visibility.Collapsed;
- gridThickness.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 画笔粗
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnCrude_Click(object sender, RoutedEventArgs e)
- {
- APP.W_PracticeWindow.Crude();
- gridColour.Visibility = Visibility.Collapsed;
- gridThickness.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 橡皮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnEraser_Click(object sender, RoutedEventArgs e)
- {
- APP.W_PracticeWindow.Eraser();
- }
- /// <summary>
- /// 🖊
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnPen_Click(object sender, RoutedEventArgs e)
- {
- APP.W_PracticeWindow.Pen();
- }
- /// <summary>
- /// ⚪
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnRound_Click(object sender, RoutedEventArgs e)
- {
- APP.W_PracticeWindow.Round();
- }
- /// <summary>
- /// 矩形
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnRectangle_Click(object sender, RoutedEventArgs e)
- {
- APP.W_PracticeWindow.Rectangle();
- }
- #endregion
- #endregion
- /// <summary>
- /// 停止录屏
- /// </summary>
- public delegate void StopRecordingScreen();
- /// <summary>
- /// 停止录屏
- /// </summary>
- public event StopRecordingScreen Click_stopRecordingScreen;
- /// <summary>
- /// 黑笔
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnBlackPen_Click(object sender, RoutedEventArgs e)
- {
-
- }
- /// <summary>
- /// 移动工具栏
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Grid_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
- {
- DragMove();
- }
- /// <summary>
- /// 红笔
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnBlackPenTwo_Click(object sender, RoutedEventArgs e)
- {
- #region 防止连击
- if (IsPressButton)
- {
- return;
- }
- else
- {
- IsPressButton = true;
- new Thread(new ThreadStart(new Action(() =>
- {
- Thread.Sleep(500);
- IsPressButton = false;
- }))).Start();
- }
- #endregion
- string time = GetTimeStamp();
- string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
- if (!Directory.Exists(tempPath))
- {
- Directory.CreateDirectory(tempPath);
- }
- #region 录屏批注取消画笔
- string imagePath = Path.Combine(tempPath, time + ".jpg");
- ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
- #endregion
- try
- {
- if (flg == 10)
- {
- Dispatcher.Invoke(() =>
- {
- borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
- borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
- });
- flg = 0;
- //this.Owner = null;
- APP.W_PracticeWindow.ReturnPractice();
- }
- else if (flg == 11)
- {
- Dispatcher.Invoke(() =>
- {
- borTwo.Background = new SolidColorBrush(Colors.LightSkyBlue);
- borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
- });
- flg = 10;
- APP.W_PracticeWindow.Red();
- }
- else
- {
- Dispatcher.Invoke(() =>
- {
- borTwo.Background = new SolidColorBrush(Colors.LightSkyBlue);
- borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
- });
- if (APP.W_PracticeWindow == null)
- {
- APP.W_PracticeWindow = new PracticeWindow
- {
- //APP.W_PracticeWindow.Topmost = true;
- Width = pwidth,
- Height = pHeight,
- Left = 0,
- Top = 0
- };
- //practiceWin.Owner = this;
- }
- APP.W_PracticeWindow.Initialize();//imagePath);
- flg = 10;
- APP.W_PracticeWindow.Red();
- APP.W_PracticeWindow.Show();
-
-
- new Thread(new ThreadStart(new Action(() =>
- {
- Thread.Sleep(100);
- Dispatcher.Invoke(() =>
- {
- Owner = APP.W_PracticeWindow;
- Topmost = true;
- });
- }))).Start();
-
-
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
- }
- }
- /// <summary>
- /// 鼠标右键按下事件 废弃
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void RightButtonDown()
- {
- if (flg > 9)
- {
- Owner = null;
- APP.W_PracticeWindow.Hide();
- }
- else
- {
- //string time = GetTimeStamp();
- string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
- if (!Directory.Exists(tempPath))
- {
- Directory.CreateDirectory(tempPath);
- }
-
- #region 录屏批注取消画笔
- //string imagePath = Path.Combine(tempPath, time + ".jpg");
- //ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
- #endregion
-
- try
- {
- if (APP.W_PracticeWindow == null)
- {
- APP.W_PracticeWindow = new PracticeWindow
- {
- //APP.W_PracticeWindow.Topmost = true;
- Width = pwidth,
- Height = pHeight,
- Left = 0,
- Top = 0
- };
- //practiceWin.Owner = this;
- }
- APP.W_PracticeWindow.Initialize();//imagePath);
-
- if (flg == 0)
- {
- flg = 10;
- APP.W_PracticeWindow.Red();
- }
- else
- {
- flg = 11;
- APP.W_PracticeWindow.Blue();
- }
- APP.W_PracticeWindow.Show();
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
- }
- }
- }
- /// <summary>
- /// 返回主界面
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnReturn_Click(object sender, RoutedEventArgs e)
- {
- if (!IsFirstRS)
- {
- MessageBoxResult br = MessageWindow.Show("退出将取消保存当前录屏,是否继续?", "提示", MessageBoxButton.OKCancel);
- if (br == MessageBoxResult.Cancel)
- {
- return;
- }
- k_hook.Stop();
- BtnRecordingScreen.ToolTip = "开始";
- APP.W_MinToolbar.Hide();
- IsSuspend = true;
- txbTime.Text = "00:00";
-
- txbTime.Visibility = Visibility.Hidden;
- End();
- APP.W_PracticeWindow.ReturnPractice();
- if (APP.W_PracticeWindow != null)
- {
- if (APP.W_PracticeWindow.Visibility == Visibility.Visible)
- {
- APP.W_PracticeWindow.Hide();
- }
- }
- if (gridToolbar.Visibility == Visibility.Visible)
- {
- gridToolbar.Visibility = Visibility.Hidden;
- gridColour.Visibility = Visibility.Hidden;
- gridThickness.Visibility = Visibility.Hidden;
- }
- if (APP.W_XHMicroLessonSystemWindow == null)
- {
- APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
- }
- try
- {
- try
- {
- APP.FFmpeg.SuspendFFmpeg();
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【录屏返回】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
- }
- IsFirstRS = true;
- new Thread(new ThreadStart(new Action(() =>
- {
- VideoInfo = null;
- FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temprs/");
-
- }))).Start();
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【录屏返回】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
- }
- }
- APP.W_XHMicroLessonSystemWindow.InitializeKeyDownEvent();
- APP.W_XHMicroLessonSystemWindow.Show();
- Hide();
- }
- /// <summary>
- /// 批注退出 废弃
- /// </summary>
- public void ReturnPractice()
- {
- new Thread(new ThreadStart(new Action(() =>
- {
- Dispatcher.Invoke(() =>
- {
- borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
- borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
- });
- flg = 0;
- Thread.Sleep(500);
- Dispatcher.Invoke(() =>
- {
- Owner = null;
- APP.W_PracticeWindow.Hide();
- });
- }))).Start();
-
-
- //Dispatcher.Invoke(() =>
- //{
- // borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
- // borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
- //});
- //flg = 0;
- //Thread.Sleep(300);
- //APP.W_PracticeWindow.Hide();
- }
- /// <summary>
- /// 修改笔状态
- /// </summary>
- public void ModifyState()
- {
- borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
- borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
- }
-
- /// <summary>
- /// 切换页面
- /// </summary>
- void SwitchPages()
- {
- //SendKeys.SendWait("%{TAB}");
- MouseEventCommon.MouseMiddleClickEvent(0);
- }
- bool isToobar = false;
- /// <summary>
- /// 在工具条区域内
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void gridToobarTwo_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
- {
- isToobar = true;
- }
-
- private void gridToobarTwo_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
- {
- if(BtnRecordingScreen.ToolTip.ToString().Equals ("暂停")&& gridToobar.Visibility == Visibility.Visible)
- {
- if (APP.W_MinToolbar == null)
- {
- APP.W_MinToolbar = new MinToolbar();
-
- }
- APP.W_MinToolbar.Initialize(this.Top);
- //else
- //{
- // APP.W_CountdownWindow.Initialize(true, 1800);
- //}
- gridToobar.Visibility = Visibility.Hidden;
- APP.W_MinToolbar.Show();
- Console.WriteLine(this.Top+"max");
- }
- }
- }
- }
|