1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192 |
- using Common.system;
-
- using NAudio.Wave;
-
- using NReco.VideoConverter;
-
- 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.Interop;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Threading;
-
- using XHWK.Model;
- using XHWK.WKTool.Utils;
-
- namespace XHWK.WKTool
- {
- /// <summary>
- /// 录屏工具栏
- /// </summary>
- public partial class ScreenRecordingToolbarWindow : Window
- {
- #region 初始变量
-
- /// <summary>
- /// 视频保存名称
- /// </summary>
- private string VideoSavePathName;
-
- /// <summary>
- /// 临时视频路径
- /// </summary>
- private string TempVideoPathName;
-
- /// <summary>
- /// 临时麦克风路径
- /// </summary>
- private string TempAudioPathName1;
-
- /// <summary>
- /// 临时扬声器路径
- /// </summary>
- private string TempAudioPathName2;
-
- /// <summary>
- /// 视频信息
- /// </summary>
- private Model_Video VideoInfo = null;
-
- //声明一个 DrawingAttributes 类型的变量
- private DrawingAttributes drawingAttributes;
-
- private DispatcherTimer t = null;
-
- /// <summary>
- /// 计时器状态
- /// </summary>
- private enum State
- {
- Start,
- Pause,
- End,
- Loading
- }
-
- /// <summary>
- /// 状态
- /// </summary>
- private State _state = State.End;
-
- private KeyboardHookCommon k_hook;
-
- /// <summary>
- /// 🖊状态 0红色 1蓝色 10红色批注内 11蓝色批注内
- /// </summary>
- public int flg = 0;
-
- #endregion 初始变量
-
- #region 初始化
-
- /// <summary>
- /// 录屏工具栏
- /// </summary>
- public ScreenRecordingToolbarWindow()
- {
- InitializeComponent();
- ResizeMode = ResizeMode.NoResize;
- }
-
- /// <summary>
- /// 初始化
- /// </summary>
- public void Initialize()
- {
- GridSrToobar.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.InitPen();
- APP.W_PracticeWindow.InitTQLPPen();
- APP.W_PracticeWindow.Show();
- new Thread(new ThreadStart(new Action(() =>
- {
- Thread.Sleep(100);
- Dispatcher.Invoke(() =>
- {
- Topmost = true;
- });
- }))).Start();
- APP.W_PracticeWindow.Hide();
-
- 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;
- //隐藏画笔工具栏
- BtnRecordingScreen.Visibility = Visibility.Visible;
- BtnRecordingScreenPause.Visibility = Visibility.Collapsed;
- BtnStopRecordingScreen.IsEnabled = false; //停止录制按钮不点击
- BtnPenBlue.IsEnabled = false;//蓝笔不可点击
- BtnPenRed.IsEnabled = false;//红笔不可点击
- BtnPenBlue.Visibility = Visibility.Visible;
- BtnPenRed.Visibility = Visibility.Visible;
- BtnPenBlue_CL.Visibility = Visibility.Collapsed;
- BtnPenRed_CL.Visibility = Visibility.Collapsed;
- TxbTime.Content = "00:00";
-
- }
-
- 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 事件
-
-
- private 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)
- {
- if (_state == State.Start)
- {
- SRTime = SRTime.AddMilliseconds(1000);
- }
-
- if (SRTime.Hour > 0)
- {
- TxbTime.Content = SRTime.ToString("HH:mm:ss");
- }
- else
- {
- TxbTime.Content = SRTime.ToString("mm:ss");
- }
- }
-
- /// <summary>
- /// 结束
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void End()
- {
- _state = State.End;
- }
-
- #region 录屏
-
- /// <summary>
- /// 设置录屏文件地址
- /// </summary>
- private void SetUpVideoPathName()
- {
- string fileType = ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
- FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
- FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temprs/");
- VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏." + fileType;
- int num = 1;
- while (FileToolsCommon.IsExistFile(VideoSavePathName))
- {
- num++;
- VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏_" + num + "." + fileType;
- }
-
-
- TempVideoPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏_" + num + ".avi";
- TempAudioPathName1 = APP.WKData.WkPath + APP.WKData.WkName + "_录屏_" + num + "_1.mp3" ;
- TempAudioPathName2 = APP.WKData.WkPath + APP.WKData.WkName + "_录屏_" + num + "_2.mp3";
-
- }
-
- /// <summary>
- /// 是否已经按下按钮
- /// </summary>
- private bool IsPressButton = false;
-
- //录制麦克风的声音
- ZAudioRecordHelper helper1 = null;
-
- //录制扬声器的声音
- ZAudioRecordHelper helper2 = null;
-
- //桌面录制
- ZVideoRecordHelper helper3 = null;
-
- public IntPtr winHandle;// 当前窗体指针
-
- /// <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 (_state == State.End)
- {
- SRTime = Convert.ToDateTime("2020-01-01 00:00:00");
- TxbTime.Content = "00:00";
-
- if (t == null)
- {
- t = new DispatcherTimer();
- t.Tick += OnTimer;
- t.Interval = new TimeSpan(0, 0, 0, 0, 1000);
- t.IsEnabled = true;
- t.Start();
- }
- else {
- t.Interval = new TimeSpan(0, 0, 0, 0, 1000);
- }
-
- _state = State.Loading;
- #region 检测麦克风扬声器是否可用
-
- //string AudioPath = FileToolsCommon.GetFileAbsolutePath("/temp/audio/");
- //FileToolsCommon.CreateDirectory(AudioPath);
- //string audioSpeakerPath = AudioPath + "adoS" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".m";
- //string audioMicrophonePath = AudioPath + "adoM" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".m";
- //try
- //{
- // FileToolsCommon.DeleteFile(audioSpeakerPath);
- // FileToolsCommon.DeleteFile(audioMicrophonePath);
- //}
- //catch (Exception)
- //{
- //}
- //扬声器
- //if (APP.FFmpeg.StartRecordSpeakerAudio(audioSpeakerPath))
- //{
- // APP.FFmpeg.StopRecordAudio(2);
-
- // //麦克风
- // 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);
- //}
- //else
- //{
- // APP.W_CountdownWindow.Initialize(true, 1800);
- //}
- //APP.W_CountdownWindow.Show();
-
- BtnRecordingScreen.Visibility = Visibility.Collapsed;
- BtnRecordingScreenPause.Visibility = Visibility.Visible;
- BtnStopRecordingScreen.IsEnabled = true; //停止录制按钮可点击
- BtnPenBlue.IsEnabled = true;//蓝笔可点击
- BtnPenRed.IsEnabled = true;//红笔可点击
- BtnPenBlue.Visibility = Visibility.Visible;
- BtnPenRed.Visibility = Visibility.Visible;
- BtnPenBlue_CL.Visibility = Visibility.Collapsed;
- BtnPenRed_CL.Visibility = Visibility.Collapsed;
- TxbTime.Visibility = Visibility.Visible;//时间显示
-
- #region 隐藏工具栏
-
- if (APP.IsHideSRTool)
- {
- if (APP.W_MinToolbar == null)
- {
- APP.W_MinToolbar = new MinToolbar();
- }
- APP.W_MinToolbar.Topmost = true;
- double MinToolTop = Top;
- GridSrToobar.Visibility = Visibility.Hidden;
-
- APP.W_MinToolbar.Initialize(MinToolTop, ActualHeight);
- APP.W_MinToolbar.Show();
- }
-
- #endregion 隐藏工具栏
-
- helper1 = new ZAudioRecordHelper(TempAudioPathName1, ZAudioRecordHelper.RecordType.microphone);
- helper2 = new ZAudioRecordHelper(TempAudioPathName2, ZAudioRecordHelper.RecordType.loudspeaker);
-
- helper1.StartRecordAudio();
- helper2.StartRecordAudio();
-
- winHandle = new WindowInteropHelper(this).Handle;
- var curScreen = Screen.FromHandle(winHandle);
- int RecordWidth = curScreen.Bounds.Width;
- int RecordHeight = curScreen.Bounds.Height;
- helper3 = new ZVideoRecordHelper(TempVideoPathName, RecordWidth, RecordHeight);
- helper3.StartRecordVideo();
- _state = State.Start;
-
- Console.WriteLine("TempAudioPathName1:"+ TempAudioPathName1);
- Console.WriteLine("TempAudioPathName2:" + TempAudioPathName2);
- Console.WriteLine("TempVideoPathName:" + TempVideoPathName);
- }
- else if (_state == State.Start)
- {
- _state = State.Pause;
- helper1.PauseRecordAudio();
- helper2.PauseRecordAudio();
- helper3.PauseRecordVideo();
- }
- else if (_state == State.Pause) {
- _state = State.Start;
- helper1.ResumeRecordAudio();
- helper2.ResumeRecordAudio();
- helper3.ResumeRecordVideo();
- }
-
- }
-
- /// <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 防止连击
-
- BtnRecordingScreen.ToolTip = "开始";
- k_hook.Stop();
- TxbTime.Content = "00:00";
-
- if (APP.W_PracticeWindow != null)
- {
- if (APP.W_PracticeWindow.Visibility == Visibility.Visible)
- {
- Owner = null;
- APP.W_PracticeWindow.ReturnPractice();
- }
- }
-
- if (APP.W_XHMicroLessonSystemWindow == null)
- {
- APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
- }
- APP.W_XHMicroLessonSystemWindow.InitializeKeyDownEvent();
- APP.W_XHMicroLessonSystemWindow.InitPen();
- APP.W_XHMicroLessonSystemWindow.InitTQLPPen();
- APP.W_XHMicroLessonSystemWindow.Show();
-
- if (_state == State.Pause || _state == State.Start) {
- t.Stop();
- t = null;
- Console.WriteLine("停止录制");
- helper1.StopRecordAudio();
- helper2.StopRecordAudio();
- helper3.StopRecordVideo();
- FFMpegConverter ffMpeg = new FFMpegConverter();
-
- FFMpegInput[] input = new FFMpegInput[] {
- new FFMpegInput(TempVideoPathName),
- new FFMpegInput(TempAudioPathName1),
- new FFMpegInput(TempAudioPathName1),
- };
-
- // 多路音频混音
- ffMpeg.ConvertMedia(
- input,
- VideoSavePathName,
- "mp4",
- new OutputSettings()
- {
- CustomOutputArgs = "-filter_complex amix=inputs=2:duration=first:dropout_transition=2"
- }
- );
- //生成缩略图
- string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
- FileToolsCommon.CreateDirectory(ThumbnailPath);
- //缩略图存储位置
- string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileName(VideoSavePathName).Replace(".", "") + ".JPG";
- new Thread(new ThreadStart(new Action(() =>
- {
-
- FileToolsCommon.DeleteFile(ThumbnailPathName);
- 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;
- if (!APP.VideoList.Exists(x => x.FileGuid == VideoInfo.FileGuid) || !APP.VideoList.Exists(x => x.VideoPath == VideoInfo.VideoPath))
- {
- APP.VideoList.Add(VideoInfo);
- //保存数据
- APP.SaveWkData();
- }
-
- FileToolsCommon.DeleteFile(TempAudioPathName1);
- FileToolsCommon.DeleteFile(TempAudioPathName2);
- FileToolsCommon.DeleteFile(TempVideoPathName);
- }))).Start();
- Click_stopRecordingScreen();
- }
- Hide();
- End();
- }
-
- 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;
- GridSrToobar.Visibility = Visibility.Visible;
- APP.W_ScreenRecordingToolbarWindow.Topmost = true;
- }
-
- #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>
- public void PenPractice()
- {
- if (flg != 11 && flg != 10)
- {
- #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);
- }
- try
- {
- Dispatcher.Invoke(() =>
- {
- //borOne.Background = new SolidColorBrush(Colors.LightSkyBlue);
- //borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
- if (APP.W_PracticeWindow == null)
- {
- APP.W_PracticeWindow = new PracticeWindow
- {
- Width = pwidth,
- Height = pHeight,
- Left = 0,
- Top = 0
- };
- //practiceWin.Owner = this;
- }
- //APP.W_PracticeWindow.InitPen();
- //APP.W_PracticeWindow.InitTQLPPen();
- APP.W_PracticeWindow.Initialize();// imagePath);
- flg = 11;
- APP.W_PracticeWindow.Blue();
- APP.W_PracticeWindow.Show();
- APP.W_PracticeWindow.Topmost = true;
- APP.W_PracticeWindow.Focus();
- });
-
- new Thread(new ThreadStart(new Action(() =>
- {
- Dispatcher.Invoke(() =>
- {
- APP.W_PracticeWindow.Topmost = false;
- });
- Thread.Sleep(500);
- 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 BtnBrush_Click(object sender, RoutedEventArgs e)
- {
- if (BtnPenBlue.Visibility != Visibility.Visible)
- {
- return;
- }
-
- #region 防止连击
-
- if (IsPressButton)
- {
- return;
- }
- else
- {
- IsPressButton = true;
- new Thread(new ThreadStart(new Action(() =>
- {
- Thread.Sleep(500);
- IsPressButton = false;
- }))).Start();
- }
-
- #endregion 防止连击
-
- BtnPenBlue.Visibility = Visibility.Collapsed;
- BtnPenRed.Visibility = Visibility.Visible;
- BtnPenBlue_CL.Visibility = Visibility.Visible;
- BtnPenRed_CL.Visibility = Visibility.Collapsed;
- 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.InitPen();
- APP.W_PracticeWindow.InitTQLPPen();
- 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 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)
- {
- if (BtnPenRed.Visibility != Visibility.Visible)
- {
- return;
- }
-
- #region 防止连击
-
- if (IsPressButton)
- {
- return;
- }
- else
- {
- IsPressButton = true;
- new Thread(new ThreadStart(new Action(() =>
- {
- Thread.Sleep(500);
- IsPressButton = false;
- }))).Start();
- }
-
- #endregion 防止连击
-
- BtnPenBlue.Visibility = Visibility.Visible;
- BtnPenRed.Visibility = Visibility.Collapsed;
- BtnPenBlue_CL.Visibility = Visibility.Collapsed;
- BtnPenRed_CL.Visibility = Visibility.Visible;
- 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)
- {
- flg = 0;
- APP.W_PracticeWindow.ReturnPractice();
- }
- else if (flg == 11)
- {
- flg = 10;
- APP.W_PracticeWindow.Red();
- }
- else
- {
- if (APP.W_PracticeWindow == null)
- {
- APP.W_PracticeWindow = new PracticeWindow
- {
- Width = pwidth,
- Height = pHeight,
- Left = 0,
- Top = 0
- };
- }
- APP.W_PracticeWindow.InitPen();
- APP.W_PracticeWindow.InitTQLPPen();
- 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 BtnReturn_Click(object sender, RoutedEventArgs e)
- {
- if (_state==State.Pause || _state == State.Start)
- {
- MessageBoxResult br = MessageWindow.Show("退出将取消保存当前录屏,是否继续?", "提示", MessageBoxButton.OKCancel);
- if (br == MessageBoxResult.Cancel)
- {
- return;
- }
- k_hook.Stop();
- BtnRecordingScreen.ToolTip = "开始";
-
- TxbTime.Content = "00:00";
- 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);
- }
-
- 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.InitPen();
- APP.W_XHMicroLessonSystemWindow.InitTQLPPen();
- APP.W_XHMicroLessonSystemWindow.Show();
-
- new Thread(new ThreadStart(new Action(() =>
- {
- Thread.Sleep(700);
- Dispatcher.Invoke(() =>
- {
- if (APP.W_MinToolbar != null)
- {
- APP.W_MinToolbar.Hide();
- }
- });
- }))).Start();
- Hide();
- }
-
- /// <summary>
- /// 修改笔状态
- /// </summary>
- public void ModifyState()
- {
- BtnPenBlue.Visibility = Visibility.Visible;
- BtnPenRed.Visibility = Visibility.Visible;
- BtnPenBlue_CL.Visibility = Visibility.Collapsed;
- BtnPenRed_CL.Visibility = Visibility.Collapsed;
- }
-
- private void gridToobarTwo_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
- {
- //if (BtnRecordingScreen.ToolTip.ToString().Equals("暂停") && (gridToobar.Visibility == Visibility.Visible || BorderBlack.Visibility == Visibility.Visible))
- if (BtnRecordingScreenPause.Visibility == Visibility.Visible)
- {
- if (APP.IsHideSRTool)
- {
- if (APP.W_MinToolbar == null)
- {
- APP.W_MinToolbar = new MinToolbar();
- }
- APP.W_MinToolbar.Topmost = true;
- double MinToolTop = Top;
-
- new Thread(new ThreadStart(new Action(() =>
- {
- Thread.Sleep(500);
- Dispatcher.Invoke(() =>
- {
- MouseEventCommon.GetCursorPos(out MouseEventCommon.POINT pointRecord);
- if (pointRecord.X >= this.Left && pointRecord.X < this.Left + this.ActualWidth && pointRecord.Y >= this.Top && pointRecord.Y < this.Top + this.ActualHeight)
- {
- //LblMessage.Content = "在区域内:("+ pointRecord.X+","+pointRecord.Y+") ("+ Left + ","+Top+")";
- }
- else
- {
- //LblMessage.Content = "不在区域内:(" + pointRecord.X + "," + pointRecord.Y + ") (" + Left + "," + Top + ")";
- APP.W_MinToolbar.Initialize(MinToolTop, ActualHeight);
- GridSrToobar.Visibility = Visibility.Hidden;
- APP.W_MinToolbar.Show();
- }
- });
- }))).Start();
- }
- }
- }
- }
- }
|