Pārlūkot izejas kodu

zhao:1增加钩子2增加录屏快捷键3增加光标随点阵笔书写移动4录制改为异步

tags/录制修改前
耀 pirms 4 gadiem
vecāks
revīzija
8faa620a8c

+ 1
- 0
Common/Common.csproj Parādīt failu

@@ -118,6 +118,7 @@
118 118
   <ItemGroup>
119 119
     <Compile Include="AESHelper.cs" />
120 120
     <Compile Include="Model\DownloadInfoModel.cs" />
121
+    <Compile Include="system\KeyboardHookCommon.cs" />
121 122
     <Compile Include="system\LatticeFileHelper.cs" />
122 123
     <Compile Include="system\PdfTrunImage.cs" />
123 124
     <Compile Include="system\BlackboardNew.cs" />

+ 207
- 0
Common/system/KeyboardHookCommon.cs Parādīt failu

@@ -0,0 +1,207 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Runtime.InteropServices;
5
+using System.Text;
6
+using System.Threading.Tasks;
7
+using System.Windows.Forms;
8
+
9
+namespace Common.system
10
+{
11
+    /// <summary>
12
+    /// 键盘钩子
13
+    /// 创建人:赵耀
14
+    /// 创建时间:2020年9月11日
15
+    /// </summary>
16
+    public class KeyboardHookCommon
17
+    {
18
+        /// <summary>
19
+        /// 全局按键按下
20
+        /// </summary>
21
+        public event KeyEventHandler KeyDownEvent;
22
+        /// <summary>
23
+        /// 窗口按键按下
24
+        /// </summary>
25
+        public event KeyPressEventHandler KeyPressEvent;
26
+        /// <summary>
27
+        /// 全局按键抬起
28
+        /// </summary>
29
+        public event KeyEventHandler KeyUpEvent;
30
+
31
+        public delegate int HookProc(int nCode, Int32 wParam, IntPtr lParam);
32
+        static int hKeyboardHook = 0; //声明键盘钩子处理的初始值
33
+                                      //值在Microsoft SDK的Winuser.h里查询
34
+        /// <summary>
35
+        /// 线程键盘钩子监听鼠标消息设为2,全局键盘监听鼠标消息设为13
36
+        /// </summary>
37
+        public const int WH_KEYBOARD_LL = 13;
38
+        /// <summary>
39
+        /// 声明KeyboardHookProcedure作为HookProc类型
40
+        /// </summary>
41
+        HookProc KeyboardHookProcedure;
42
+
43
+        /// <summary>
44
+        /// 自己创建窗口按键 
45
+        /// </summary>
46
+        private const int WM_KEYDOWN = 0x100;//KEYDOWN
47
+        /// <summary>
48
+        /// 窗口按键抬起
49
+        /// </summary>
50
+        private const int WM_KEYUP = 0x101;//KEYUP
51
+        /// <summary>
52
+        /// 全局系统按键
53
+        /// </summary>
54
+        private const int WM_SYSKEYDOWN = 0x104;//SYSKEYDOWN
55
+        /// <summary>
56
+        /// 全局按键抬起
57
+        /// </summary>
58
+        private const int WM_SYSKEYUP = 0x105;//SYSKEYUP
59
+
60
+        //键盘结构
61
+        [StructLayout(LayoutKind.Sequential)]
62
+        public class KeyboardHookStruct
63
+        {
64
+            public int vkCode;  //定一个虚拟键码。该代码必须有一个价值的范围1至254
65
+            public int scanCode; // 指定的硬件扫描码的关键
66
+            public int flags;  // 键标志
67
+            public int time; // 指定的时间戳记的这个讯息
68
+            public int dwExtraInfo; // 指定额外信息相关的信息
69
+        }
70
+        //使用此功能,安装了一个钩子
71
+        [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
72
+        public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);
73
+
74
+
75
+        //调用此函数卸载钩子
76
+        [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
77
+        public static extern bool UnhookWindowsHookEx(int idHook);
78
+
79
+
80
+        //使用此功能,通过信息钩子继续下一个钩子
81
+        [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
82
+        public static extern int CallNextHookEx(int idHook, int nCode, Int32 wParam, IntPtr lParam);
83
+
84
+        // 取得当前线程编号(线程钩子需要用到)
85
+        [DllImport("kernel32.dll")]
86
+        static extern int GetCurrentThreadId();
87
+
88
+        //使用WINDOWS API函数代替获取当前实例的函数,防止钩子失效
89
+        [DllImport("kernel32.dll")]
90
+        public static extern IntPtr GetModuleHandle(string name);
91
+
92
+        //ToAscii职能的转换指定的虚拟键码和键盘状态的相应字符或字符
93
+        [DllImport("user32")]
94
+        public static extern int ToAscii(int uVirtKey, //[in] 指定虚拟关键代码进行翻译。
95
+                                         int uScanCode, // [in] 指定的硬件扫描码的关键须翻译成英文。高阶位的这个值设定的关键,如果是(不压)
96
+                                         byte[] lpbKeyState, // [in] 指针,以256字节数组,包含当前键盘的状态。每个元素(字节)的数组包含状态的一个关键。如果高阶位的字节是一套,关键是下跌(按下)。在低比特,如果设置表明,关键是对切换。在此功能,只有肘位的CAPS LOCK键是相关的。在切换状态的NUM个锁和滚动锁定键被忽略。
97
+                                         byte[] lpwTransKey, // [out] 指针的缓冲区收到翻译字符或字符。
98
+                                         int fuState); // [in] Specifies whether a menu is active. This parameter must be 1 if a menu is active, or 0 otherwise.
99
+
100
+        //获取按键的状态
101
+        [DllImport("user32")]
102
+        public static extern int GetKeyboardState(byte[] pbKeyState);
103
+
104
+
105
+        [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
106
+        private static extern short GetKeyState(int vKey);
107
+
108
+        public void Start()
109
+        {
110
+            // 安装键盘钩子
111
+            if (hKeyboardHook == 0)
112
+            {
113
+                KeyboardHookProcedure = new HookProc(KeyboardHookProc);
114
+                hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProcedure, GetModuleHandle(System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleName), 0);
115
+                //hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProcedure, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]), 0);
116
+                //************************************
117
+                //键盘线程钩子
118
+                //SetWindowsHookEx( 2,KeyboardHookProcedure, IntPtr.Zero, GetCurrentThreadId());//指定要监听的线程idGetCurrentThreadId(),
119
+                //键盘全局钩子,需要引用空间(using System.Reflection;)
120
+                //SetWindowsHookEx( 13,MouseHookProcedure,Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]),0);
121
+                //
122
+                //关于SetWindowsHookEx (int idHook, HookProc lpfn, IntPtr hInstance, int threadId)函数将钩子加入到钩子链表中,说明一下四个参数:
123
+                //idHook 钩子类型,即确定钩子监听何种消息,上面的代码中设为2,即监听键盘消息并且是线程钩子,如果是全局钩子监听键盘消息应设为13,
124
+                //线程钩子监听鼠标消息设为7,全局钩子监听鼠标消息设为14。lpfn 钩子子程的地址指针。如果dwThreadId参数为0 或是一个由别的进程创建的
125
+                //线程的标识,lpfn必须指向DLL中的钩子子程。 除此以外,lpfn可以指向当前进程的一段钩子子程代码。钩子函数的入口地址,当钩子钩到任何
126
+                //消息后便调用这个函数。hInstance应用程序实例的句柄。标识包含lpfn所指的子程的DLL。如果threadId 标识当前进程创建的一个线程,而且子
127
+                //程代码位于当前进程,hInstance必须为NULL。可以很简单的设定其为本应用程序的实例句柄。threaded 与安装的钩子子程相关联的线程的标识符
128
+                //如果为0,钩子子程与所有的线程关联,即为全局钩子
129
+                //************************************
130
+                //如果SetWindowsHookEx失败
131
+                if (hKeyboardHook == 0)
132
+                {
133
+                    Stop();
134
+                    throw new Exception("安装键盘钩子失败");
135
+                }
136
+            }
137
+        }
138
+        public void Stop()
139
+        {
140
+            bool retKeyboard = true;
141
+
142
+
143
+            if (hKeyboardHook != 0)
144
+            {
145
+                retKeyboard = UnhookWindowsHookEx(hKeyboardHook);
146
+                hKeyboardHook = 0;
147
+            }
148
+            try
149
+            {
150
+
151
+                if (!(retKeyboard)) throw new Exception("卸载钩子失败!");
152
+            }
153
+            catch (Exception)
154
+            {
155
+
156
+            }
157
+        }
158
+        //接收SetWindowsHookEx返回值  
159
+        private static int _hHookValue = 0;
160
+        private int KeyboardHookProc(int nCode, Int32 wParam, IntPtr lParam)
161
+        {
162
+            // 侦听键盘事件
163
+            if ((nCode >= 0) && (KeyDownEvent != null || KeyUpEvent != null || KeyPressEvent != null))
164
+            {
165
+                KeyboardHookStruct MyKeyboardHookStruct = (KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyboardHookStruct));
166
+                // raise KeyDown
167
+                if (KeyDownEvent != null && (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN))
168
+                {
169
+                    Keys keyData = (Keys)MyKeyboardHookStruct.vkCode;
170
+                    KeyEventArgs e = new KeyEventArgs(keyData);
171
+                    KeyDownEvent(this, e);
172
+                }
173
+
174
+                //键盘按下
175
+                if (KeyPressEvent != null && wParam == WM_KEYDOWN)
176
+                {
177
+                    byte[] keyState = new byte[256];
178
+                    GetKeyboardState(keyState);
179
+
180
+                    byte[] inBuffer = new byte[2];
181
+                    if (ToAscii(MyKeyboardHookStruct.vkCode, MyKeyboardHookStruct.scanCode, keyState, inBuffer, MyKeyboardHookStruct.flags) == 1)
182
+                    {
183
+                        KeyPressEventArgs e = new KeyPressEventArgs((char)inBuffer[0]);
184
+                        KeyPressEvent(this, e);
185
+                    }
186
+                }
187
+
188
+                // 键盘抬起
189
+                if (KeyUpEvent != null && (wParam == WM_KEYUP || wParam == WM_SYSKEYUP))
190
+                {
191
+                    Keys keyData = (Keys)MyKeyboardHookStruct.vkCode;
192
+                    KeyEventArgs e = new KeyEventArgs(keyData);
193
+                    KeyUpEvent(this, e);
194
+                }
195
+
196
+            }
197
+            //如果返回1,则结束消息,这个消息到此为止,不再传递。
198
+            //如果返回0或调用CallNextHookEx函数则消息出了这个钩子继续往下传递,也就是传给消息真正的接受者
199
+            return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);
200
+        }
201
+        ~KeyboardHookCommon()
202
+        {
203
+            Stop();
204
+        }
205
+
206
+    }
207
+}

+ 5
- 0
XHWK.WKTool/App.cs Parādīt failu

@@ -286,6 +286,11 @@ namespace XHWK.WKTool
286 286
                 {
287 287
                     string WkDateXmlStr = FileToolsCommon.FileToString(SaveName);
288 288
                     WKDataList = XmlUtilHelper.DESerializer<List<Model_WKData>>(WkDateXmlStr);
289
+                    foreach (Model_WKData wklist in WKDataList)
290
+                    {
291
+                        //移除找不到视频的微课数据
292
+                        wklist.VideoList.RemoveAll(x => !FileToolsCommon.IsExistFile(x.VideoPath));
293
+                    }
289 294
                     if (WKDataList.Exists(x => x.WkPath == WkPath))
290 295
                     {
291 296
                         WKData = WKDataList.Find(x => x.WkPath == WkPath);

+ 5
- 2
XHWK.WKTool/CreateAMicroLessonWindow.xaml Parādīt failu

@@ -5,9 +5,12 @@
5 5
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6 6
         xmlns:local="clr-namespace:XHWK.WKTool"
7 7
         mc:Ignorable="d"
8
-        Title="星火微课" Height="341" Width="454"   AllowsTransparency="True"
8
+        Title="星火微课" Height="346" Width="457"   AllowsTransparency="True"
9 9
     WindowStartupLocation="CenterScreen"
10
-    WindowStyle="None" Loaded="Window_Loaded">
10
+    WindowStyle="None" Loaded="Window_Loaded" Margin="0"  BorderThickness="5,5,5,5">
11
+    <Window.Effect>
12
+        <DropShadowEffect BlurRadius="5" Color="#FF060606" Direction="80" ShadowDepth="0"/>
13
+    </Window.Effect>
11 14
     <Viewbox>
12 15
         <Grid Height="341" Width="454" >
13 16
             <!--分4行-->

+ 14
- 6
XHWK.WKTool/FileDirectoryWindow.xaml.cs Parādīt failu

@@ -127,21 +127,28 @@ namespace XHWK.WKTool
127 127
                         continue;
128 128
                     foreach (Model_Video videoinfo in Vdata.VideoList)
129 129
                     {
130
-                        if (string.IsNullOrWhiteSpace(videoinfo.VideoPath))
130
+                        try
131 131
                         {
132
-                            continue;
132
+                            if (string.IsNullOrWhiteSpace(videoinfo.VideoPath))
133
+                            {
134
+                                continue;
135
+                            }
136
+                            if (string.IsNullOrWhiteSpace(videoinfo.VideoSize) || videoinfo.VideoSize == "0 MB")
137
+                            {
138
+                                videoinfo.VideoSize = FileToolsCommon.GetFileSizeByMB(videoinfo.VideoPath).ToString() + " MB";
139
+                            }
140
+                            model_VideoList.Add(videoinfo);
133 141
                         }
134
-                        if (string.IsNullOrWhiteSpace(videoinfo.VideoSize) || videoinfo.VideoSize == "0 MB")
142
+                        catch (Exception ex)
135 143
                         {
136
-                            videoinfo.VideoSize = FileToolsCommon.GetFileSizeByMB(videoinfo.VideoPath).ToString() + " MB";
144
+                            LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
137 145
                         }
138
-                        model_VideoList.Add(videoinfo);
139 146
                     }
140 147
                 }
141 148
             }
142 149
             catch (Exception ex)
143 150
             {
144
-
151
+                LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
145 152
             }
146 153
         }
147 154
         /// <summary>
@@ -151,6 +158,7 @@ namespace XHWK.WKTool
151 158
         /// <param name="e"></param>
152 159
         private void btnDown_Click(object sender, RoutedEventArgs e)
153 160
         {
161
+            APP.SaveWkData();
154 162
             this.Hide();
155 163
         }
156 164
         /// <summary>

+ 32
- 6
XHWK.WKTool/ScreenRecordingToolbarWindow.xaml.cs Parādīt failu

@@ -5,6 +5,7 @@ using System.Configuration;
5 5
 using System.IO;
6 6
 using System.Threading;
7 7
 using System.Windows;
8
+using System.Windows.Forms;
8 9
 using System.Windows.Ink;
9 10
 using System.Windows.Media;
10 11
 using System.Windows.Media.Imaging;
@@ -55,6 +56,8 @@ namespace XHWK.WKTool
55 56
         /// 计时用
56 57
         /// </summary>
57 58
         private TimeSpan _timeSpan = new TimeSpan(0, 0, 0, 0, 0);
59
+
60
+        KeyboardHookCommon k_hook;
58 61
         #endregion
59 62
 
60 63
         #region 初始化
@@ -70,6 +73,9 @@ namespace XHWK.WKTool
70 73
         /// </summary>
71 74
         public void Initialize()
72 75
         {
76
+            k_hook = new KeyboardHookCommon();
77
+            k_hook.KeyDownEvent += K_hook_KeyDownEvent;
78
+
73 79
             //创建 DrawingAttributes 类的一个实例  
74 80
             drawingAttributes = new DrawingAttributes();
75 81
             //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用  
@@ -81,6 +87,7 @@ namespace XHWK.WKTool
81 87
             gridToolbar.Visibility = Visibility.Hidden;
82 88
             gridColour.Visibility = Visibility.Hidden;
83 89
             gridThickness.Visibility = Visibility.Hidden;
90
+            ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
84 91
             if (t == null)
85 92
             {
86 93
                 t = new DispatcherTimer();
@@ -90,9 +97,23 @@ namespace XHWK.WKTool
90 97
                 t.Start();
91 98
             }
92 99
             t.Interval = new TimeSpan(0, 0, 0, 1);
93
-            Stack();
94
-            ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar25.png"));
95
-            BtnRecordingScreen_Click(null, null);
100
+            //Stack();
101
+            //ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar25.png"));
102
+            //BtnRecordingScreen_Click(null, null);
103
+        }
104
+
105
+        private void K_hook_KeyDownEvent(object sender, System.Windows.Forms.KeyEventArgs e)
106
+        {
107
+            if (e.KeyValue == (int)System.Windows.Forms.Keys.F5 && (int)Control.ModifierKeys == (int)Keys.Control)
108
+            {
109
+                //开始,暂停
110
+                BtnRecordingScreen_Click(null, null);
111
+            }
112
+            if (e.KeyValue == (int)Keys.S && (int)Control.ModifierKeys == (int)Keys.Control)
113
+            {
114
+                //结束
115
+                BtnStopRecordingScreen_Click(null, null);
116
+            }
96 117
         }
97 118
         #endregion
98 119
 
@@ -188,6 +209,7 @@ namespace XHWK.WKTool
188 209
                     VideoInfo.WkType = Enum_WKVidetype.RecordingScreen;
189 210
                     SetUpVideoPathName();
190 211
                     IsFirstRS = false;
212
+                    k_hook.Start();//安装键盘钩子
191 213
                 }
192 214
                 IsSuspend = false;
193 215
 
@@ -208,11 +230,14 @@ namespace XHWK.WKTool
208 230
                 ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar25.png"));
209 231
                 try
210 232
                 {
211
-                    APP.FFmpeg.StartRecordingVideo(VideoSavePathName);
233
+                    new Thread(new ThreadStart(new Action(() =>
234
+                    {
235
+                        APP.FFmpeg.StartRecordingVideo(VideoSavePathName);
236
+                    }))).Start();
212 237
                 }
213 238
                 catch (Exception ex)
214 239
                 {
215
-                    MessageBox.Show(ex.Message);
240
+                    System.Windows.MessageBox.Show(ex.Message);
216 241
                 }
217 242
             }
218 243
             else
@@ -242,7 +267,7 @@ namespace XHWK.WKTool
242 267
                 }
243 268
                 catch (Exception ex)
244 269
                 {
245
-                    MessageBox.Show(ex.Message);
270
+                    System.Windows.MessageBox.Show(ex.Message);
246 271
                 }
247 272
             }
248 273
         }
@@ -253,6 +278,7 @@ namespace XHWK.WKTool
253 278
         /// <param name="e"></param>
254 279
         private void BtnStopRecordingScreen_Click(object sender, RoutedEventArgs e)
255 280
         {
281
+            k_hook.Stop();
256 282
             IsSuspend = true;
257 283
             txbTime.Text = "00:00";
258 284
             End();

+ 25
- 8
XHWK.WKTool/XHMicroLessonSystemWindow.xaml Parādīt failu

@@ -8,9 +8,26 @@
8 8
         xmlns:local="clr-namespace:XHWK.WKTool"
9 9
         mc:Ignorable="d"
10 10
         Title="星火微课系统" Height="1040" Width="1276" WindowStartupLocation="CenterScreen"
11
-    WindowStyle="None"    AllowsTransparency="True"  Background="#EFF1F8" ShowInTaskbar="True" ResizeMode="CanMinimize"
12
-   >
13
-    
11
+    WindowStyle="None"    AllowsTransparency="True"  Background="#EFF1F8" ShowInTaskbar="True" ResizeMode="CanMinimize" BorderThickness="10"
12
+   >    
13
+    <!--<Grid>
14
+        <Border CornerRadius="0,0,0,0"
15
+                Background="White"
16
+                BorderBrush="Gray"
17
+                BorderThickness="1"
18
+                Margin="10,10,10,10">
19
+            <Border.Effect>
20
+                <DropShadowEffect Color="Gray" BlurRadius="10" ShadowDepth="0" Opacity="0.8" />
21
+            </Border.Effect>
22
+        </Border>
23
+    </Grid>-->
24
+    <Window.BorderBrush>
25
+        <RadialGradientBrush>
26
+            <GradientStop Offset="0.997" Color="#001B1919"/>
27
+            <GradientStop Color="Black"/>
28
+        </RadialGradientBrush>
29
+    </Window.BorderBrush>
30
+
14 31
     <Viewbox>
15 32
         <Grid x:Name="GridContent" Height="1040">
16 33
 
@@ -129,7 +146,7 @@
129 146
                                             <TranslateTransform/>
130 147
                                         </TransformGroup>
131 148
                                     </Grid.Resources>
132
-                               
149
+
133 150
                                     <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Disabled"   Cursor="SizeAll"
134 151
                   Margin="0,0,0,0" Focusable="False" x:Name="BackFrame">
135 152
                                         <ContentControl  MouseLeftButtonDown="IMG1_MouseLeftButtonDown"   
@@ -150,10 +167,10 @@
150 167
                         <!--<wfi:WindowsFormsHost Grid.Row="0" Grid.Column="1" x:Name="wfhCamera" Height="124" Width="172" HorizontalAlignment="Right" Margin="0,10,30.10,0" VerticalAlignment="Top">
151 168
                     <aforge:VideoSourcePlayer x:Name="player" Height="124" Width="172"  />
152 169
                 </wfi:WindowsFormsHost>-->
153
-             
154 170
 
155
-                    
156
-       
171
+
172
+
173
+
157 174
                     </Grid>
158 175
                 </ScrollViewer>
159 176
                 <Image x:Name="imgPlayerLeft" Width="172" Height="124" Source="./Images/microLessonSystem_17.png"  HorizontalAlignment="Left"  Margin="10,7,10,10" VerticalAlignment="Top" Visibility="Collapsed"/>
@@ -165,7 +182,7 @@
165 182
                 <Label Content="" Grid.Column="0" Height="2" Width="2" Background="#FF0F0F0F" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="1,0,0,0"/>
166 183
                 <Label Content="" Grid.Column="1" Height="2" Width="2" Background="#FF0F0F0F" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,16,0"/>
167 184
             </Grid>
168
-           
185
+
169 186
             <Grid Grid.Row="1">
170 187
                 <StackPanel Grid.Row="0" Orientation="Horizontal" Background="#FFFFFF" Width="180" HorizontalAlignment="Center"
171 188
             Height="58" Margin="0,520,0,0" Grid.Column="1" VerticalAlignment="Bottom">

+ 78
- 16
XHWK.WKTool/XHMicroLessonSystemWindow.xaml.cs Parādīt failu

@@ -23,6 +23,7 @@ using XHWK.WKTool.DAL;
23 23
 using System.Text;
24 24
 using System.Collections.Specialized;
25 25
 using XHWK.WKTool.Config;
26
+using System.Windows.Media.Converters;
26 27
 
27 28
 namespace XHWK.WKTool
28 29
 {
@@ -392,22 +393,24 @@ namespace XHWK.WKTool
392 393
             }
393 394
             else
394 395
             {
395
-                MessageBoxResult dr = System.Windows.MessageBox.Show("当前正在录制,是否停止录制?", "提示", MessageBoxButton.OKCancel);
396
-                if (dr == MessageBoxResult.OK)
397
-                {
398
-                    APP.SaveWkData();
399
-                    APP.SaveDraw();
400
-                    BtnStop_Click(null, null);
401
-                    while (!IsFirstR)
402
-                    {
403
-                        Thread.Sleep(100);
404
-                    }
405
-                    System.Environment.Exit(0);
406
-                }
407
-                else
408
-                {
409
-                    return;
410
-                }
396
+                System.Windows.MessageBox.Show("当前正在录制,请先停止录制。");
397
+                return;
398
+                //MessageBoxResult dr = System.Windows.MessageBox.Show("当前正在录制,是否停止录制?", "提示", MessageBoxButton.OKCancel);
399
+                //if (dr == MessageBoxResult.OK)
400
+                //{
401
+                //    APP.SaveWkData();
402
+                //    APP.SaveDraw();
403
+                //    BtnStop_Click(null, null);
404
+                //    while (!IsFirstR)
405
+                //    {
406
+                //        Thread.Sleep(100);
407
+                //    }
408
+                //    System.Environment.Exit(0);
409
+                //}
410
+                //else
411
+                //{
412
+                //    return;
413
+                //}
411 414
             }
412 415
         }
413 416
         /// <summary>
@@ -2302,6 +2305,58 @@ namespace XHWK.WKTool
2302 2305
                     {
2303 2306
                         //myblackboard.changepages(testX, testY,false);
2304 2307
                         myblackboard.changepages(testX, testY, false, Color, PenSize, APP.pageData.currpage - 1);
2308
+
2309
+                        #region 设置滚动条位置
2310
+
2311
+                        //点在显示页面上方
2312
+                        if (testY < scroMain.VerticalOffset)
2313
+                        {
2314
+                            //滚动条当前位置
2315
+                            double RollCurrentLocation = scroMain.VerticalOffset;
2316
+                            //向上滚动至以点为中心需要滚动的距离  
2317
+                            double UpRoll = (RollCurrentLocation - testY) + (scroMain.ActualHeight / 2);
2318
+                            //如果小于0则等于0
2319
+                            double RollLocation = RollCurrentLocation - UpRoll;
2320
+                            if (RollLocation < 0)
2321
+                            {
2322
+                                RollLocation = 0;
2323
+                            }
2324
+                            ////滚动条实际偏移量
2325
+                            //double RollOffset = RollCurrentLocation - RollLocation;
2326
+                            scroMain.ScrollToVerticalOffset(RollLocation);
2327
+                        }
2328
+                        //点在显示页面下方
2329
+                        if (testY > scroMain.VerticalOffset + scroMain.ActualHeight)
2330
+                        {
2331
+                            //滚动条当前位置
2332
+                            double RollCurrentLocation = scroMain.VerticalOffset;
2333
+                            //向下滚动至以点为中心需要滚动的距离  
2334
+                            double DownRoll = (testY - RollCurrentLocation) - (scroMain.ActualHeight / 2);
2335
+                            //如果小于0则等于0
2336
+                            double RollLocation = RollCurrentLocation + DownRoll;
2337
+                            //滚动条最大滚动值
2338
+                            double ScrollbarMaxNum = gridM.ActualHeight - scroMain.ActualHeight;
2339
+                            if (RollLocation > ScrollbarMaxNum)
2340
+                            {
2341
+                                RollLocation = ScrollbarMaxNum;
2342
+                            }
2343
+                            ////滚动条实际偏移量
2344
+                            //double RollOffset = RollLocation-RollCurrentLocation;
2345
+                            scroMain.ScrollToVerticalOffset(RollLocation);
2346
+                        }
2347
+                        #endregion
2348
+                        //gridM.Height //A4高度
2349
+                        //scroMain.VerticalOffset;//获取滚动条位置
2350
+                        //scroMain.ActualHeight//A4纸显示高度
2351
+                        //scroMain.ScrollToHorizontalOffset()//设置滚动条位置
2352
+
2353
+                        //Mouse.GetPosition(this)
2354
+                        if (testX > 0 && testY > 0)
2355
+                        {
2356
+                            //System.Windows.Point getP = blackboard_canvas.PointToScreen(new System.Windows.Point(testX, testY));
2357
+                            System.Windows.Point getP = scroMain.PointToScreen(new System.Windows.Point(testX, testY - scroMain.VerticalOffset));
2358
+                            SetCursorPos((int)getP.X, (int)getP.Y);
2359
+                        }
2305 2360
                     }));
2306 2361
                 }
2307 2362
 
@@ -2398,6 +2453,13 @@ namespace XHWK.WKTool
2398 2453
             //btnOk.Visibility = Visibility.Collapsed;
2399 2454
             //blackboard_canvas.Visibility = Visibility.Visible;
2400 2455
         }
2456
+        /// <summary>
2457
+        /// 引用user32.dll动态链接库(windows api),
2458
+        /// 使用库中定义 API:SetCursorPos
2459
+        /// 设置光标位置
2460
+        /// </summary>
2461
+        [System.Runtime.InteropServices.DllImport("user32.dll")]
2462
+        private static extern int SetCursorPos(int x, int y);
2401 2463
 
2402 2464
     }
2403 2465
 }

Notiek ielāde…
Atcelt
Saglabāt