├── .gitattributes
├── .gitignore
├── JxCode.Windows.sln
├── JxCode.Windows
└── JxCode.Windows.csproj
├── LICENSE
├── README.md
├── Shared.JxCode.Windows
├── App.cs
├── FileDialog.cs
├── IniHelper.cs
├── KeyboardUtil.cs
├── MCIPlayer.cs
├── MessageBox.cs
├── MouseUtil.cs
├── Native
│ ├── Kernel32.cs
│ ├── Shell32.cs
│ ├── User32.cs
│ ├── User32Enum
│ │ ├── GWL_WindowsLongMessage.cs
│ │ ├── GW_GetWindow.cs
│ │ ├── MOUSEEVENTF_MouseEventType.cs
│ │ ├── SC_SysCommand.cs
│ │ ├── VK_Keys.cs
│ │ ├── WA_WindowsActiveMessage.cs
│ │ ├── WM_WindowsMessage.cs
│ │ ├── WSEX_ExtendedWindowStyle.cs
│ │ └── WS_WindowStyle.cs
│ └── Winmm.cs
├── NotifyIcon.cs
├── ProcessHandle.cs
├── RegeditConfiguration.cs
├── Shared.JxCode.Windows.projitems
├── Shared.JxCode.Windows.shproj
├── SoftUtility
│ └── JavaInfo.cs
├── TaskbarProgress.cs
├── WindowsForm.cs
└── WinformMessageProc.cs
└── Test
├── Program.cs
├── Properties
└── AssemblyInfo.cs
└── Test.csproj
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .vs/
2 | JxCode.Windows/bin
3 | JxCode.Windows/obj
4 | Test
--------------------------------------------------------------------------------
/JxCode.Windows.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.30523.141
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Shared.JxCode.Windows", "Shared.JxCode.Windows\Shared.JxCode.Windows.shproj", "{12CE725D-57FC-4BD3-B1D5-6C749211DC23}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JxCode.Windows", "JxCode.Windows\JxCode.Windows.csproj", "{731F6837-E4FE-4C79-B17C-080638F5CCB9}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{B41B8F6E-844F-4347-9EE2-0F202FBEABAF}"
11 | EndProject
12 | Global
13 | GlobalSection(SharedMSBuildProjectFiles) = preSolution
14 | Shared.JxCode.Windows\Shared.JxCode.Windows.projitems*{12ce725d-57fc-4bd3-b1d5-6c749211dc23}*SharedItemsImports = 13
15 | Shared.JxCode.Windows\Shared.JxCode.Windows.projitems*{731f6837-e4fe-4c79-b17c-080638f5ccb9}*SharedItemsImports = 5
16 | Shared.JxCode.Windows\Shared.JxCode.Windows.projitems*{b41b8f6e-844f-4347-9ee2-0f202fbeabaf}*SharedItemsImports = 4
17 | EndGlobalSection
18 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
19 | Debug|Any CPU = Debug|Any CPU
20 | Debug|x64 = Debug|x64
21 | Debug|x86 = Debug|x86
22 | Release|Any CPU = Release|Any CPU
23 | Release|x64 = Release|x64
24 | Release|x86 = Release|x86
25 | EndGlobalSection
26 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
27 | {731F6837-E4FE-4C79-B17C-080638F5CCB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28 | {731F6837-E4FE-4C79-B17C-080638F5CCB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
29 | {731F6837-E4FE-4C79-B17C-080638F5CCB9}.Debug|x64.ActiveCfg = Debug|x64
30 | {731F6837-E4FE-4C79-B17C-080638F5CCB9}.Debug|x64.Build.0 = Debug|x64
31 | {731F6837-E4FE-4C79-B17C-080638F5CCB9}.Debug|x86.ActiveCfg = Debug|x86
32 | {731F6837-E4FE-4C79-B17C-080638F5CCB9}.Debug|x86.Build.0 = Debug|x86
33 | {731F6837-E4FE-4C79-B17C-080638F5CCB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
34 | {731F6837-E4FE-4C79-B17C-080638F5CCB9}.Release|Any CPU.Build.0 = Release|Any CPU
35 | {731F6837-E4FE-4C79-B17C-080638F5CCB9}.Release|x64.ActiveCfg = Release|x64
36 | {731F6837-E4FE-4C79-B17C-080638F5CCB9}.Release|x64.Build.0 = Release|x64
37 | {731F6837-E4FE-4C79-B17C-080638F5CCB9}.Release|x86.ActiveCfg = Release|x86
38 | {731F6837-E4FE-4C79-B17C-080638F5CCB9}.Release|x86.Build.0 = Release|x86
39 | {B41B8F6E-844F-4347-9EE2-0F202FBEABAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
40 | {B41B8F6E-844F-4347-9EE2-0F202FBEABAF}.Debug|Any CPU.Build.0 = Debug|Any CPU
41 | {B41B8F6E-844F-4347-9EE2-0F202FBEABAF}.Debug|x64.ActiveCfg = Debug|Any CPU
42 | {B41B8F6E-844F-4347-9EE2-0F202FBEABAF}.Debug|x64.Build.0 = Debug|Any CPU
43 | {B41B8F6E-844F-4347-9EE2-0F202FBEABAF}.Debug|x86.ActiveCfg = Debug|Any CPU
44 | {B41B8F6E-844F-4347-9EE2-0F202FBEABAF}.Debug|x86.Build.0 = Debug|Any CPU
45 | {B41B8F6E-844F-4347-9EE2-0F202FBEABAF}.Release|Any CPU.ActiveCfg = Release|Any CPU
46 | {B41B8F6E-844F-4347-9EE2-0F202FBEABAF}.Release|Any CPU.Build.0 = Release|Any CPU
47 | {B41B8F6E-844F-4347-9EE2-0F202FBEABAF}.Release|x64.ActiveCfg = Release|Any CPU
48 | {B41B8F6E-844F-4347-9EE2-0F202FBEABAF}.Release|x64.Build.0 = Release|Any CPU
49 | {B41B8F6E-844F-4347-9EE2-0F202FBEABAF}.Release|x86.ActiveCfg = Release|Any CPU
50 | {B41B8F6E-844F-4347-9EE2-0F202FBEABAF}.Release|x86.Build.0 = Release|Any CPU
51 | EndGlobalSection
52 | GlobalSection(SolutionProperties) = preSolution
53 | HideSolutionNode = FALSE
54 | EndGlobalSection
55 | GlobalSection(ExtensibilityGlobals) = postSolution
56 | SolutionGuid = {4DB21CAE-093C-4108-84EB-C2803097F504}
57 | EndGlobalSection
58 | EndGlobal
59 |
--------------------------------------------------------------------------------
/JxCode.Windows/JxCode.Windows.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net472
5 | AnyCPU;x86;x64
6 | 2.0.0.0
7 | 2.0.0.0
8 | 2.0.0
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Jayshonyves
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # JxCode.Windows
2 | 
3 | 
4 | 
5 |
6 | 基于Win32API编写的C#windows操作类库。拥有窗体控制、鼠标键盘的模拟、任务栏进度条、托盘等工具,可以使用在控制台、链接库、以及Unity等windows平台的框架下。
7 |
8 | ## Contents
9 | - [JxCode.Windows](#jxcodewindows)
10 | - [Contents](#contents)
11 | - [如何使用](#如何使用)
12 | - [Win32API](#win32api)
13 | - [WindowsForm](#windowsform)
14 | - [App](#app)
15 | - [FileDialog](#filedialog)
16 | - [INI配置文件读写](#ini配置文件读写)
17 | - [KeyboardUtil](#keyboardutil)
18 | - [MCIPlayer](#mciplayer)
19 | - [MessageBox](#messagebox)
20 | - [TaskbarProgress](#TaskbarProgress)
21 | - [MouseUtil](#mouseutil)
22 | - [NotifyIcon](#notifyicon)
23 | - [ProcessHandle](#processhandle)
24 | - [RegeditConfiguration](#RegeditConfiguration)
25 | - [拓展工具](#拓展工具)
26 |
27 | ## 如何使用
28 |
29 | 两种方法:
30 |
31 | - 直接将`Shared.JxCode.Windows`共享项目添加至解决方案并引用。
32 | - 将`JxCode.Windows`项目编译成dll后,在项目中引用。
33 |
34 | ## Win32API
35 | 封装了一些常用的API以及Enum。API来源于:
36 | - Kernel32
37 | - Shell32
38 | - User32
39 | - Winmm
40 | - comdlg32
41 |
42 | 可以在Native文件夹中找到,命名空间为`JxCode.Windows.Native`。
43 |
44 | ## WindowsForm
45 | 封装了窗体为WindowsForm对象,实现了一些Windows窗体控制与模拟的函数
46 | - 获取窗体句柄
47 | - 设置获取窗体标题
48 | - 设置获取窗体类名
49 | - 设置获取窗体大小与位置
50 | - 设置获取窗体父对象
51 | - 获取所有子窗体
52 | - 设置窗体小图标
53 | - 设置窗体置顶与还原
54 | - 最小化、最大化、还原操作
55 | - 设置窗体为焦点
56 | - 发送粘贴消息到窗体
57 | - 设置窗体激活状态(是否可用)
58 | - 设置获取窗体外观
59 |
60 | 可以通过多种工厂函数创建WindowsForm对象:
61 | - 从一个句柄创建
62 | - 搜寻一个窗口标题创建
63 | - 使用一个坐标来创建
64 | - 从当前鼠标位置指向的窗体创建
65 | - 从PID创建
66 | - 从当前程序的PID创建
67 | - 从调用线程的活动窗口创建
68 |
69 | ## App
70 | 可以获取一个程序运行时的一些基础状态。
71 | - Path : 程序运行的工作路径
72 | - BasePath : 程序所在路径
73 | - FullPath : Exe的完整路径
74 | - EXEName : Exe的名字(不含扩展名)
75 | - PrevInstance : 是否有程序实例在运行
76 |
77 | ## FileDialog
78 | 打开文件与保存文件对话框,使用`comdlg32`导入api,封装后只对外暴露两个方法:
79 | ```C#
80 | public static string OpenFileDialog(
81 | string dirPath,
82 | string filter,
83 | string title = "OpenFileDialog",
84 | string defaultFilename = "");
85 | ```
86 | ```C#
87 | public static string SaveFileDialog(
88 | string dirPath,
89 | string filter = "All(*.*)|*.*",
90 | string title = "SaveFileDialog",
91 | string defaultFilename = "")
92 | ```
93 | 它们都返回一个string,如果打开/保存成功,返回文件完整路径,否则为null。
94 |
95 |
96 | ## INI配置文件读写
97 | IniHelper文件中有两个类,分别是:
98 | - INIFile
99 | - INISection
100 |
101 | 在`JxCode.Windows.Native`导入了API,并封装了`Kernel32.WritePrivateProfileString`和`Kernel32.GetPrivateProfileString`。
102 |
103 | 使用构造`public INIFile(string filepath)`创建INI对象。
104 | ```C#
105 | INIFile inifile = new INIFile("a.ini");
106 | INISection section = inifile["section"];
107 | section.SetValue("k","v");
108 | string v = section.GetValue("k");
109 | ```
110 |
111 | ## KeyboardUtil
112 | 键盘模拟
113 | ```C#
114 | KeyboardUtil.Click(JxCode.Windows.Native.User32.VK_Keys.VK_W);
115 | ```
116 | 模拟`W`键按下
117 |
118 | ## MCIPlayer
119 | 使用MCI来播放音频或者视频
120 |
121 | ## MessageBox
122 | 使用`User32`中导出的函数,还原了`MessageBox`, `MessageBoxButtons`, `DialogResult`。
123 | ```C#
124 | DialogResult r = MessageBox.Show("text", "caption", MessageBoxButtons.OkCancel);
125 | ```
126 |
127 | ## TaskbarProgress
128 | 设置windows任务栏进度条的状态的进度。
129 | 可以使用WindowsForm类中函数,从当前进程中获取窗体对象。
130 | ```C#
131 | var wf = WindowsForm.CreateFromCurrentPid();
132 | TaskbarProgress.SetState(wf, TaskbarProgress.TaskbarStates.Normal);
133 | TaskbarProgress.SetValue(wf, 50, 100);
134 | ```
135 |
136 | ## MouseUtil
137 | - 获取与设置鼠标位置
138 | - 模拟点击
139 |
140 | ## NotifyIcon
141 | 托盘按钮
142 |
143 | ## ProcessHandle
144 | 运行程序的一个句柄,可以方便的重定向输入输出流,设置程序响应与结束的回调,或终结程序。
145 |
146 | ## RegeditConfiguration
147 | 快速简洁的注册表配置工具类
148 | 注册表的位置在`HKCU/Software/当前执行的程序集名字`。
149 |
150 | ```C#
151 | static string GetSetting(
152 | string key,
153 | string appName = null);
154 | ```
155 | ```C#
156 | static void SetSetting(
157 | string key,
158 | string value,
159 | string appName = null)
160 | ```
161 | 当appName为null时,则默认使用当前运行程序集的名字作为配置名。
162 | ## 拓展工具
163 | Java信息获取(获取本机安装的所有Java信息)
164 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/App.cs:
--------------------------------------------------------------------------------
1 |
2 | using System.Diagnostics;
3 | using System.Threading;
4 |
5 | namespace JxCode.Windows
6 | {
7 | public class App
8 | {
9 | ///
10 | /// 程序运行的工作路径
11 | ///
12 | public static string Path
13 | {
14 | get { return global::System.Environment.CurrentDirectory; }
15 | }
16 | ///
17 | /// 程序所在路径
18 | ///
19 | public static string BasePath
20 | {
21 | get
22 | {
23 | string t = global::System.AppDomain.CurrentDomain.BaseDirectory;
24 | return t.Substring(0, t.Length - 1);
25 | }
26 | }
27 | ///
28 | /// Exe的完整路径
29 | ///
30 | public static string FullPath
31 | {
32 | get { return global::System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName; }
33 | }
34 | ///
35 | /// Exe的名字(不含扩展名)
36 | ///
37 | public static string EXEName
38 | {
39 | get { return global::System.IO.Path.GetFileNameWithoutExtension(FullPath); }
40 | }
41 | ///
42 | /// 是否有程序实例在运行
43 | ///
44 | public static bool PrevInstance
45 | {
46 | get
47 | {
48 | string processName = Process.GetCurrentProcess().ProcessName;
49 | Process[] processes = Process.GetProcessesByName(processName);
50 | if(processes.Length > 1)
51 | {
52 | return true;
53 | }
54 | else
55 | {
56 | return false;
57 | }
58 | }
59 | }
60 | public static void End(int exitCode = 0)
61 | {
62 | System.Environment.Exit(exitCode);
63 | }
64 | }
65 | }
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/FileDialog.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Runtime.InteropServices;
4 | using System.Text;
5 |
6 | namespace JxCode.Windows
7 | {
8 | public static class FileDialog
9 | {
10 | private const string DLL_NAME = "comdlg32.dll";
11 | #region nativeDefine
12 | [DllImport(DLL_NAME, SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
13 | private extern static int GetOpenFileName(ref OPENFILENAME pOpenfilename);
14 | [DllImport(DLL_NAME, SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
15 | private extern static bool GetSaveFileName(ref OPENFILENAME pOpenfilename);
16 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
17 | private struct OPENFILENAME
18 | {
19 | public int lStructSize;
20 | public IntPtr hwndOwner;
21 | public int hInstance;
22 | public string lpstrFilter;
23 | public string lpstrCustomFilter;
24 | public int nMaxCustFilter;
25 | public int nFilterIndex;
26 | public string lpstrFile;
27 | public int nMaxFile;
28 | public string lpstrFileTitle;
29 | public int nMaxFileTitle;
30 | public string lpstrInitialDir;
31 | public string lpstrTitle;
32 | public OFNEnum Flags;
33 | public short nFileOffset;
34 | public short nFileExtension;
35 | public string lpstrDefExt;
36 | public int lCustData;
37 | public IntPtr lpfnHook;
38 | public string lpTemplateName;
39 | }
40 | private enum OFNEnum : uint
41 | {
42 | OFN_READONLY = 0x00000001,
43 | OFN_OVERWRITEPROMPT = 0x00000002,
44 | OFN_HIDEREADONLY = 0x00000004,
45 | OFN_NOCHANGEDIR = 0x00000008,
46 | OFN_SHOWHELP = 0x00000010,
47 | OFN_ENABLEHOOK = 0x00000020,
48 | OFN_ENABLETEMPLATE = 0x00000040,
49 | OFN_ENABLETEMPLATEHANDLE = 0x00000080,
50 | OFN_NOVALIDATE = 0x00000100,
51 | OFN_ALLOWMULTISELECT = 0x00000200,
52 | OFN_EXTENSIONDIFFERENT = 0x00000400,
53 | OFN_PATHMUSTEXIST = 0x00000800,
54 | OFN_FILEMUSTEXIST = 0x00001000,
55 | OFN_CREATEPROMPT = 0x00002000,
56 | OFN_SHAREAWARE = 0x00004000,
57 | OFN_NOREADONLYRETURN = 0x00008000,
58 | OFN_NOTESTFILECREATE = 0x00010000,
59 | OFN_NONETWORKBUTTON = 0x00020000,
60 | OFN_NOLONGNAMES = 0x00040000,
61 | OFN_EXPLORER = 0x00080000,
62 | OFN_NODEREFERENCELINKS = 0x00100000,
63 | OFN_LONGNAMES = 0x00200000,
64 | OFN_ENABLEINCLUDENOTIFY = 0x00400000,
65 | OFN_ENABLESIZING = 0x00800000,
66 | OFN_DONTADDTORECENT = 0x02000000,
67 | OFN_FORCESHOWHIDDEN = 0x10000000,
68 | }
69 | #endregion
70 | private static OPENFILENAME GetOFN(string dirPath, string filter, string title, string defaultFilename)
71 | {
72 | OPENFILENAME ofn = new OPENFILENAME();
73 | ofn.lStructSize = Marshal.SizeOf(ofn);
74 | ofn.lpstrFilter = filter.Replace('|', '\0') + '\0';
75 | ofn.nFilterIndex = 1;
76 | ofn.lpstrInitialDir = dirPath;
77 |
78 | char[] _filename = new char[256];
79 | char[] _defaultFilename = defaultFilename.ToCharArray();
80 | Array.Copy(_defaultFilename, _filename, _defaultFilename.Length);
81 | string filename = new string(_filename);
82 |
83 | ofn.lpstrTitle = title;
84 | ofn.lpstrFile = filename;
85 | ofn.nMaxFile = ofn.lpstrFile.Length;
86 |
87 | ofn.Flags = OFNEnum.OFN_PATHMUSTEXIST | OFNEnum.OFN_FILEMUSTEXIST;
88 |
89 | return ofn;
90 | }
91 | ///
92 | /// 打开文件对话框
93 | ///
94 | ///
95 | ///
96 | ///
97 | ///
98 | /// 打开的文件名,如果取消则为null
99 | public static string OpenFileDialog(
100 | string dirPath,
101 | string filter,
102 | string title = "OpenFileDialog",
103 | string defaultFilename = "")
104 | {
105 | OPENFILENAME ofn = GetOFN(dirPath, filter, title, defaultFilename);
106 | int result = GetOpenFileName(ref ofn);
107 | return result > 0 ? ofn.lpstrFile : null;
108 | }
109 | ///
110 | /// 保存文件的对话框
111 | ///
112 | ///
113 | ///
114 | ///
115 | ///
116 | /// 保存的文件名,如果取消则为null
117 | public static string SaveFileDialog(string dirPath,
118 | string filter = "All(*.*)|*.*",
119 | string title = "SaveFileDialog",
120 | string defaultFilename = "")
121 | {
122 | OPENFILENAME ofn = GetOFN(dirPath, filter, title, defaultFilename);
123 | bool result = GetSaveFileName(ref ofn);
124 | return result ? ofn.lpstrFile : null;
125 | }
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/IniHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using JxCode.Windows.Native;
5 |
6 | namespace JxCode.Windows
7 | {
8 | public sealed class INIFile
9 | {
10 | private string filepath = string.Empty;
11 | public string FilePath => filepath;
12 |
13 | public INISection this[string sectionName]
14 | {
15 | get
16 | {
17 | return new INISection(this, sectionName);
18 | }
19 | }
20 |
21 | public INIFile(string filepath)
22 | {
23 | this.filepath = filepath;
24 | }
25 |
26 | public INISection GetSection(string name) => this[name];
27 |
28 | public void SetValue(string sectionName, string key, object value)
29 | {
30 | Kernel32.WritePrivateProfileString(sectionName, key, value.ToString(), FilePath);
31 | }
32 | public string GetValue(string sectionName, string key)
33 | {
34 | byte[] buf = new byte[255];
35 | Kernel32.GetPrivateProfileString(sectionName, key, string.Empty, buf, 255, FilePath);
36 | string s = Encoding.GetEncoding(0).GetString(buf);
37 | s = s.Substring(0, buf.Length);
38 | return s;
39 | }
40 | }
41 |
42 | public sealed class INISection
43 | {
44 | private INIFile parent;
45 | private string sectionName;
46 | public INISection(INIFile parent, string sectionName)
47 | {
48 | this.parent = parent;
49 | this.sectionName = sectionName;
50 | }
51 | public string this[string key] => GetValue(key);
52 |
53 | public void SetValue(string key, object value)
54 | {
55 | this.parent.SetValue(sectionName, key, value);
56 | }
57 | public string GetValue(string key)
58 | {
59 | return this.parent.GetValue(sectionName, key);
60 | }
61 |
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/KeyboardUtil.cs:
--------------------------------------------------------------------------------
1 | using JxCode.Windows.Native;
2 |
3 | namespace JxCode.Windows
4 | {
5 | public static class KeyboardUtil
6 | {
7 | public static void Down(User32.VK_Keys key)
8 | {
9 | User32.keybd_event(key, 0, User32.KeyEvent.down, 0);
10 | }
11 | public static void Up(User32.VK_Keys key)
12 | {
13 | User32.keybd_event(key, 0, User32.KeyEvent.up, 0);
14 | }
15 | public static void Click(User32.VK_Keys key)
16 | {
17 | User32.keybd_event(key, 0, User32.KeyEvent.down, 0);
18 | User32.keybd_event(key, 0, User32.KeyEvent.up, 0);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/MCIPlayer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 | using JxCode.Windows.Native;
4 | using WindowStyle = JxCode.Windows.Native.User32.WS_WindowStyle;
5 |
6 | namespace JxCode.Windows
7 | {
8 | public class MCIPlayer
9 | {
10 | public string FilePath { get; set; }
11 | private string alias = "ll";
12 | public IntPtr Handle { get; set; }
13 |
14 | public void Play(bool isLoop = false)
15 | {
16 | StringBuilder sb = new StringBuilder();
17 | sb.AppendFormat("open {0} alias {1}", this.FilePath, this.alias);
18 | if (this.Handle != IntPtr.Zero)
19 | sb.AppendFormat(" parent {0} style child", this.Handle, ((long)WindowStyle.WS_CHILD).ToString());
20 |
21 | ExecuteCommand(sb.ToString());
22 | string playCmd = "play " + this.alias + (isLoop ? " repeat" : string.Empty);
23 | ExecuteCommand(playCmd);
24 | }
25 | public void Stop()
26 | {
27 | ExecuteCommand(string.Format("stop {0}", this.alias));
28 | }
29 |
30 | public void SetSize(int x, int y, int width, int height)
31 | {
32 | string cmd = string.Format("put {0} window at {1} {2} {3} {4}",
33 | this.alias, x, y, width, height);
34 | try
35 | {
36 | ExecuteCommand(cmd);
37 | }
38 | catch (Exception)
39 | {
40 | }
41 | }
42 |
43 | public static void ExecuteCommand(string cmd)
44 | {
45 | var err = Winmm.mciSendString(cmd, null, 0, 0);
46 |
47 | if (err != 0)
48 | {
49 | StringBuilder buf = new StringBuilder(256);
50 | Winmm.mciGetErrorString(err, buf, 256);
51 | string errStr = buf.ToString();
52 | throw new MCIException(string.Format("ErrorCode: {0} ,Info: {1}", err.ToString(), errStr));
53 | }
54 | }
55 |
56 | public static void PlayMusic(string musicPath, bool isLoop)
57 | {
58 | try
59 | {
60 | ExecuteCommand("close __MUSIC");
61 | }
62 | catch (Exception)
63 | {
64 | }
65 |
66 | ExecuteCommand("open \"" + musicPath + "\" alias __MUSIC");
67 | ExecuteCommand("play __MUSIC" + (isLoop ? " repeat" : string.Empty));
68 |
69 |
70 | }
71 | public static void StopMusic(string musicPath)
72 | {
73 | ExecuteCommand("stop __MUSIC");
74 | }
75 |
76 |
77 | public class MCIException : ApplicationException
78 | {
79 | public MCIException(string errMsg) : base(errMsg)
80 | {
81 |
82 | }
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/MessageBox.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Reflection;
4 | using System.Text;
5 | using JxCode.Windows.Native;
6 |
7 | namespace JxCode.Windows
8 | {
9 | public static class MessageBox
10 | {
11 | public static DialogResult Show(string text)
12 | {
13 | return Show(text, Assembly.GetCallingAssembly().GetName().Name);
14 | }
15 | public static DialogResult Show(string text, string caption)
16 | {
17 | return Show(text, caption, MessageBoxButtons.Ok);
18 | }
19 | public static DialogResult Show(string text, string caption, MessageBoxButtons button)
20 | {
21 | return (DialogResult)User32.MessageBox(default, text, caption, (uint)button);
22 | }
23 | public static DialogResult Show(IntPtr OnwerHWND, string text, string caption, MessageBoxButtons button)
24 | {
25 | return (DialogResult)User32.MessageBox(OnwerHWND, text, caption, (uint)button);
26 | }
27 | }
28 | public enum MessageBoxButtons
29 | {
30 | Ok = 0x00,
31 | OkCancel = 0x01,
32 | AbortRetryIgnore = 0x02,
33 | YesNoCancel = 0x03,
34 | YesNo = 0x04,
35 | RetryCancel = 0x05,
36 | CancelTryContinue = 0x06,
37 |
38 | IconHand = 0x10,
39 | IconQuestion = 0x20,
40 | UcibExclamation = 0x30,
41 | IconAsterisk = 0x40,
42 | UserIcon = 0x80,
43 | IconWarning = 0x30,
44 | IconError = 0x10,
45 | IconInformation = 0x40,
46 | IconStop = 0x10,
47 | }
48 | public enum DialogResult
49 | {
50 | Ok = 1 ,
51 | Cancel = 2 ,
52 | Abort = 3 ,
53 | Retry = 4 ,
54 | Ignore = 5 ,
55 | Yes = 6 ,
56 | No = 7 ,
57 | Close = 8 ,
58 | Help = 9 ,
59 | TryAgain = 10,
60 | Continue = 11,
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/MouseUtil.cs:
--------------------------------------------------------------------------------
1 | using JxCode.Windows.Native;
2 | using MouseEventType = JxCode.Windows.Native.User32.MOUSEEVENTF_MouseEventType;
3 |
4 | namespace JxCode.Windows
5 | {
6 | ///
7 | /// 鼠标操作类
8 | ///
9 | public static class MouseUtil
10 | {
11 | public static void SetCursorPosition(int x , int y)
12 | {
13 | User32.SetCursorPos(x, y);
14 | }
15 | public static void SetToCenter()
16 | {
17 | User32.mouse_event(MouseEventType.MOUSEEVENTF_MOVE | MouseEventType.MOUSEEVENTF_ABSOLUTE, 32768, 32768, 0, 0);
18 | }
19 | public static void LeftClick()
20 | {
21 | User32.mouse_event(MouseEventType.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
22 | User32.mouse_event(MouseEventType.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
23 | }
24 | public static void RightClick()
25 | {
26 | User32.mouse_event(MouseEventType.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
27 | User32.mouse_event(MouseEventType.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
28 | }
29 | public static void MiddleDown()
30 | {
31 | User32.mouse_event(MouseEventType.MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0);
32 | User32.mouse_event(MouseEventType.MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0);
33 | }
34 | public static void MiddleWhell(int count)
35 | {
36 | User32.mouse_event(MouseEventType.MOUSEEVENTF_WHEEL, 0, 0, count, 0);
37 | }
38 |
39 | public static User32.Point GetMousePosition()
40 | {
41 | User32.Point p = new User32.Point();
42 | User32.GetCursorPos(ref p);
43 | return p;
44 | }
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/Native/Kernel32.cs:
--------------------------------------------------------------------------------
1 |
2 | using System;
3 | using System.Runtime.InteropServices;
4 |
5 | namespace JxCode.Windows.Native
6 | {
7 | public static class Kernel32
8 | {
9 | private const string DLL_NAME = "kernel32.dll";
10 | [DllImport(DLL_NAME, EntryPoint = "GetPrivateProfileString")]
11 | public static extern int GetPrivateProfileString(string section, string key, string def, byte[] retVal, int size, string filePath);
12 | [DllImport(DLL_NAME, EntryPoint = "WritePrivateProfileString")]
13 | public static extern int WritePrivateProfileString(string section, string key, string val, string filePath);
14 |
15 | [DllImport(DLL_NAME, EntryPoint = "GetModuleHandle")]
16 | public static extern IntPtr GetModuleHandle(string name);
17 | [DllImport(DLL_NAME, EntryPoint = "GetCurrentThreadId")]
18 | private static extern int GetCurrentThreadId();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/Native/Shell32.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 | using DWORD = System.Int32;
4 | using TCHAR = System.Char;
5 | using UINT = System.UInt32;
6 |
7 | namespace JxCode.Windows.Native
8 | {
9 | public static class Shell32
10 | {
11 | private const string DLL_NAME = "shell32.dll";
12 | [DllImport(DLL_NAME, EntryPoint = "ExtractIcon", CharSet = CharSet.Unicode)]
13 | public static extern IntPtr ExtractIcon(int hInst, string lpszExeFileName, int nIconIndex);
14 | [DllImport(DLL_NAME, EntryPoint = "Shell_NotifyIconW", CharSet = CharSet.Unicode)]
15 | public static extern bool Shell_NotifyIconW(NIM_NotityMessage dwMessage, NotifyIconData lpdata);
16 |
17 | public enum NIM_NotityMessage
18 | {
19 | NIM_ADD = 0x00000000,
20 | NIM_MODIFY = 0x00000001,
21 | NIM_DELETE = 0x00000002,
22 | NIM_SETFOCUS = 0x00000003,
23 | NIM_SETVERSION = 0x00000004,
24 | }
25 | public enum NIF_NotifyFlag
26 | {
27 | NIF_MESSAGE = 0x00000001,
28 | NIF_ICON = 0x00000002,
29 | NIF_TIP = 0x00000004,
30 | NIF_STATE = 0x00000008,
31 | NIF_INFO = 0x00000010,
32 | NIF_GUID = 0x00000020,
33 | NIF_REALTIME = 0x00000040,
34 | NIF_SHOWTIP = 0x00000080,
35 | }
36 | ///
37 | /// 32bit length: 152 ; 64bit length: 160
38 | ///
39 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
40 | public struct NotifyIconData
41 | {
42 | public DWORD cbSize;
43 | public IntPtr hWnd;
44 | public UINT uID;
45 | public NIF_NotifyFlag uFlags;
46 | public UINT uCallbackMessage;
47 | public IntPtr hIcon;
48 |
49 | ///
50 | /// 固定数组长度:64
51 | ///
52 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
53 | public char[] szTip; //128
54 | }
55 |
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/Native/User32.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 | using System.Text;
4 |
5 | namespace JxCode.Windows.Native
6 | {
7 | public static partial class User32
8 | {
9 | private const string DLL_NAME = "user32.dll";
10 | public delegate bool WNDENUMPROC(IntPtr hwnd, IntPtr lParam);
11 | [DllImport(DLL_NAME, EntryPoint = "SetWindowText", CharSet = CharSet.Unicode)]
12 | public static extern bool SetWindowText(IntPtr hwnd, string title);
13 | [DllImport(DLL_NAME, EntryPoint = "EnumWindows")]
14 | public static extern int EnumWindows(WNDENUMPROC lpEnumFunc, IntPtr lParam);
15 | [DllImport(DLL_NAME, EntryPoint = "GetWindowThreadProcessId")]
16 | public static extern uint GetWindowThreadProcessId(IntPtr hWnd, ref IntPtr lpdwProcessId);
17 | [DllImport(DLL_NAME, EntryPoint = "CloseWindow")]
18 | public static extern bool CloseWindow(IntPtr hwnd);
19 |
20 | [DllImport(DLL_NAME, EntryPoint = "SendMessage")]
21 | public static extern int SendMessage(IntPtr hWnd, uint wMsg, IntPtr wParam, string lParam);
22 | [DllImport(DLL_NAME, EntryPoint = "SendMessage")]
23 | public static extern int SendMessage(IntPtr hWnd, uint wMsg, IntPtr wParam, IntPtr lParam);
24 | [DllImport(DLL_NAME, EntryPoint = "SendMessage")]
25 | public static extern int SendMessage(IntPtr hWnd, uint wMsg, uint wParam, uint lParam);
26 | [DllImport(DLL_NAME, EntryPoint = "SendMessage")]
27 | public static extern int SendMessage(IntPtr hWnd, WM_WindowsMessage wMsg, uint wParam, uint lParam);
28 | public static int SendMessage(IntPtr hWnd, WM_WindowsMessage wMsg, SC_SysCommand wParam)
29 | {
30 | return SendMessage(hWnd, wMsg, (uint)wParam, 0);
31 | }
32 | [DllImport(DLL_NAME, EntryPoint = "SendMessage")]
33 | public static extern int SendMessage(IntPtr hWnd, WM_WindowsMessage wMsg, uint wParam, string lParam);
34 | [DllImport(DLL_NAME, EntryPoint = "SendMessage")]
35 | public static extern int SendMessage(IntPtr hWnd, WM_WindowsMessage wMsg, IntPtr wParam, string lParam);
36 | [DllImport(DLL_NAME, EntryPoint = "SendMessage")]
37 | public static extern int SendMessage(IntPtr hWnd, WM_WindowsMessage wMsg, IntPtr wParam, IntPtr lParam);
38 |
39 | [DllImport(DLL_NAME, EntryPoint = "FindWindow")]
40 | public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
41 | [DllImport(DLL_NAME, EntryPoint = "FindWindowEx")]
42 | public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName);
43 | [DllImport(DLL_NAME, EntryPoint = "SetWindowPos")]
44 | public static extern int SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int Width, int Height, int flags);
45 | [DllImport(DLL_NAME, EntryPoint = "GetForegroundWindow")]
46 | public static extern IntPtr GetForegroundWindow();
47 | [DllImport(DLL_NAME, EntryPoint = "SetForegroundWindow")]
48 | public static extern bool SetForegroundWindow(IntPtr hWnd);
49 | [DllImport(DLL_NAME, EntryPoint = "GetWindowRect")]
50 | [return: MarshalAs(UnmanagedType.Bool)]
51 | public static extern bool GetWindowRect(IntPtr hWnd, ref Rect lpRect);
52 | [StructLayout(LayoutKind.Sequential)]
53 | public struct Rect
54 | {
55 | public int Left;
56 | public int Top;
57 | public int Right;
58 | public int Bottom;
59 | }
60 | [DllImport(DLL_NAME, EntryPoint = "keybd_event")]
61 | public static extern void keybd_event(VK_Keys bVk, byte bScan, KeyEvent dwFlags, uint dwExtraInfo);
62 | public enum KeyEvent
63 | {
64 | down = 0,
65 | up = 2
66 | }
67 | ///
68 | ///
69 | ///
70 | ///
71 | ///
72 | ///
73 | /// 仅dwFlags为MOUSEEVENTF_WHEEL,则dwData指定鼠标轮移动的数量。正值表明鼠标轮向前转动,即远离用户的方向
74 | /// 应用程序调用函数GetMessageExtraInfo来获得此附加信息
75 | [DllImport(DLL_NAME, EntryPoint = "mouse_event")]
76 | public static extern void mouse_event(MOUSEEVENTF_MouseEventType dwFlags, int dx = 0, int dy = 0, int dwData = 0, ulong dwExtraInfo = 0);
77 | [DllImport(DLL_NAME, EntryPoint = "GetCursorPos")]
78 | public static extern bool GetCursorPos(ref Point point);
79 | [DllImport(DLL_NAME, EntryPoint = "SetCursorPos")]
80 | public static extern bool SetCursorPos(int x, int y);
81 | public struct Point
82 | {
83 | public int x;
84 | public int y;
85 | public Point(int x, int y)
86 | {
87 | this.x = x;
88 | this.y = y;
89 | }
90 | public override bool Equals(object obj)
91 | {
92 | return obj is Point point &&
93 | x == point.x &&
94 | y == point.y;
95 | }
96 |
97 | public override int GetHashCode()
98 | {
99 | int hashCode = 1502939027;
100 | hashCode = hashCode * -1521134295 + this.x.GetHashCode();
101 | hashCode = hashCode * -1521134295 + this.y.GetHashCode();
102 | return hashCode;
103 | }
104 |
105 | public override string ToString()
106 | {
107 | return string.Format("{{x:{0}, y:{1}}}", x.ToString(), y.ToString());
108 | }
109 | public static bool operator ==(Point a, Point b)
110 | {
111 | return a.Equals(b);
112 | }
113 | public static bool operator !=(Point a, Point b)
114 | {
115 | return a.Equals(b);
116 | }
117 | }
118 | public struct Size
119 | {
120 | public int width;
121 | public int height;
122 | public Size(int width, int height)
123 | {
124 | this.width = width;
125 | this.height = height;
126 | }
127 | public override string ToString()
128 | {
129 | return string.Format("{{width:{0}, height:{1}}}", width.ToString(), height.ToString());
130 | }
131 | }
132 | [DllImport(DLL_NAME, EntryPoint = "WindowFromPoint")]
133 | public static extern IntPtr WindowFromPoint(Point Point);
134 |
135 | [DllImport(DLL_NAME, EntryPoint = "GetWindowText")]
136 | public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
137 |
138 | [DllImport(DLL_NAME, EntryPoint = "GetClassName")]
139 | public static extern int GetClassName(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
140 |
141 | public delegate int HookProc(int nCode, int wParam, IntPtr lParam);// 钩子委托声明
142 | [DllImport(DLL_NAME, EntryPoint = "SetWindowsHookEx")]
143 | public static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr pInstance, int threadId);//安装钩子
144 | [DllImport(DLL_NAME, EntryPoint = "UnhookWindowsHookEx")]// 卸载钩子
145 | public static extern bool UnhookWindowsHookEx(IntPtr pHookHandle);
146 |
147 | [DllImport(DLL_NAME, EntryPoint = "CallNextHookEx")]
148 | public static extern int CallNextHookEx(IntPtr pHookHandle, int nCode, Int32 wParam, IntPtr lParam);
149 | [StructLayout(LayoutKind.Sequential)]
150 | public struct KeyMSG
151 | {
152 | public int vkCode;
153 | public int scanCode;
154 | public int flags;
155 | public int time;
156 | public int dwExtraInfo;
157 | }
158 |
159 | [DllImport(DLL_NAME, EntryPoint = "IsWindow")]
160 | public static extern bool IsWindow(IntPtr hWnd);
161 |
162 | [DllImport(DLL_NAME, EntryPoint = "MessageBox")]
163 | public static extern int MessageBox(IntPtr hWnd, string lpText, string lpCaption, uint uType);
164 |
165 | [DllImport(DLL_NAME, EntryPoint = "GetDesktopWindow")]
166 | public static extern IntPtr GetDesktopWindow();
167 |
168 | [DllImport(DLL_NAME, EntryPoint = "SetParent")]
169 | public static extern IntPtr SetParent(IntPtr hwndChild, IntPtr newParent);
170 |
171 | [DllImport(DLL_NAME, EntryPoint = "GetParent")]
172 | public static extern IntPtr GetParent(IntPtr hWnd);
173 |
174 | //[DllImport(DLL_NAME, EntryPoint = "EnumDisplaySettings")]
175 | //public static extern bool EnumDisplaySettings(string lpszDeviceName, uint iModeNum, lpDevMode);
176 |
177 | public delegate IntPtr WindowLongCallBack(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
178 | [DllImport(DLL_NAME, EntryPoint = "GetWindowLong")]
179 | public extern static IntPtr GetWindowLong(IntPtr hWnd, int nIndex);
180 | [DllImport(DLL_NAME, EntryPoint = "GetWindowLong")]
181 | public extern static IntPtr GetWindowLong(IntPtr hWnd, GWL_WindowsLongMessage nIndex);
182 | [DllImport(DLL_NAME, EntryPoint = "SetWindowLong")]
183 | public extern static IntPtr SetWindowLong(IntPtr hWnd, int nIndex, WindowLongCallBack wndProc);
184 | [DllImport(DLL_NAME, EntryPoint = "SetWindowLong")]
185 | public extern static IntPtr SetWindowLong(IntPtr hWnd, GWL_WindowsLongMessage nIndex, WindowLongCallBack wndProc);
186 | [DllImport(DLL_NAME, EntryPoint = "SetWindowLong")]
187 | public extern static IntPtr SetWindowLong(IntPtr hWnd, GWL_WindowsLongMessage nIndex, uint dwNewLong);
188 | [DllImport(DLL_NAME, EntryPoint = "SetWindowLong")]
189 | public extern static IntPtr SetWindowLong(IntPtr hWnd, GWL_WindowsLongMessage nIndex, IntPtr dwNewLong);
190 | [DllImport(DLL_NAME, EntryPoint = "SetWindowLong")]
191 | public extern static IntPtr SetWindowLong(IntPtr hWnd, GWL_WindowsLongMessage nIndex, WS_WindowStyle dwNewLong);
192 | [DllImport(DLL_NAME, EntryPoint = "CallWindowProc")]
193 | public extern static IntPtr CallWindowProc(IntPtr wndProc, IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
194 |
195 | [DllImport(DLL_NAME, EntryPoint = "GetWindow")]
196 | public extern static IntPtr GetWindow(IntPtr hWnd, GW_GetWindow wCmd);
197 |
198 | [DllImport(DLL_NAME, EntryPoint = "GetActiveWindow")]
199 | public extern static IntPtr GetActiveWindow();
200 |
201 | [DllImport(DLL_NAME, EntryPoint = "EnumChildWindows")]
202 | public static extern int EnumChildWindows(IntPtr hWndParent, WNDENUMPROC lpfn, int lParam);
203 | [DllImport(DLL_NAME, EntryPoint = "SendMessageTimeout")]
204 | public static extern int SendMessageTimeout(
205 | IntPtr hWnd,
206 | uint Msg,
207 | uint wParam,
208 | IntPtr lParam,
209 | uint fuFlags,
210 | uint uTimeout,
211 | IntPtr outOpt_lpdwResult);
212 |
213 |
214 | }
215 | }
216 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/Native/User32Enum/GWL_WindowsLongMessage.cs:
--------------------------------------------------------------------------------
1 | namespace JxCode.Windows.Native
2 | {
3 | public static partial class User32
4 | {
5 | public enum GWL_WindowsLongMessage : int
6 | {
7 | GWL_WNDPROC = -4,
8 | GWL_HINSTANCE = -6,
9 | GWL_HWNDPARENT = -8,
10 | GWL_STYLE = -16,
11 | GWL_EXSTYLE = -20,
12 | GWL_USERDATA = -21,
13 | GWL_ID = -12,
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/Native/User32Enum/GW_GetWindow.cs:
--------------------------------------------------------------------------------
1 | namespace JxCode.Windows.Native
2 | {
3 | public static partial class User32
4 | {
5 | public enum GW_GetWindow : int
6 | {
7 | GW_HWNDFIRST = 0,
8 | GW_HWNDLAST = 1,
9 | GW_HWNDNEXT = 2,
10 | GW_HWNDPREV = 3,
11 | GW_OWNER = 4,
12 | GW_CHILD = 5,
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/Native/User32Enum/MOUSEEVENTF_MouseEventType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace JxCode.Windows.Native
6 | {
7 | public static partial class User32
8 | {
9 | public enum MOUSEEVENTF_MouseEventType : int
10 | {
11 | ///
12 | /// 移动鼠标
13 | ///
14 | MOUSEEVENTF_MOVE = 0x0001,
15 | ///
16 | /// 模拟鼠标左键按下
17 | ///
18 | MOUSEEVENTF_LEFTDOWN = 0x0002,
19 | ///
20 | /// 模拟鼠标左键抬起
21 | ///
22 | MOUSEEVENTF_LEFTUP = 0x0004,
23 | ///
24 | /// 模拟鼠标右键按下
25 | ///
26 | MOUSEEVENTF_RIGHTDOWN = 0x0008,
27 | ///
28 | /// 模拟鼠标右键抬起
29 | ///
30 | MOUSEEVENTF_RIGHTUP = 0x0010,
31 | ///
32 | /// 模拟鼠标中键按下
33 | ///
34 | MOUSEEVENTF_MIDDLEDOWN = 0x0020,
35 | ///
36 | /// 模拟鼠标中键抬起
37 | ///
38 | MOUSEEVENTF_MIDDLEUP = 0x0040,
39 | ///
40 | /// 标示是否采用绝对坐标
41 | ///
42 | MOUSEEVENTF_ABSOLUTE = 0x8000,
43 | ///
44 | /// 模拟鼠标滚轮滚动操作,必须配合dwData参数
45 | ///
46 | MOUSEEVENTF_WHEEL = 0x0800,
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/Native/User32Enum/SC_SysCommand.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace JxCode.Windows.Native
6 | {
7 | public static partial class User32
8 | {
9 | public enum SC_SysCommand
10 | {
11 | SC_SIZE = 0xF000,
12 | SC_MOVE = 0xF010,
13 | SC_MINIMIZE = 0xF020,
14 | SC_MAXIMIZE = 0xF030,
15 | SC_NEXTWINDOW = 0xF040,
16 | SC_PREVWINDOW = 0xF050,
17 | SC_CLOSE = 0xF060,
18 | SC_VSCROLL = 0xF070,
19 | SC_HSCROLL = 0xF080,
20 | SC_MOUSEMENU = 0xF090,
21 | SC_KEYMENU = 0xF100,
22 | SC_ARRANGE = 0xF110,
23 | SC_RESTORE = 0xF120,
24 | SC_TASKLIST = 0xF130,
25 | SC_SCREENSAVE = 0xF140,
26 | SC_HOTKEY = 0xF150,
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/Native/User32Enum/VK_Keys.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace JxCode.Windows.Native
6 | {
7 | public static partial class User32
8 | {
9 | ///
10 | /// Windows 使用的256个虚拟键码
11 | ///
12 | public enum VK_Keys
13 | {
14 | ///
15 | ///
16 | ///
17 | VK_LBUTTON = 0x1,
18 | ///
19 | ///
20 | ///
21 | VK_RBUTTON = 0x2,
22 | ///
23 | ///
24 | ///
25 | VK_CANCEL = 0x3,
26 | ///
27 | ///
28 | ///
29 | VK_MBUTTON = 0x4,
30 | ///
31 | ///
32 | ///
33 | VK_BACK = 0x8,
34 | ///
35 | ///
36 | ///
37 | VK_TAB = 0x9,
38 | ///
39 | ///
40 | ///
41 | VK_CLEAR = 0xC,
42 | ///
43 | ///
44 | ///
45 | VK_RETURN = 0xD,
46 | ///
47 | ///
48 | ///
49 | VK_SHIFT = 0x10,
50 | ///
51 | ///
52 | ///
53 | VK_CONTROL = 0x11,
54 | ///
55 | ///
56 | ///
57 | VK_MENU = 0x12,
58 | ///
59 | ///
60 | ///
61 | VK_PAUSE = 0x13,
62 | ///
63 | ///
64 | ///
65 | VK_CAPITAL = 0x14,
66 | ///
67 | ///
68 | ///
69 | VK_ESCAPE = 0x1B,
70 | ///
71 | ///
72 | ///
73 | VK_SPACE = 0x20,
74 | ///
75 | ///
76 | ///
77 | VK_PRIOR = 0x21,
78 | ///
79 | ///
80 | ///
81 | VK_NEXT = 0x22,
82 | ///
83 | ///
84 | ///
85 | VK_END = 0x23,
86 | ///
87 | ///
88 | ///
89 | VK_HOME = 0x24,
90 | ///
91 | ///
92 | ///
93 | VK_LEFT = 0x25,
94 | ///
95 | ///
96 | ///
97 | VK_UP = 0x26,
98 | ///
99 | ///
100 | ///
101 | VK_RIGHT = 0x27,
102 | ///
103 | ///
104 | ///
105 | VK_DOWN = 0x28,
106 | ///
107 | ///
108 | ///
109 | VK_Select = 0x29,
110 | ///
111 | ///
112 | ///
113 | VK_PRINT = 0x2A,
114 | ///
115 | ///
116 | ///
117 | VK_EXECUTE = 0x2B,
118 | ///
119 | ///
120 | ///
121 | VK_SNAPSHOT = 0x2C,
122 | ///
123 | ///
124 | ///
125 | VK_Insert = 0x2D,
126 | ///
127 | ///
128 | ///
129 | VK_Delete = 0x2E,
130 | ///
131 | ///
132 | ///
133 | VK_HELP = 0x2F,
134 | ///
135 | ///
136 | ///
137 | VK_0 = 0x30,
138 | ///
139 | ///
140 | ///
141 | VK_1 = 0x31,
142 | ///
143 | ///
144 | ///
145 | VK_2 = 0x32,
146 | ///
147 | ///
148 | ///
149 | VK_3 = 0x33,
150 | ///
151 | ///
152 | ///
153 | VK_4 = 0x34,
154 | ///
155 | ///
156 | ///
157 | VK_5 = 0x35,
158 | ///
159 | ///
160 | ///
161 | VK_6 = 0x36,
162 | ///
163 | ///
164 | ///
165 | VK_7 = 0x37,
166 | ///
167 | ///
168 | ///
169 | VK_8 = 0x38,
170 | ///
171 | ///
172 | ///
173 | VK_9 = 0x39,
174 | ///
175 | ///
176 | ///
177 | VK_A = 0x41,
178 | ///
179 | ///
180 | ///
181 | VK_B = 0x42,
182 | ///
183 | ///
184 | ///
185 | VK_C = 0x43,
186 | ///
187 | ///
188 | ///
189 | VK_D = 0x44,
190 | ///
191 | ///
192 | ///
193 | VK_E = 0x45,
194 | ///
195 | ///
196 | ///
197 | VK_F = 0x46,
198 | ///
199 | ///
200 | ///
201 | VK_G = 0x47,
202 | ///
203 | ///
204 | ///
205 | VK_H = 0x48,
206 | ///
207 | ///
208 | ///
209 | VK_I = 0x49,
210 | ///
211 | ///
212 | ///
213 | VK_J = 0x4A,
214 | ///
215 | ///
216 | ///
217 | VK_K = 0x4B,
218 | ///
219 | ///
220 | ///
221 | VK_L = 0x4C,
222 | ///
223 | ///
224 | ///
225 | VK_M = 0x4D,
226 | ///
227 | ///
228 | ///
229 | VK_N = 0x4E,
230 | ///
231 | ///
232 | ///
233 | VK_O = 0x4F,
234 | ///
235 | ///
236 | ///
237 | VK_P = 0x50,
238 | ///
239 | ///
240 | ///
241 | VK_Q = 0x51,
242 | ///
243 | ///
244 | ///
245 | VK_R = 0x52,
246 | ///
247 | ///
248 | ///
249 | VK_S = 0x53,
250 | ///
251 | ///
252 | ///
253 | VK_T = 0x54,
254 | ///
255 | ///
256 | ///
257 | VK_U = 0x55,
258 | ///
259 | ///
260 | ///
261 | VK_V = 0x56,
262 | ///
263 | ///
264 | ///
265 | VK_W = 0x57,
266 | ///
267 | ///
268 | ///
269 | VK_X = 0x58,
270 | ///
271 | ///
272 | ///
273 | VK_Y = 0x59,
274 | ///
275 | ///
276 | ///
277 | VK_Z = 0x5A,
278 | ///
279 | ///
280 | ///
281 | VK_STARTKEY = 0x5B,
282 | ///
283 | ///
284 | ///
285 | VK_CONTEXTKEY = 0x5D,
286 | ///
287 | ///
288 | ///
289 | VK_NUMPAD0 = 0x60,
290 | ///
291 | ///
292 | ///
293 | VK_NUMPAD1 = 0x61,
294 | ///
295 | ///
296 | ///
297 | VK_NUMPAD2 = 0x62,
298 | ///
299 | ///
300 | ///
301 | VK_NUMPAD3 = 0x63,
302 | ///
303 | ///
304 | ///
305 | VK_NUMPAD4 = 0x64,
306 | ///
307 | ///
308 | ///
309 | VK_NUMPAD5 = 0x65,
310 | ///
311 | ///
312 | ///
313 | VK_NUMPAD6 = 0x66,
314 | ///
315 | ///
316 | ///
317 | VK_NUMPAD7 = 0x67,
318 | ///
319 | ///
320 | ///
321 | VK_NUMPAD8 = 0x68,
322 | ///
323 | ///
324 | ///
325 | VK_NUMPAD9 = 0x69,
326 | ///
327 | ///
328 | ///
329 | VK_MULTIPLY = 0x6A,
330 | ///
331 | ///
332 | ///
333 | VK_ADD = 0x6B,
334 | ///
335 | ///
336 | ///
337 | VK_SEPARATOR = 0x6C,
338 | ///
339 | ///
340 | ///
341 | VK_SUBTRACT = 0x6D,
342 | ///
343 | ///
344 | ///
345 | VK_DECIMAL = 0x6E,
346 | ///
347 | ///
348 | ///
349 | VK_DIVIDE = 0x6F,
350 | ///
351 | ///
352 | ///
353 | VK_F1 = 0x70,
354 | ///
355 | ///
356 | ///
357 | VK_F2 = 0x71,
358 | ///
359 | ///
360 | ///
361 | VK_F3 = 0x72,
362 | ///
363 | ///
364 | ///
365 | VK_F4 = 0x73,
366 | ///
367 | ///
368 | ///
369 | VK_F5 = 0x74,
370 | ///
371 | ///
372 | ///
373 | VK_F6 = 0x75,
374 | ///
375 | ///
376 | ///
377 | VK_F7 = 0x76,
378 | ///
379 | ///
380 | ///
381 | VK_F8 = 0x77,
382 | ///
383 | ///
384 | ///
385 | VK_F9 = 0x78,
386 | ///
387 | ///
388 | ///
389 | VK_F10 = 0x79,
390 | ///
391 | ///
392 | ///
393 | VK_F11 = 0x7A,
394 | ///
395 | ///
396 | ///
397 | VK_F12 = 0x7B,
398 | ///
399 | ///
400 | ///
401 | VK_F13 = 0x7C,
402 | ///
403 | ///
404 | ///
405 | VK_F14 = 0x7D,
406 | ///
407 | ///
408 | ///
409 | VK_F15 = 0x7E,
410 | ///
411 | ///
412 | ///
413 | VK_F16 = 0x7F,
414 | ///
415 | ///
416 | ///
417 | VK_F17 = 0x80,
418 | ///
419 | ///
420 | ///
421 | VK_F18 = 0x81,
422 | ///
423 | ///
424 | ///
425 | VK_F19 = 0x82,
426 | ///
427 | ///
428 | ///
429 | VK_F20 = 0x83,
430 | ///
431 | ///
432 | ///
433 | VK_F21 = 0x84,
434 | ///
435 | ///
436 | ///
437 | VK_F22 = 0x85,
438 | ///
439 | ///
440 | ///
441 | VK_F23 = 0x86,
442 | ///
443 | ///
444 | ///
445 | VK_F24 = 0x87,
446 | ///
447 | ///
448 | ///
449 | VK_NUMLOCK = 0x90,
450 | ///
451 | ///
452 | ///
453 | VK_OEM_SCROLL = 0x91,
454 | ///
455 | ///
456 | ///
457 | VK_OEM_1 = 0xBA,
458 | ///
459 | ///
460 | ///
461 | VK_OEM_PLUS = 0xBB,
462 | ///
463 | ///
464 | ///
465 | VK_OEM_COMMA = 0xBC,
466 | ///
467 | ///
468 | ///
469 | VK_OEM_MINUS = 0xBD,
470 | ///
471 | ///
472 | ///
473 | VK_OEM_PERIOD = 0xBE,
474 | ///
475 | ///
476 | ///
477 | VK_OEM_2 = 0xBF,
478 | ///
479 | ///
480 | ///
481 | VK_OEM_3 = 0xC0,
482 | ///
483 | ///
484 | ///
485 | VK_OEM_4 = 0xDB,
486 | ///
487 | ///
488 | ///
489 | VK_OEM_5 = 0xDC,
490 | ///
491 | ///
492 | ///
493 | VK_OEM_6 = 0xDD,
494 | ///
495 | ///
496 | ///
497 | VK_OEM_7 = 0xDE,
498 | ///
499 | ///
500 | ///
501 | VK_OEM_8 = 0xDF,
502 | ///
503 | ///
504 | ///
505 | VK_ICO_F17 = 0xE0,
506 | ///
507 | ///
508 | ///
509 | VK_ICO_F18 = 0xE1,
510 | ///
511 | ///
512 | ///
513 | VK_OEM102 = 0xE2,
514 | ///
515 | ///
516 | ///
517 | VK_ICO_HELP = 0xE3,
518 | ///
519 | ///
520 | ///
521 | VK_ICO_00 = 0xE4,
522 | ///
523 | ///
524 | ///
525 | VK_ICO_CLEAR = 0xE6,
526 | ///
527 | ///
528 | ///
529 | VK_OEM_RESET = 0xE9,
530 | ///
531 | ///
532 | ///
533 | VK_OEM_JUMP = 0xEA,
534 | ///
535 | ///
536 | ///
537 | VK_OEM_PA1 = 0xEB,
538 | ///
539 | ///
540 | ///
541 | VK_OEM_PA2 = 0xEC,
542 | ///
543 | ///
544 | ///
545 | VK_OEM_PA3 = 0xED,
546 | ///
547 | ///
548 | ///
549 | VK_OEM_WSCTRL = 0xEE,
550 | ///
551 | ///
552 | ///
553 | VK_OEM_CUSEL = 0xEF,
554 | ///
555 | ///
556 | ///
557 | VK_OEM_ATTN = 0xF0,
558 | ///
559 | ///
560 | ///
561 | VK_OEM_FINNISH = 0xF1,
562 | ///
563 | ///
564 | ///
565 | VK_OEM_COPY = 0xF2,
566 | ///
567 | ///
568 | ///
569 | VK_OEM_AUTO = 0xF3,
570 | ///
571 | ///
572 | ///
573 | VK_OEM_ENLW = 0xF4,
574 | ///
575 | ///
576 | ///
577 | VK_OEM_BACKTAB = 0xF5,
578 | ///
579 | ///
580 | ///
581 | VK_ATTN = 0xF6,
582 | ///
583 | ///
584 | ///
585 | VK_CRSEL = 0xF7,
586 | ///
587 | ///
588 | ///
589 | VK_EXSEL = 0xF8,
590 | ///
591 | ///
592 | ///
593 | VK_EREOF = 0xF9,
594 | ///
595 | ///
596 | ///
597 | VK_PLAY = 0xFA,
598 | ///
599 | ///
600 | ///
601 | VK_ZOOM = 0xFB,
602 | ///
603 | ///
604 | ///
605 | VK_NONAME = 0xFC,
606 | ///
607 | ///
608 | ///
609 | VK_PA1 = 0xFD,
610 | ///
611 | ///
612 | ///
613 | VK_OEM_CLEAR = 0xFE,
614 | }
615 | }
616 | }
617 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/Native/User32Enum/WA_WindowsActiveMessage.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace JxCode.Windows.Native
3 | {
4 | public static partial class User32
5 | {
6 | public enum WA_WindowsActiveMessage : int
7 | {
8 | WA_INACTIVE = 0,
9 | WA_ACTIVE = 1,
10 | WA_CLICKACTIVE = 2,
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/Native/User32Enum/WM_WindowsMessage.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace JxCode.Windows.Native
6 | {
7 | public static partial class User32
8 | {
9 | public enum WM_WindowsMessage : int
10 | {
11 | ///
12 | ///
13 | ///
14 | WM_NULL = 0x0000,
15 | ///
16 | /// 应用程序创建一个窗口
17 | ///
18 | WM_CREATE = 0x0001,
19 | ///
20 | /// 一个窗口被销毁
21 | ///
22 | WM_DESTROY = 0x0002,
23 | ///
24 | /// 移动一个窗口
25 | ///
26 | WM_MOVE = 0x0003,
27 | ///
28 | /// 改变一个窗口的大小
29 | ///
30 | WM_SIZE = 0x0005,
31 | ///
32 | /// 一个窗口被激活或失去激活状态;
33 | ///
34 | WM_ACTIVATE = 0x0006,
35 | ///
36 | /// 获得焦点后
37 | ///
38 | WM_SETFOCUS = 0x0007,
39 | ///
40 | /// 失去焦点
41 | ///
42 | WM_KILLFOCUS = 0x0008,
43 | ///
44 | /// 改变enable状态
45 | ///
46 | WM_ENABLE = 0x000A,
47 | ///
48 | /// 设置窗口是否能重画
49 | ///
50 | WM_SETREDRAW = 0x000B,
51 | ///
52 | /// 应用程序发送此消息来设置一个窗口的文本
53 | ///
54 | WM_SETTEXT = 0x000C,
55 | ///
56 | /// 应用程序发送此消息来复制对应窗口的文本到缓冲区
57 | ///
58 | WM_GETTEXT = 0x000D,
59 | ///
60 | /// 得到与一个窗口有关的文本的长度(不包含空字符)
61 | ///
62 | WM_GETTEXTLENGTH = 0x000E,
63 | ///
64 | /// 要求一个窗口重画自己
65 | ///
66 | WM_PAINT = 0x000F,
67 | ///
68 | /// 当一个窗口或应用程序要关闭时发送一个信号
69 | ///
70 | WM_CLOSE = 0x0010,
71 | ///
72 | /// 当用户选择结束对话框或程序自己调用ExitWindows函数
73 | ///
74 | WM_QUERYENDSESSION = 0x0011,
75 | ///
76 | /// 用来结束程序运行或当程序调用postquitmessage函数
77 | ///
78 | WM_QUIT = 0x0012,
79 | ///
80 | /// 当用户窗口恢复以前的大小位置时,把此消息发送给某个图标
81 | ///
82 | WM_QUERYOPEN = 0x0013,
83 | ///
84 | /// 当窗口背景必须被擦除时(例在窗口改变大小时)
85 | ///
86 | WM_ERASEBKGND = 0x0014,
87 | ///
88 | /// 当系统颜色改变时,发送此消息给所有顶级窗口
89 | ///
90 | WM_SYSCOLORCHANGE = 0x0015,
91 | ///
92 | /// 当系统进程发出WM_QUERYENDSESSION消息后,此消息发送给应用程序,通知它对话是否结束
93 | ///
94 | WM_ENDSESSION = 0x0016,
95 | ///
96 | ///
97 | ///
98 | WM_SYSTEMERROR = 0x0017,
99 | ///
100 | /// 当隐藏或显示窗口是发送此消息给这个窗口
101 | ///
102 | WM_SHOWWINDOW = 0x0018,
103 | ///
104 | /// 发此消息给应用程序哪个窗口是激活的,哪个是非激活的;
105 | ///
106 | WM_ACTIVATEAPP = 0x001C,
107 | ///
108 | /// 当系统的字体资源库变化时发送此消息给所有顶级窗口
109 | ///
110 | WM_FONTCHANGE = 0x001D,
111 | ///
112 | /// 当系统的时间变化时发送此消息给所有顶级窗口
113 | ///
114 | WM_TIMECHANGE = 0x001E,
115 | ///
116 | /// 发送此消息来取消某种正在进行的摸态(操作)
117 | ///
118 | WM_CANCELMODE = 0x001F,
119 | ///
120 | /// 如果鼠标引起光标在某个窗口中移动且鼠标输入没有被捕获时,就发消息给某个窗口
121 | ///
122 | WM_SETCURSOR = 0x0020,
123 | ///
124 | /// 当光标在某个非激活的窗口中而用户正按着鼠标的某个键发送此消息给当前窗口
125 | ///
126 | WM_MOUSEACTIVATE = 0x0021,
127 | ///
128 | /// 发送此消息给MDI子窗口当用户点击此窗口的标题栏,或当窗口被激活,移动,改变大小
129 | ///
130 | WM_CHILDACTIVATE = 0x0022,
131 | ///
132 | /// 此消息由基于计算机的训练程序发送,通过WH_JOURNALPALYBACK的hook程序分离出用户输入消息
133 | ///
134 | WM_QUEUESYNC = 0x0023,
135 | ///
136 | /// 此消息发送给窗口当它将要改变大小或位置;
137 | ///
138 | WM_GETMINMAXINFO = 0x0024,
139 | ///
140 | /// 发送给最小化窗口当它图标将要被重画
141 | ///
142 | WM_PAINTICON = 0x0026,
143 | ///
144 | /// 此消息发送给某个最小化窗口,仅当它在画图标前它的背景必须被重画
145 | ///
146 | WM_ICONERASEBKGND = 0x0027,
147 | ///
148 | /// 发送此消息给一个对话框程序去更改焦点位置
149 | ///
150 | WM_NEXTDLGCTL = 0x0028,
151 | ///
152 | /// 每当打印管理列队增加或减少一条作业时发出此消息
153 | ///
154 | WM_SPOOLERSTATUS = 0x002A,
155 | ///
156 | /// 当button,combobox,listbox,menu的可视外观改变时发送此消息给这些空件的所有者
157 | ///
158 | WM_DRAWITEM = 0x002B,
159 | ///
160 | /// 当button, combo box, list box, list view control, or menu item 被创建时
161 | /// 发送此消息给控件的所有者
162 | ///
163 | WM_MEASUREITEM = 0x002C,
164 | ///
165 | /// 当the list box 或 combo box 被销毁 或 当某些项被删除通过LB_DELETESTRING, LB_RESETCONTENT,
166 | /// CB_DELETESTRING, or CB_RESETCONTENT 消息
167 | ///
168 | WM_DELETEITEM = 0x002D,
169 | ///
170 | /// 此消息有一个LBS_WANTKEYBOARDINPUT风格的发出给它的所有者来响应WM_KEYDOWN消息
171 | ///
172 | WM_VKEYTOITEM = 0x002E,
173 | ///
174 | /// 此消息由一个LBS_WANTKEYBOARDINPUT风格的列表框发送给他的所有者来响应WM_CHAR消息
175 | ///
176 | WM_CHARTOITEM = 0x002F,
177 | ///
178 | /// 当绘制文本时程序发送此消息得到控件要用的颜色
179 | ///
180 | WM_SETFONT = 0x0030,
181 | ///
182 | /// 应用程序发送此消息得到当前控件绘制文本的字体
183 | ///
184 | WM_GETFONT = 0x0031,
185 | ///
186 | /// 应用程序发送此消息让一个窗口与一个热键相关连
187 | ///
188 | WM_SETHOTKEY = 0x0032,
189 | ///
190 | /// 应用程序发送此消息来判断热键与某个窗口是否有关联
191 | ///
192 | WM_GETHOTKEY = 0x0033,
193 | ///
194 | /// 此消息发送给最小化窗口,当此窗口将要被拖放而它的类中没有定义图标,应用程序能
195 | /// 返回一个图标或光标的句柄,当用户拖放图标时系统显示这个图标或光标
196 | ///
197 | WM_QUERYDRAGICON = 0x0037,
198 | ///
199 | /// 发送此消息来判定combobox或listbox新增加的项的相对位置
200 | ///
201 | WM_COMPAREITEM = 0x0039,
202 | ///
203 | ///
204 | ///
205 | WM_GETOBJECT = 0x003D,
206 | ///
207 | /// 显示内存已经很少了
208 | ///
209 | WM_COMPACTING = 0x0041,
210 | ///
211 | /// 发送此消息给那个窗口的大小和位置将要被改变时,来调用setwindowpos函数或其它窗口管理函数
212 | ///
213 | WM_WINDOWPOSCHANGING = 0x0046,
214 | ///
215 | /// 发送此消息给那个窗口的大小和位置已经被改变时,来调用setwindowpos函数或其它窗口管理函数
216 | ///
217 | WM_WINDOWPOSCHANGED = 0x0047,
218 | ///
219 | /// 当系统将要进入暂停状态时发送此消息 (适用于16位的windows)
220 | ///
221 | WM_POWER = 0x0048,
222 | ///
223 | /// 当一个应用程序传递数据给另一个应用程序时发送此消息
224 | ///
225 | WM_COPYDATA = 0x004A,
226 | ///
227 | /// 当某个用户取消程序日志激活状态,提交此消息给程序
228 | ///
229 | WM_CANCELJOURNAL = 0x004B,
230 | ///
231 | /// 当某个控件的某个事件已经发生或这个控件需要得到一些信息时,发送此消息给它的父窗口
232 | ///
233 | WM_NOTIFY = 0x004E,
234 | ///
235 | /// 当用户选择某种输入语言,或输入语言的热键改变
236 | ///
237 | WM_INPUTLANGCHANGEREQUEST = 0x0050,
238 | ///
239 | /// 当平台现场已经被改变后发送此消息给受影响的最顶级窗口
240 | ///
241 | WM_INPUTLANGCHANGE = 0x0051,
242 | ///
243 | /// 当程序已经初始化windows帮助例程时发送此消息给应用程序
244 | ///
245 | WM_TCARD = 0x0052,
246 | ///
247 | /// 此消息显示用户按下了F1,如果某个菜单是激活的,就发送此消息个此窗口关联的菜单,否则就
248 | /// 发送给有焦点的窗口,如果当前都没有焦点,就把此消息发送给当前激活的窗口
249 | ///
250 | WM_HELP = 0x0053,
251 | ///
252 | /// 当用户已经登入或退出后发送此消息给所有的窗口,当用户登入或退出时系统更新用户的具体
253 | /// 设置信息,在用户更新设置时系统马上发送此消息;
254 | ///
255 | WM_USERCHANGED = 0x0054,
256 | ///
257 | /// 公用控件,自定义控件和他们的父窗口通过此消息来判断控件是使用ANSI还是UNI CODE结构
258 | /// 在WM_NOTIFY消息,使用此控件能使某个控件与它的父控件之间进行相互通信
259 | ///
260 | WM_NOTIFYformAT = 0x0055,
261 | ///
262 | /// 当用户某个窗口中点击了一下右键就发送此消息给这个窗口
263 | ///
264 | WM_CONTEXTMENU = 0x007B,
265 | ///
266 | /// 当调用SETWINDOWLONG函数将要改变一个或多个 窗口的风格时发送此消息给那个窗口
267 | ///
268 | WM_styleCHANGING = 0x007C,
269 | ///
270 | /// 当调用SETWINDOWLONG函数一个或多个 窗口的风格后发送此消息给那个窗口
271 | ///
272 | WM_styleCHANGED = 0x007D,
273 | ///
274 | /// 当显示器的分辨率改变后发送此消息给所有的窗口
275 | ///
276 | WM_DISPLAYCHANGE = 0x007E,
277 | ///
278 | /// 此消息发送给某个窗口来返回与某个窗口有关连的大图标或小图标的句柄;
279 | ///
280 | WM_GETICON = 0x007F,
281 | ///
282 | /// 程序发送此消息让一个新的大图标或小图标与某个窗口关联;
283 | ///
284 | WM_SETICON = 0x0080,
285 | ///
286 | /// 当某个窗口第一次被创建时,此消息在WM_CREATE消息发送前发送;
287 | ///
288 | WM_NCCREATE = 0x0081,
289 | ///
290 | /// 此消息通知某个窗口,非客户区正在销毁
291 | ///
292 | WM_NCDESTROY = 0x0082,
293 | ///
294 | /// 当某个窗口的客户区域必须被核算时发送此消息
295 | ///
296 | WM_NCCALCSIZE = 0x0083,
297 | ///
298 | /// 移动鼠标,按住或释放鼠标时发生
299 | ///
300 | WM_NCHITTEST = 0x0084,
301 | ///
302 | /// 程序发送此消息给某个窗口当它(窗口)的框架必须被绘制时;
303 | ///
304 | WM_NCPAINT = 0x0085,
305 | ///
306 | /// 此消息发送给某个窗口 仅当它的非客户区需要被改变来显示是激活还是非激活状态;
307 | ///
308 | WM_NCACTIVATE = 0x0086,
309 | ///
310 | /// 发送此消息给某个与对话框程序关联的控件,widdows控制方位键和TAB键使输入进入此控件
311 | /// 通过响应WM_GETDLGCODE消息,应用程序可以把他当成一个特殊的输入控件并能处理它
312 | ///
313 | WM_GETDLGCODE = 0x0087,
314 | ///
315 | /// 当光标在一个窗口的非客户区内移动时发送此消息给这个窗口(非客户区 为:窗体的标题栏及窗的边框体)
316 | ///
317 | WM_NCMOUSEMOVE = 0x00A0,
318 | ///
319 | /// 当光标在一个窗口的非客户区同时按下鼠标左键时提交此消息
320 | ///
321 | WM_NCLBUTTONDOWN = 0x00A1,
322 | ///
323 | /// 当用户释放鼠标左键同时光标某个窗口在非客户区十发送此消息;
324 | ///
325 | WM_NCLBUTTONUP = 0x00A2,
326 | ///
327 | /// 当用户双击鼠标左键同时光标某个窗口在非客户区十发送此消息
328 | ///
329 | WM_NCLBUTTONDBLCLK = 0x00A3,
330 | ///
331 | /// 当用户按下鼠标右键同时光标又在窗口的非客户区时发送此消息
332 | ///
333 | WM_NCRBUTTONDOWN = 0x00A4,
334 | ///
335 | /// 当用户释放鼠标右键同时光标又在窗口的非客户区时发送此消息
336 | ///
337 | WM_NCRBUTTONUP = 0x00A5,
338 | ///
339 | /// 当用户双击鼠标右键同时光标某个窗口在非客户区十发送此消息
340 | ///
341 | WM_NCRBUTTONDBLCLK = 0x00A6,
342 | ///
343 | /// 当用户按下鼠标中键同时光标又在窗口的非客户区时发送此消息
344 | ///
345 | WM_NCMBUTTONDOWN = 0x00A7,
346 | ///
347 | /// 当用户释放鼠标中键同时光标又在窗口的非客户区时发送此消息
348 | ///
349 | WM_NCMBUTTONUP = 0x00A8,
350 | ///
351 | /// 当用户双击鼠标中键同时光标又在窗口的非客户区时发送此消息
352 | ///
353 | WM_NCMBUTTONDBLCLK = 0x00A9,
354 | ///
355 | ///
356 | ///
357 | WM_KEYFIRST = 0x0100,
358 | ///
359 | /// 按下一个键
360 | ///
361 | WM_KEYDOWN = 0x0100,
362 | ///
363 | /// 释放一个键
364 | ///
365 | WM_KEYUP = 0x0101,
366 | ///
367 | /// 按下某键,并已发出WM_KEYDOWN, WM_KEYUP消息
368 | ///
369 | WM_CHAR = 0x0102,
370 | ///
371 | /// 当用translatemessage函数翻译WM_KEYUP消息时发送此消息给拥有焦点的窗口
372 | ///
373 | WM_DEADCHAR = 0x0103,
374 | ///
375 | /// 当用户按住ALT键同时按下其它键时提交此消息给拥有焦点的窗口;
376 | ///
377 | WM_SYSKEYDOWN = 0x0104,
378 | ///
379 | /// 当用户释放一个键同时ALT 键还按着时提交此消息给拥有焦点的窗口
380 | ///
381 | WM_SYSKEYUP = 0x0105,
382 | ///
383 | /// 当WM_SYSKEYDOWN消息被TRANSLATEMESSAGE函数翻译后提交此消息给拥有焦点的窗口
384 | ///
385 | WM_SYSCHAR = 0x0106,
386 | ///
387 | /// 当WM_SYSKEYDOWN消息被TRANSLATEMESSAGE函数翻译后发送此消息给拥有焦点的窗口
388 | ///
389 | WM_SYSDEADCHAR = 0x0107,
390 | ///
391 | ///
392 | ///
393 | WM_KEYLAST = 0x0108,
394 | ///
395 | /// 在一个对话框程序被显示前发送此消息给它,通常用此消息初始化控件和执行其它任务
396 | ///
397 | WM_INITDIALOG = 0x0110,
398 | ///
399 | /// 当用户选择一条菜单命令项或当某个控件发送一条消息给它的父窗口,一个快捷键被翻译
400 | ///
401 | WM_COMMAND = 0x0111,
402 | ///
403 | /// 当用户选择窗口菜单的一条命令或当用户选择最大化或最小化时那个窗口会收到此消息
404 | ///
405 | WM_SYSCOMMAND = 0x0112,
406 | ///
407 | /// 发生了定时器事件
408 | ///
409 | WM_TIMER = 0x0113,
410 | ///
411 | /// 当一个窗口标准水平滚动条产生一个滚动事件时发送此消息给那个窗口,也发送给拥有它的控件
412 | ///
413 | WM_HSCROLL = 0x0114,
414 | ///
415 | /// 当一个窗口标准垂直滚动条产生一个滚动事件时发送此消息给那个窗口,发送给拥有它的控件
416 | ///
417 | WM_VSCROLL = 0x0115,
418 | ///
419 | /// 当一个菜单将要被激活时发送此消息,它发生在用户菜单条中的某项或按下某个菜单键,它允许程序在显示前更改菜单
420 | ///
421 | WM_INITMENU = 0x0116,
422 | ///
423 | /// 当一个下拉菜单或子菜单将要被激活时发送此消息,它允许程序在它显示前更改菜单,而不要改变全部
424 | ///
425 | WM_INITMENUPOPUP = 0x0117,
426 | ///
427 | /// 当用户选择一条菜单项时发送此消息给菜单的所有者(一般是窗口)
428 | ///
429 | WM_MENUSELECT = 0x011F,
430 | ///
431 | /// 当菜单已被激活用户按下了某个键(不同于加速键),发送此消息给菜单的所有者;
432 | ///
433 | WM_MENUCHAR = 0x0120,
434 | ///
435 | /// 当一个模态对话框或菜单进入空载状态时发送此消息给它的所有者,一个模态对话框或菜单进入空载
436 | /// 状态就是在处理完一条或几条先前的消息后没有消息它的列队中等待
437 | ///
438 | WM_ENTERIDLE = 0x0121,
439 | ///
440 | ///
441 | ///
442 | WM_MENURBUTTONUP = 0x0122,
443 | ///
444 | ///
445 | ///
446 | WM_MENUDRAG = 0x0123,
447 | ///
448 | ///
449 | ///
450 | WM_MENUGETOBJECT = 0x0124,
451 | ///
452 | ///
453 | ///
454 | WM_UNINITMENUPOPUP = 0x0125,
455 | ///
456 | ///
457 | ///
458 | WM_MENUCOMMAND = 0x0126,
459 | ///
460 | ///
461 | ///
462 | WM_CHANGEUISTATE = 0x0127,
463 | ///
464 | ///
465 | ///
466 | WM_UPDATEUISTATE = 0x0128,
467 | ///
468 | ///
469 | ///
470 | WM_QUERYUISTATE = 0x0129,
471 | ///
472 | /// 在windows绘制消息框前发送此消息给消息框的所有者窗口,通过响应这条消息, 所有者窗口可以
473 | /// 通过使用给定的相关显示设备的句柄来设置消息框的文本和背景颜色
474 | ///
475 | WM_CTLCOLORMSGBOX = 0x0132,
476 | ///
477 | /// 当一个编辑型控件将要被绘制时发送此消息给它的父窗口;通过响应这条消息,所有者窗口可以
478 | /// 通过使用给定的相关显示设备的句柄来设置编辑框的文本和背景颜色
479 | ///
480 | WM_CTLCOLOREDIT = 0x0133,
481 | ///
482 | /// 当一个列表框控件将要被绘制前发送此消息给它的父窗口;通过响应这条消息,所有者窗口可以
483 | /// 通过使用给定的相关显示设备的句柄来设置列表框的文本和背景颜色
484 | ///
485 | WM_CTLCOLORLISTBOX = 0x0134,
486 | ///
487 | /// 当一个按钮控件将要被绘制时发送此消息给它的父窗口;通过响应这条消息,所有者窗口可以
488 | /// 通过使用给定的相关显示设备的句柄来设置按纽的文本和背景颜色
489 | ///
490 | WM_CTLCOLORBTN = 0x0135,
491 | ///
492 | /// 当一个对话框控件将要被绘制前发送此消息给它的父窗口;通过响应这条消息,所有者窗口可以
493 | /// 通过使用给定的相关显示设备的句柄来设置对话框的文本背景颜色
494 | ///
495 | WM_CTLCOLORDLG = 0x0136,
496 | ///
497 | /// 当一个滚动条控件将要被绘制时发送此消息给它的父窗口;通过响应这条消息,所有者窗口可以
498 | /// 通过使用给定的相关显示设备的句柄来设置滚动条的背景颜色
499 | ///
500 | WM_CTLCOLORSCROLLBAR = 0x0137,
501 | ///
502 | /// 当一个静态控件将要被绘制时发送此消息给它的父窗口;通过响应这条消息,所有者窗口可以
503 | /// 通过使用给定的相关显示设备的句柄来设置静态控件的文本和背景颜色
504 | ///
505 | WM_CTLCOLORSTATIC = 0x0138,
506 | ///
507 | ///
508 | ///
509 | WM_MOUSEFIRST = 0x0200,
510 | ///
511 | /// 移动鼠标
512 | ///
513 | WM_MOUSEMOVE = 0x0200,
514 | ///
515 | /// 按下鼠标左键
516 | ///
517 | WM_LBUTTONDOWN = 0x0201,
518 | ///
519 | /// 释放鼠标左键
520 | ///
521 | WM_LBUTTONUP = 0x0202,
522 | ///
523 | /// 双击鼠标左键
524 | ///
525 | WM_LBUTTONDBLCLK = 0x0203,
526 | ///
527 | /// 按下鼠标右键
528 | ///
529 | WM_RBUTTONDOWN = 0x0204,
530 | ///
531 | /// 释放鼠标右键
532 | ///
533 | WM_RBUTTONUP = 0x0205,
534 | ///
535 | /// 双击鼠标右键
536 | ///
537 | WM_RBUTTONDBLCLK = 0x0206,
538 | ///
539 | /// 按下鼠标中键
540 | ///
541 | WM_MBUTTONDOWN = 0x0207,
542 | ///
543 | /// 释放鼠标中键
544 | ///
545 | WM_MBUTTONUP = 0x0208,
546 | ///
547 | /// 双击鼠标中键
548 | ///
549 | WM_MBUTTONDBLCLK = 0x0209,
550 | ///
551 | /// 当鼠标轮子转动时发送此消息给当前有焦点的控件
552 | ///
553 | WM_MOUSEWHEEL = 0x020A,
554 | ///
555 | ///
556 | ///
557 | WM_MOUSELAST = 0x020A,
558 | ///
559 | /// 当MDI子窗口被创建或被销毁,或用户按了一下鼠标键而光标在子窗口上时发送此消息给它的父窗口
560 | ///
561 | WM_PARENTNOTIFY = 0x0210,
562 | ///
563 | /// 发送此消息通知应用程序的主窗口that已经进入了菜单循环模式
564 | ///
565 | WM_ENTERMENULOOP = 0x0211,
566 | ///
567 | /// 发送此消息通知应用程序的主窗口that已退出了菜单循环模式
568 | ///
569 | WM_EXITMENULOOP = 0x0212,
570 | ///
571 | ///
572 | ///
573 | WM_NEXTMENU = 0x0213,
574 | ///
575 | /// 当用户正在调整窗口大小时发送此消息给窗口;通过此消息应用程序可以监视窗口大小和位置也可以修改他们
576 | ///
577 | WM_SIZING = 0x0214,
578 | ///
579 | /// 发送此消息 给窗口当它失去捕获的鼠标时;
580 | ///
581 | WM_CAPTURECHANGED = 0x0215,
582 | ///
583 | /// 当用户在移动窗口时发送此消息,通过此消息应用程序可以监视窗口大小和位置也可以修改他们;
584 | ///
585 | WM_MOVING = 0x0216,
586 | ///
587 | /// 此消息发送给应用程序来通知它有关电源管理事件;
588 | ///
589 | WM_POWERBROADCAST = 0x0218,
590 | ///
591 | /// 当设备的硬件配置改变时发送此消息给应用程序或设备驱动程序
592 | ///
593 | WM_DEVICECHANGE = 0x0219,
594 | ///
595 | ///
596 | ///
597 | WM_IME_STARTCOMPOSITION = 0x010D,
598 | ///
599 | ///
600 | ///
601 | WM_IME_ENDCOMPOSITION = 0x010E,
602 | ///
603 | ///
604 | ///
605 | WM_IME_COMPOSITION = 0x010F,
606 | ///
607 | ///
608 | ///
609 | WM_IME_KEYLAST = 0x010F,
610 | ///
611 | ///
612 | ///
613 | WM_IME_SETCONTEXT = 0x0281,
614 | ///
615 | ///
616 | ///
617 | WM_IME_NOTIFY = 0x0282,
618 | ///
619 | ///
620 | ///
621 | WM_IME_CONTROL = 0x0283,
622 | ///
623 | ///
624 | ///
625 | WM_IME_COMPOSITIONFULL = 0x0284,
626 | ///
627 | ///
628 | ///
629 | WM_IME_SELECT = 0x0285,
630 | ///
631 | ///
632 | ///
633 | WM_IME_CHAR = 0x0286,
634 | ///
635 | ///
636 | ///
637 | WM_IME_REQUEST = 0x0288,
638 | ///
639 | ///
640 | ///
641 | WM_IME_KEYDOWN = 0x0290,
642 | ///
643 | ///
644 | ///
645 | WM_IME_KEYUP = 0x0291,
646 | ///
647 | /// 应用程序发送此消息给多文档的客户窗口来创建一个MDI 子窗口
648 | ///
649 | WM_MDICREATE = 0x0220,
650 | ///
651 | /// 应用程序发送此消息给多文档的客户窗口来关闭一个MDI 子窗口
652 | ///
653 | WM_MDIDESTROY = 0x0221,
654 | ///
655 | /// 应用程序发送此消息给多文档的客户窗口通知客户窗口激活另一个MDI子窗口,当客户窗口收到
656 | /// 此消息后,它发出WM_MDIACTIVE消息给MDI子窗口(未激活)激活它;
657 | ///
658 | WM_MDIACTIVATE = 0x0222,
659 | ///
660 | /// 程序 发送此消息给MDI客户窗口让子窗口从最大最小化恢复到原来大小
661 | ///
662 | WM_MDIRESTORE = 0x0223,
663 | ///
664 | /// 程序 发送此消息给MDI客户窗口激活下一个或前一个窗口
665 | ///
666 | WM_MDINEXT = 0x0224,
667 | ///
668 | /// 程序发送此消息给MDI客户窗口来最大化一个MDI子窗口;
669 | ///
670 | WM_MDIMAXIMIZE = 0x0225,
671 | ///
672 | /// 程序 发送此消息给MDI客户窗口以平铺方式重新排列所有MDI子窗口
673 | ///
674 | WM_MDITILE = 0x0226,
675 | ///
676 | /// 程序 发送此消息给MDI客户窗口以层叠方式重新排列所有MDI子窗口
677 | ///
678 | WM_MDICASCADE = 0x0227,
679 | ///
680 | /// 程序 发送此消息给MDI客户窗口重新排列所有最小化的MDI子窗口
681 | ///
682 | WM_MDIICONARRANGE = 0x0228,
683 | ///
684 | /// 程序 发送此消息给MDI客户窗口来找到激活的子窗口的句柄
685 | ///
686 | WM_MDIGETACTIVE = 0x0229,
687 | ///
688 | /// 程序 发送此消息给MDI客户窗口用MDI菜单代替子窗口的菜单
689 | ///
690 | WM_MDISETMENU = 0x0230,
691 | ///
692 | ///
693 | ///
694 | WM_ENTERSIZEMOVE = 0x0231,
695 | ///
696 | ///
697 | ///
698 | WM_EXITSIZEMOVE = 0x0232,
699 | ///
700 | ///
701 | ///
702 | WM_DROPFILES = 0x0233,
703 | ///
704 | ///
705 | ///
706 | WM_MDIREFRESHMENU = 0x0234,
707 | ///
708 | ///
709 | ///
710 | WM_MOUSEHOVER = 0x02A1,
711 | ///
712 | ///
713 | ///
714 | WM_MOUSELEAVE = 0x02A3,
715 | ///
716 | /// 程序发送此消息给一个编辑框或combobox来删除当前选择的文本
717 | ///
718 | WM_CUT = 0x0300,
719 | ///
720 | /// 程序发送此消息给一个编辑框或combobox来复制当前选择的文本到剪贴板
721 | ///
722 | WM_COPY = 0x0301,
723 | ///
724 | /// 程序发送此消息给editcontrol或combobox从剪贴板中得到数据
725 | ///
726 | WM_PASTE = 0x0302,
727 | ///
728 | /// 程序发送此消息给editcontrol或combobox清除当前选择的内容;
729 | ///
730 | WM_CLEAR = 0x0303,
731 | ///
732 | /// 程序发送此消息给editcontrol或combobox撤消最后一次操作
733 | ///
734 | WM_UNDO = 0x0304,
735 | ///
736 | ///
737 | ///
738 | WM_RENDERformAT = 0x0305,
739 | ///
740 | ///
741 | ///
742 | WM_RENDERALLformATS = 0x0306,
743 | ///
744 | /// 当调用ENPTYCLIPBOARD函数时 发送此消息给剪贴板的所有者
745 | ///
746 | WM_DESTROYCLIPBOARD = 0x0307,
747 | ///
748 | /// 当剪贴板的内容变化时发送此消息给剪贴板观察链的第一个窗口;它允许用剪贴板观察窗口来显示剪贴板的新内容;
749 | ///
750 | WM_DRAWCLIPBOARD = 0x0308,
751 | ///
752 | /// 当剪贴板包含CF_OWNERDIPLAY格式的数据并且剪贴板观察窗口的客户区需要重画;
753 | ///
754 | WM_PAINTCLIPBOARD = 0x0309,
755 | ///
756 | ///
757 | ///
758 | WM_VSCROLLCLIPBOARD = 0x030A,
759 | ///
760 | /// 当剪贴板包含CF_OWNERDIPLAY格式的数据并且剪贴板观察窗口的客户区域的大小已经改变是此消息通过剪
761 | /// 贴板观察窗口发送给剪贴板的所有者;
762 | ///
763 | WM_SIZECLIPBOARD = 0x030B,
764 | ///
765 | /// 通过剪贴板观察窗口发送此消息给剪贴板的所有者来请求一个CF_OWNERDISPLAY格式的剪贴板的名字
766 | ///
767 | WM_ASKCBformATNAME = 0x030C,
768 | ///
769 | /// 当一个窗口从剪贴板观察链中移去时发送此消息给剪贴板观察链的第一个窗口;
770 | ///
771 | WM_CHANGECBCHAIN = 0x030D,
772 | ///
773 | /// 此消息通过一个剪贴板观察窗口发送给剪贴板的所有者 ;它发生在当剪贴板包含CFOWNERDISPALY格式的数据
774 | /// 并且有个事件在剪贴板观察窗的水平滚动条上;所有者应滚动剪贴板图象并更新滚动条的值;
775 | ///
776 | WM_HSCROLLCLIPBOARD = 0x030E,
777 | ///
778 | /// 此消息发送给将要收到焦点的窗口,此消息能使窗口在收到焦点时同时有机会实现他的逻辑调色板
779 | ///
780 | WM_QUERYNEWPALETTE = 0x030F,
781 | ///
782 | /// 当一个应用程序正要实现它的逻辑调色板时发此消息通知所有的应用程序
783 | ///
784 | WM_PALETTEISCHANGING = 0x0310,
785 | ///
786 | /// 此消息在一个拥有焦点的窗口实现它的逻辑调色板后发送此消息给所有顶级并重叠的窗口,以此来改变系统调色板
787 | ///
788 | WM_PALETTECHANGED = 0x0311,
789 | ///
790 | /// 当用户按下由REGISTERHOTKEY函数注册的热键时提交此消息
791 | ///
792 | WM_HOTKEY = 0x0312,
793 | ///
794 | /// 应用程序发送此消息仅当WINDOWS或其它应用程序发出一个请求要求绘制一个应用程序的一部分;
795 | ///
796 | WM_PRINT = 0x0317,
797 | ///
798 | ///
799 | ///
800 | WM_PRINTCLIENT = 0x0318,
801 | ///
802 | ///
803 | ///
804 | WM_HANDHELDFIRST = 0x0358,
805 | ///
806 | ///
807 | ///
808 | WM_HANDHELDLAST = 0x035F,
809 | ///
810 | ///
811 | ///
812 | WM_PENWINFIRST = 0x0380,
813 | ///
814 | ///
815 | ///
816 | WM_PENWINLAST = 0x038F,
817 | ///
818 | ///
819 | ///
820 | WM_COALESCE_FIRST = 0x0390,
821 | ///
822 | ///
823 | ///
824 | WM_COALESCE_LAST = 0x039F,
825 | ///
826 | ///
827 | ///
828 | WM_DDE_FIRST = 0x03E0,
829 | ///
830 | ///
831 | ///
832 | WM_THEMECHNAGED = 0x31A
833 | }
834 |
835 | }
836 | }
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/Native/User32Enum/WSEX_ExtendedWindowStyle.cs:
--------------------------------------------------------------------------------
1 | namespace JxCode.Windows.Native
2 | {
3 | public static partial class User32
4 | {
5 | public enum WSEX_ExtendedWindowStyle : uint
6 | {
7 | WS_EX_DLGMODALFRAME = 0x00000001,
8 | WS_EX_NOPARENTNOTIFY = 0x00000004,
9 | WS_EX_TOPMOST = 0x00000008,
10 | WS_EX_ACCEPTFILES = 0x00000010,
11 | WS_EX_TRANSPARENT = 0x00000020,
12 |
13 | WS_EX_MDICHILD = 0x00000040,
14 | WS_EX_TOOLWINDOW = 0x00000080,
15 | WS_EX_WINDOWEDGE = 0x00000100,
16 | WS_EX_CLIENTEDGE = 0x00000200,
17 | WS_EX_CONTEXTHELP = 0x00000400,
18 |
19 | WS_EX_RIGHT = 0x00001000,
20 | WS_EX_LEFT = 0x00000000,
21 | WS_EX_RTLREADING = 0x00002000,
22 | WS_EX_LTRREADING = 0x00000000,
23 | WS_EX_LEFTSCROLLBAR = 0x00004000,
24 | WS_EX_RIGHTSCROLLBAR = 0x00000000,
25 |
26 | WS_EX_CONTROLPARENT = 0x00010000,
27 | WS_EX_STATICEDGE = 0x00020000,
28 | WS_EX_APPWINDOW = 0x00040000,
29 |
30 | WS_EX_OVERLAPPEDWINDOW = (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE),
31 | WS_EX_PALETTEWINDOW = (WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST),
32 |
33 | WS_EX_LAYERED = 0x00080000,
34 |
35 | WS_EX_NOINHERITLAYOUT = 0x00100000, // Disable inheritence of mirroring by children
36 |
37 | WS_EX_NOREDIRECTIONBITMAP = 0x00200000,
38 |
39 | WS_EX_LAYOUTRTL = 0x00400000, // Right to left mirroring
40 |
41 | WS_EX_COMPOSITED = 0x02000000,
42 |
43 | WS_EX_NOACTIVATE = 0x08000000,
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/Native/User32Enum/WS_WindowStyle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace JxCode.Windows.Native
6 | {
7 | public static partial class User32
8 | {
9 | ///
10 | /// Windows 窗口样式
11 | ///
12 | [Flags]
13 | public enum WS_WindowStyle : uint
14 | {
15 | ///
16 | ///
17 | ///
18 | WS_OVERLAPPED = 0x00000000,
19 | ///
20 | ///
21 | ///
22 | WS_POPUP = 0x80000000,
23 | ///
24 | ///
25 | ///
26 | WS_CHILD = 0x40000000,
27 | ///
28 | ///
29 | ///
30 | WS_MINIMIZE = 0x20000000,
31 | ///
32 | ///
33 | ///
34 | WS_VISIBLE = 0x10000000,
35 | ///
36 | ///
37 | ///
38 | WS_DISABLED = 0x08000000,
39 | ///
40 | ///
41 | ///
42 | WS_CLIPSIBLINGS = 0x04000000,
43 | ///
44 | ///
45 | ///
46 | WS_CLIPCHILDREN = 0x02000000,
47 | ///
48 | ///
49 | ///
50 | WS_MAXIMIZE = 0x01000000,
51 | ///
52 | ///
53 | ///
54 | WS_CAPTION = 0x00C00000,
55 | ///
56 | ///
57 | ///
58 | WS_BORDER = 0x00800000,
59 | ///
60 | ///
61 | ///
62 | WS_DLGFRAME = 0x00400000,
63 | ///
64 | ///
65 | ///
66 | WS_VSCROLL = 0x00200000,
67 | ///
68 | ///
69 | ///
70 | WS_HSCROLL = 0x00100000,
71 | ///
72 | ///
73 | ///
74 | WS_SYSMENU = 0x00080000,
75 | ///
76 | ///
77 | ///
78 | WS_THICKFRAME = 0x00040000,
79 | ///
80 | ///
81 | ///
82 | WS_GROUP = 0x00020000,
83 | ///
84 | ///
85 | ///
86 | WS_TABSTOP = 0x00010000,
87 | ///
88 | ///
89 | ///
90 | WS_MINIMIZEBOX = 0x00020000,
91 | ///
92 | ///
93 | ///
94 | WS_MAXIMIZEBOX = 0x00010000,
95 | ///
96 | ///
97 | ///
98 | WS_TILED = WS_OVERLAPPED,
99 | ///
100 | ///
101 | ///
102 | WS_ICONIC = WS_MINIMIZE,
103 | ///
104 | ///
105 | ///
106 | WS_SIZEBOX = WS_THICKFRAME,
107 | ///
108 | ///
109 | ///
110 | WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW,
111 | ///
112 | ///
113 | ///
114 | WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU |
115 | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX),
116 | ///
117 | ///
118 | ///
119 | WS_POPUPWINDOW = (WS_POPUP | WS_BORDER | WS_SYSMENU),
120 | ///
121 | ///
122 | ///
123 | WS_CHILDWINDOW = (WS_CHILD)
124 | }
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/Native/Winmm.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Runtime.InteropServices;
4 | using System.Text;
5 |
6 | namespace JxCode.Windows.Native
7 | {
8 | public class Winmm
9 | {
10 | private const string DLL_NAME = @"winmm.dll";
11 |
12 | [DllImport("winmm.dll", EntryPoint = "mciSendString" , CharSet = CharSet.Auto)]
13 | public static extern int mciSendString
14 | (string lpszCommand, string lpszReturnString, uint cchReturn, int hwndCallback);
15 |
16 | [DllImport(DLL_NAME, EntryPoint = "mciGetErrorString")]
17 | public static extern int mciGetErrorString(int mcierr, StringBuilder pszText, uint cchText);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/NotifyIcon.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using JxCode.Windows.Native;
5 |
6 | namespace JxCode.Windows
7 | {
8 | public class NotifyIcon
9 | {
10 | private bool isEnable = false;
11 | private readonly IntPtr icon;
12 | private Shell32.NotifyIconData nid;
13 | private string text = string.Empty;
14 | public string Text
15 | {
16 | get => text;
17 | set
18 | {
19 | text = value;
20 | nid.szTip = ToCharArray(value);
21 | if (isEnable)
22 | {
23 | Shell32.Shell_NotifyIconW(Shell32.NIM_NotityMessage.NIM_MODIFY, nid);
24 | }
25 | }
26 | }
27 | public NotifyIcon(string iconPath, IntPtr hWnd)
28 | {
29 | icon = Shell32.ExtractIcon(0, iconPath, 0);
30 | int structSize = 0;
31 | if (Environment.Is64BitOperatingSystem)
32 | structSize = 160;
33 | else
34 | structSize = 152;
35 | nid = new Shell32.NotifyIconData()
36 | {
37 | cbSize = structSize,
38 | hIcon = icon,
39 | hWnd = hWnd,
40 | szTip = ToCharArray(Text),
41 | uFlags = Shell32.NIF_NotifyFlag.NIF_ICON
42 | | Shell32.NIF_NotifyFlag.NIF_TIP
43 | | Shell32.NIF_NotifyFlag.NIF_MESSAGE,
44 | uCallbackMessage = (uint)User32.WM_WindowsMessage.WM_PASTE ,
45 | };
46 | }
47 |
48 | public void Enable()
49 | {
50 | Shell32.Shell_NotifyIconW(Shell32.NIM_NotityMessage.NIM_ADD, this.nid);
51 | isEnable = true;
52 | }
53 | public void Disable()
54 | {
55 | Shell32.Shell_NotifyIconW(Shell32.NIM_NotityMessage.NIM_DELETE, this.nid);
56 | isEnable = false;
57 | }
58 | //定长字符数组
59 | private char[] ToCharArray(string str)
60 | {
61 | //固定64长度,64个字符,总共128字节长度
62 | int length = 64;
63 | int strLen = str.Length;
64 | if (strLen == length)
65 | return str.ToCharArray();
66 | else if (strLen > length)
67 | {
68 | //过长裁剪
69 | return str.ToCharArray(0, length);
70 | }
71 | else
72 | {
73 | //填充已有,剩下的char默认就是\0
74 | char[] chars = new char[length];
75 | for (int i = 0; i < chars.Length; i++)
76 | {
77 | if (i < str.Length)
78 | {
79 | chars[i] = str[i];
80 | }
81 | }
82 | return chars;
83 | }
84 |
85 | }
86 | }
87 |
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/ProcessHandle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.IO;
5 | using System.Text;
6 |
7 | namespace JxCode.Windows
8 | {
9 | public class ProcessHandle : IDisposable
10 | {
11 | private readonly Process process;
12 | public Process Process { get => this.process; }
13 |
14 | public event Action Exited;
15 | public event Action Output;
16 | public event Action Error;
17 |
18 | public string ProgramPath { get; }
19 | public string WorkDirectory { get; }
20 | public string Argument { get; }
21 |
22 | public ProcessHandle(string path, string workDir = null, string arg = null, ProcessWindowStyle style = ProcessWindowStyle.Normal)
23 | {
24 | if (string.IsNullOrEmpty(path) || !File.Exists(path))
25 | {
26 | throw new ArgumentException();
27 | }
28 | if (workDir == null)
29 | {
30 | workDir = Path.GetDirectoryName(path);
31 | }
32 |
33 | this.ProgramPath = path;
34 | this.WorkDirectory = workDir;
35 | this.Argument = arg;
36 |
37 | ProcessStartInfo info = new ProcessStartInfo(path, arg)
38 | {
39 | WorkingDirectory = workDir,
40 | UseShellExecute = false,
41 | //RedirectStandardInput = true,
42 | RedirectStandardOutput = true,
43 | RedirectStandardError = true,
44 | WindowStyle = style,
45 | };
46 | Process process = new Process()
47 | {
48 | StartInfo = info,
49 | };
50 | process.OutputDataReceived += (s, e) =>
51 | {
52 | if (e.Data == null)
53 | {
54 | //程序结束
55 | this.process.CancelErrorRead();
56 | this.process.CancelOutputRead();
57 | this.Exited?.Invoke(this);
58 | }
59 | else
60 | {
61 | this.Output?.Invoke(e.Data);
62 | }
63 | };
64 | process.ErrorDataReceived += (s, e) =>
65 | {
66 | if (e.Data != null)
67 | {
68 | this.Error?.Invoke(e.Data);
69 | }
70 | };
71 | this.process = process;
72 | }
73 |
74 | public void Start()
75 | {
76 | this.process.Start();
77 | this.process.BeginOutputReadLine();
78 | this.process.BeginErrorReadLine();
79 | }
80 | public int StartWaitExit()
81 | {
82 | this.process.Start();
83 | this.process.BeginOutputReadLine();
84 | this.process.BeginErrorReadLine();
85 | this.process.WaitForExit();
86 | return this.process.ExitCode;
87 | }
88 | public void Shutdown()
89 | {
90 | if (!this.process.HasExited)
91 | this.process.Kill();
92 | }
93 | public void Dispose()
94 | {
95 | this.process?.Dispose();
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/RegeditConfiguration.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Win32;
2 | using System.Reflection;
3 |
4 | namespace JxCode.Windows
5 | {
6 | public static class RegeditConfiguration
7 | {
8 | public static string GetSetting(string key, string appName = null)
9 | {
10 | appName = appName ?? Assembly.GetExecutingAssembly().FullName;
11 |
12 | RegistryKey HKCU = Registry.CurrentUser.OpenSubKey("Software");
13 | RegistryKey cfg = HKCU.OpenSubKey(appName);
14 | if (cfg == null) return null;
15 | return (string)cfg.GetValue(key);
16 | }
17 | public static void SetSetting(string key, string value, string appName = null)
18 | {
19 | appName = appName ?? Assembly.GetExecutingAssembly().FullName;
20 | RegistryKey HKCU = Registry.CurrentUser.OpenSubKey("Software", true);
21 | RegistryKey cfg = HKCU.OpenSubKey(appName, true);
22 | if (cfg == null)
23 | {
24 | cfg = HKCU.CreateSubKey(appName);
25 | }
26 | cfg.SetValue(key, value);
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/Shared.JxCode.Windows.projitems:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 | true
6 | 12ce725d-57fc-4bd3-b1d5-6c749211dc23
7 |
8 |
9 | JxCode.Windows
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/Shared.JxCode.Windows.shproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 12ce725d-57fc-4bd3-b1d5-6c749211dc23
5 | 14.0
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/SoftUtility/JavaInfo.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Win32;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Linq;
6 | using System.Text;
7 |
8 | namespace JxCode.Windows.SoftUtility
9 | {
10 | public class JavaInfo
11 | {
12 | public string JavaHome { get; private set; }
13 | public bool Is64Bit { get; private set; }
14 | public int MainVersion { get; private set; }
15 | public string FullVersion { get; private set; }
16 |
17 | public string JavaExe
18 | {
19 | get => this.JavaHome + "\\bin\\java.exe";
20 | }
21 | public string JavawExe
22 | {
23 | get => this.JavaHome + "\\bin\\javaw.exe";
24 | }
25 |
26 | public JavaInfo()
27 | {
28 |
29 | }
30 | public JavaInfo(string javaHome, bool is64Bit, int mainVersion, string fullVersion)
31 | {
32 | this.JavaHome = javaHome;
33 | this.Is64Bit = is64Bit;
34 | this.MainVersion = mainVersion;
35 | this.FullVersion = fullVersion;
36 | }
37 |
38 | public override string ToString()
39 | {
40 | return "JavaHome: " + this.JavaHome + " is64Bit: " + this.Is64Bit.ToString();
41 | }
42 |
43 | public static int GetMainVersion(string fullVersion)
44 | {
45 | string[] versionSubArray = fullVersion.Split('.');
46 | if (versionSubArray.Length < 2)
47 | {
48 | return 0;
49 | }
50 |
51 | int mainVersion = 0;
52 | int.TryParse(versionSubArray[1], out mainVersion);
53 |
54 | return mainVersion;
55 | }
56 |
57 | ///
58 | /// 获取该计算机中的所有Java信息
59 | ///
60 | ///
61 | public static IList FindJava()
62 | {
63 | RegistryKey registry;
64 | registry = Registry.LocalMachine.OpenSubKey("SOFTWARE");
65 |
66 | //return
67 | IList javaInfos = new List();
68 |
69 | bool is64Bit = Environment.Is64BitOperatingSystem;
70 |
71 | label_r64bit: //在64系统下重新处理32位java
72 |
73 | RegistryKey registryKey = registry.OpenSubKey("JavaSoft");
74 | registryKey = registryKey?.OpenSubKey("Java Runtime Environment");
75 | if (registryKey == null)
76 | {
77 | return javaInfos;
78 | }
79 |
80 | string[] javaVers = registryKey.GetSubKeyNames();
81 | for (int i = 0; i < javaVers.Length; i++)
82 | {
83 | string fullVersionName = javaVers[i];
84 | RegistryKey javaInfoKey = registryKey.OpenSubKey(fullVersionName);
85 |
86 | int mainVersion = GetMainVersion(javaVers[i]);
87 |
88 | JavaInfo info = new JavaInfo(
89 | (string)javaInfoKey.GetValue("JavaHome"),
90 | is64Bit,
91 | mainVersion,
92 | fullVersionName);
93 |
94 | javaInfos.Add(info);
95 |
96 | }
97 |
98 | if (is64Bit)
99 | {
100 | //如果是64位系统,打开32注册表跳转回去继续处理
101 | is64Bit = false;
102 | registry = registry.OpenSubKey("Wow6432Node");
103 | goto label_r64bit;
104 | }
105 |
106 | return javaInfos;
107 | }
108 |
109 | ///
110 | /// 从Java执行程序或目录中获取Java信息
111 | ///
112 | ///
113 | ///
114 | public static JavaInfo GetJavaInfo(string path)
115 | {
116 | bool isFile = false;
117 | bool isDir = false;
118 | if (File.Exists(path))
119 | {
120 | isFile = true;
121 | }
122 | else if (Directory.Exists(path))
123 | {
124 | isDir = true;
125 | }
126 | if (!isFile && !isDir)
127 | {
128 | return null;
129 | }
130 |
131 | string dirPath = string.Empty;
132 | if (isFile)
133 | {
134 | dirPath = Path.GetDirectoryName(path);
135 | }
136 | DirectoryInfo dirInfo = new DirectoryInfo(dirPath);
137 |
138 | while (dirInfo != null)
139 | {
140 | if (File.Exists(dirInfo.FullName + "\\release"))
141 | {
142 | break;
143 | }
144 | else
145 | {
146 | dirInfo = dirInfo.Parent;
147 | }
148 | }
149 |
150 | if (dirInfo == null)
151 | {
152 | return null;
153 | }
154 |
155 | string[] releaseContent = File.ReadAllLines(dirInfo.FullName + "\\release");
156 |
157 | JavaInfo javaInfo = new JavaInfo();
158 | javaInfo.JavaHome = dirInfo.FullName;
159 |
160 | foreach (var item in releaseContent)
161 | {
162 | string[] items = item.Split('=');
163 | if (items[0] == "JAVA_VERSION")
164 | {
165 | javaInfo.FullVersion = items[1].Replace("\"", "");
166 | javaInfo.MainVersion = GetMainVersion(javaInfo.FullVersion);
167 | }
168 | else if (items[0] == "OS_ARCH")
169 | {
170 | javaInfo.Is64Bit = items[1].Replace("\"", "") == "amd64";
171 | }
172 | }
173 |
174 | return javaInfo;
175 | }
176 |
177 | }
178 |
179 |
180 | }
181 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/TaskbarProgress.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Runtime.InteropServices;
5 |
6 | namespace JxCode.Windows
7 | {
8 | public static class TaskbarProgress
9 | {
10 | public enum TaskbarStates
11 | {
12 | NoProgress = 0,
13 | Indeterminate = 0x1,
14 | Normal = 0x2,
15 | Error = 0x4,
16 | Paused = 0x8
17 | }
18 |
19 | [ComImport()]
20 | [Guid("ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf")]
21 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
22 | private interface ITaskbarList3
23 | {
24 | // ITaskbarList
25 | [PreserveSig]
26 | void HrInit();
27 | [PreserveSig]
28 | void AddTab(IntPtr hwnd);
29 | [PreserveSig]
30 | void DeleteTab(IntPtr hwnd);
31 | [PreserveSig]
32 | void ActivateTab(IntPtr hwnd);
33 | [PreserveSig]
34 | void SetActiveAlt(IntPtr hwnd);
35 |
36 | // ITaskbarList2
37 | [PreserveSig]
38 | void MarkFullscreenWindow(IntPtr hwnd, [MarshalAs(UnmanagedType.Bool)] bool fFullscreen);
39 |
40 | // ITaskbarList3
41 | [PreserveSig]
42 | void SetProgressValue(IntPtr hwnd, UInt64 ullCompleted, UInt64 ullTotal);
43 | [PreserveSig]
44 | void SetProgressState(IntPtr hwnd, TaskbarStates state);
45 | }
46 |
47 | [ComImport()]
48 | [Guid("56fdf344-fd6d-11d0-958a-006097c9a090")]
49 | [ClassInterface(ClassInterfaceType.None)]
50 | private class TaskbarInstance
51 | {
52 | }
53 |
54 | private static ITaskbarList3 taskbarInstance = (ITaskbarList3)new TaskbarInstance();
55 | private static bool taskbarSupported = Environment.OSVersion.Version >= new Version(6, 1);
56 |
57 | public static void SetState(IntPtr windowHandle, TaskbarStates taskbarState)
58 | {
59 | if (taskbarSupported) taskbarInstance.SetProgressState(windowHandle, taskbarState);
60 | }
61 |
62 | public static void SetValue(IntPtr windowHandle, double progressValue, double progressMax)
63 | {
64 | if (taskbarSupported) taskbarInstance.SetProgressValue(windowHandle, (ulong)progressValue, (ulong)progressMax);
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/WindowsForm.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using JxCode.Windows.Native;
5 |
6 | namespace JxCode.Windows
7 | {
8 | public class WindowsForm
9 | {
10 | private IntPtr hWnd;
11 | ///
12 | /// 窗体句柄
13 | ///
14 | public IntPtr HWND
15 | {
16 | get => hWnd;
17 | private set
18 | {
19 | this.hWnd = value;
20 | this.RefreshWindowRect();
21 | }
22 | }
23 | private int topPos = 0;
24 | private User32.Point position;
25 | private User32.Size size;
26 | ///
27 | /// 窗体大小
28 | ///
29 | public User32.Size Size
30 | {
31 | set
32 | {
33 | RefreshWindowRect();
34 | this.size = value;
35 | User32.SetWindowPos(this.hWnd, this.topPos, this.position.x, this.position.y, size.width, size.height, 0);
36 | }
37 | get
38 | {
39 | RefreshWindowRect();
40 | return size;
41 | }
42 | }
43 | ///
44 | /// 窗体位置
45 | ///
46 | public User32.Point Position
47 | {
48 | set
49 | {
50 | RefreshWindowRect();
51 | this.position = value;
52 | User32.SetWindowPos(this.hWnd, this.topPos, value.x, value.y, this.size.width, this.size.height, 0);
53 | }
54 | get
55 | {
56 | RefreshWindowRect();
57 | return this.position;
58 | }
59 | }
60 | ///
61 | /// 窗体父对象
62 | ///
63 | public IntPtr Parent
64 | {
65 | get => User32.GetParent(this.hWnd);
66 | set => User32.SetParent(this.hWnd, value);
67 | }
68 |
69 | public WindowsForm GetParent()
70 | {
71 | IntPtr ptr = this.Parent;
72 | if(ptr == IntPtr.Zero)
73 | {
74 | return null;
75 | }
76 | return CreateFromHWND(ptr);
77 | }
78 | public void SetParent(WindowsForm windowsForm)
79 | {
80 | this.Parent = windowsForm.hWnd;
81 | }
82 |
83 | ///
84 | /// 窗体标题
85 | ///
86 | public string Title
87 | {
88 | get
89 | {
90 | StringBuilder sb = new StringBuilder(255);
91 | User32.GetWindowText(this.hWnd, sb, 255);
92 |
93 | return sb.ToString();
94 | }
95 | set
96 | {
97 | User32.SetWindowText(this.hWnd, value);
98 | }
99 | }
100 | ///
101 | /// 窗体类名
102 | ///
103 | public string ClassName
104 | {
105 | get
106 | {
107 | StringBuilder sb = new StringBuilder(256);
108 | User32.GetClassName(hWnd, sb, 256);
109 | return sb.ToString();
110 | }
111 | }
112 |
113 | ///
114 | /// 窗体实际大小同步至本类数据
115 | ///
116 | private void RefreshWindowRect()
117 | {
118 | User32.Rect rect = new User32.Rect();
119 | if (User32.GetWindowRect(this.hWnd, ref rect))
120 | {
121 | this.size = new User32.Size(rect.Right - rect.Left, rect.Bottom - rect.Top);
122 | this.position = new User32.Point(rect.Left, rect.Top);
123 | }
124 |
125 | }
126 | ///
127 | /// 设置窗体图标
128 | ///
129 | ///
130 | public void SetIcon(string icon)
131 | {
132 | IntPtr result = Shell32.ExtractIcon(0, icon, 0);
133 | if (result != IntPtr.Zero)
134 | User32.SendMessage(this.hWnd, 0x80, IntPtr.Zero, result);
135 | }
136 | ///
137 | /// 关闭窗体
138 | ///
139 | public void CloseWindow()
140 | {
141 | User32.CloseWindow(this.hWnd);
142 | }
143 | ///
144 | /// 设置窗体置顶
145 | ///
146 | ///
147 | public void SetTop(bool isTop)
148 | {
149 | RefreshWindowRect();
150 | this.topPos = isTop ? -1 : -2;
151 | User32.SetWindowPos(
152 | this.hWnd,
153 | this.topPos,
154 | this.position.x,
155 | this.position.y,
156 | this.size.width,
157 | this.size.height,
158 | 0
159 | );
160 | }
161 |
162 | public IntPtr[] GetChildWindows()
163 | {
164 | List list = new List();
165 | User32.EnumChildWindows(this.hWnd,
166 | (hwnd, lparam) =>
167 | {
168 | list.Add(hwnd);
169 | return true;
170 | }, 0);
171 |
172 | return list.ToArray();
173 | }
174 |
175 | public WindowsForm[] GetChildWindowsForms()
176 | {
177 | IntPtr[] intptr = this.GetChildWindows();
178 | WindowsForm[] forms = new WindowsForm[intptr.Length];
179 | for (int i = 0; i < intptr.Length; i++)
180 | {
181 | forms[i] = CreateFromHWND(intptr[i]);
182 | }
183 | return forms;
184 | }
185 |
186 | ///
187 | /// 窗体是否存在
188 | ///
189 | ///
190 | ///
191 | public static bool Exist(IntPtr hWnd)
192 | {
193 | return User32.IsWindow(hWnd);
194 | }
195 | ///
196 | /// 最大化
197 | ///
198 | public void Maximize()
199 | {
200 | User32.SendMessage(this.hWnd, User32.WM_WindowsMessage.WM_SYSCOMMAND, User32.SC_SysCommand.SC_MAXIMIZE);
201 | }
202 | ///
203 | /// 最小化
204 | ///
205 | public void Minimize()
206 | {
207 | User32.SendMessage(this.hWnd, User32.WM_WindowsMessage.WM_SYSCOMMAND, User32.SC_SysCommand.SC_MINIMIZE);
208 | }
209 | ///
210 | /// 还原
211 | ///
212 | public void Restore()
213 | {
214 | User32.SendMessage(this.hWnd, User32.WM_WindowsMessage.WM_SYSCOMMAND, User32.SC_SysCommand.SC_RESTORE);
215 | }
216 | ///
217 | /// 发送粘贴
218 | ///
219 | public void Paste()
220 | {
221 | User32.SendMessage(this.hWnd, User32.WM_WindowsMessage.WM_PASTE, 0, 0);
222 | }
223 | ///
224 | /// 设置焦点
225 | ///
226 | public void SetFocus()
227 | {
228 | User32.SetForegroundWindow(this.hWnd);
229 | }
230 |
231 | public override bool Equals(object obj)
232 | {
233 | WindowsForm form = obj as WindowsForm;
234 | return form != null && this.hWnd == form.hWnd;
235 | }
236 |
237 |
238 | ///
239 | /// 从句柄创建
240 | ///
241 | /// 窗口句柄
242 | protected WindowsForm(IntPtr hWnd)
243 | {
244 | this.HWND = hWnd;
245 | }
246 |
247 | public enum BorderStyle
248 | {
249 | None,
250 | Sizable,
251 | }
252 | public bool SetBorderStyle(BorderStyle style)
253 | {
254 |
255 | var oldLong = (User32.WS_WindowStyle)User32.GetWindowLong(this.hWnd, User32.GWL_WindowsLongMessage.GWL_STYLE);
256 | var newLong = oldLong;
257 | if (oldLong.HasFlag(User32.WS_WindowStyle.WS_CAPTION))
258 | {
259 | //newLong = oldLong & ~User32.WS_WindowStyle.WS_CAPTION;
260 | newLong = oldLong & ~User32.WS_WindowStyle.WS_OVERLAPPEDWINDOW;
261 | }
262 |
263 | //newLong = newLong & ~(uint)(User32.WSEX_ExtendedWindowStyle.WS_EX_WINDOWEDGE
264 | // | User32.WSEX_ExtendedWindowStyle.WS_EX_DLGMODALFRAME);
265 |
266 | User32.SetWindowLong(this.hWnd, User32.GWL_WindowsLongMessage.GWL_STYLE, newLong);
267 | if(((User32.WS_WindowStyle)User32.GetWindowLong(this.hWnd, User32.GWL_WindowsLongMessage.GWL_STYLE)).HasFlag(User32.WS_WindowStyle.WS_CAPTION))
268 | {
269 | return false;
270 | }
271 | return true;
272 | //return User32.SetWindowLong(this.hWnd, User32.GWL_WindowsLongMessage.GWL_STYLE, newLong) != IntPtr.Zero;
273 | }
274 |
275 | public IntPtr SetWindowLong(User32.GWL_WindowsLongMessage msg, uint dw)
276 | {
277 | return User32.SetWindowLong(this.HWND, msg, dw);
278 | }
279 | public void SetWindowStyle(uint style)
280 | {
281 | User32.SetWindowLong(this.hWnd, User32.GWL_WindowsLongMessage.GWL_STYLE, style);
282 | }
283 | public IntPtr GetWindowLong(int nIndex)
284 | {
285 | return User32.GetWindowLong(this.hWnd, nIndex);
286 | }
287 |
288 | public uint GetWindowStyle()
289 | {
290 | return (uint)User32.GetWindowLong(this.hWnd, User32.GWL_WindowsLongMessage.GWL_STYLE);
291 | }
292 |
293 | public void Active()
294 | {
295 | User32.SendMessage(this.hWnd, User32.WM_WindowsMessage.WM_ACTIVATE, (IntPtr)User32.WA_WindowsActiveMessage.WA_ACTIVE, IntPtr.Zero);
296 | }
297 | public void Inactive()
298 | {
299 | User32.SendMessage(this.hWnd, User32.WM_WindowsMessage.WM_ACTIVATE, (IntPtr)User32.WA_WindowsActiveMessage.WA_INACTIVE, IntPtr.Zero);
300 | }
301 |
302 | #region Factory
303 | ///
304 | /// 从句柄创建
305 | ///
306 | ///
307 | ///
308 | public static WindowsForm CreateFromHWND(IntPtr hWnd)
309 | {
310 | if(hWnd == IntPtr.Zero)
311 | {
312 | return null;
313 | }
314 | return new WindowsForm(hWnd);
315 | }
316 | ///
317 | /// 从标题创建
318 | ///
319 | ///
320 | ///
321 | public static WindowsForm CreateFromTitle(string title)
322 | {
323 | IntPtr result = User32.FindWindow(null, title);
324 | if (result == IntPtr.Zero)
325 | {
326 | return null;
327 | }
328 | return new WindowsForm(result);
329 | }
330 | ///
331 | /// 从位置创建
332 | ///
333 | ///
334 | ///
335 | public static WindowsForm CreateFromPosition(User32.Point position)
336 | {
337 | IntPtr ptr = User32.WindowFromPoint(position);
338 | if (ptr == IntPtr.Zero)
339 | {
340 | return null;
341 | }
342 | return new WindowsForm(ptr);
343 | }
344 | ///
345 | /// 从鼠标位置创建
346 | ///
347 | ///
348 | public static WindowsForm CreateFromCursorPosition()
349 | {
350 | var pos = MouseUtil.GetMousePosition();
351 | IntPtr ptr = User32.WindowFromPoint(pos);
352 | if(ptr == IntPtr.Zero)
353 | {
354 | return null;
355 | }
356 | return new WindowsForm(ptr);
357 | }
358 | ///
359 | /// 从PID创建
360 | ///
361 | ///
362 | ///
363 | public static WindowsForm CreateFromPID(IntPtr pid)
364 | {
365 | IntPtr hWnd = IntPtr.Zero;
366 | //阻塞函数
367 | User32.EnumWindows((hwnd, lParam) =>
368 | {
369 | IntPtr _pid = IntPtr.Zero;
370 | User32.GetWindowThreadProcessId(hwnd, ref _pid);
371 | //判断当前窗口是否属于本进程
372 | if (_pid == lParam)
373 | {
374 | hWnd = hwnd;
375 | return false;
376 | }
377 | //继续循环
378 | return true;
379 | }, pid);
380 |
381 | if(hWnd == IntPtr.Zero)
382 | {
383 | return null;
384 | }
385 |
386 | return new WindowsForm(hWnd);
387 | }
388 | ///
389 | /// 从当前程序的窗体创建
390 | ///
391 | ///
392 | public static WindowsForm CreateFromCurrentPid()
393 | {
394 | IntPtr PID = new IntPtr(System.Diagnostics.Process.GetCurrentProcess().Id);
395 | return CreateFromPID(PID);
396 | }
397 | ///
398 | /// 从调用线程的活动窗口创建
399 | ///
400 | ///
401 | public static WindowsForm CreateFromCurThreadActiveWindow()
402 | {
403 | return new WindowsForm(User32.GetActiveWindow());
404 | }
405 | #endregion
406 | public override int GetHashCode()
407 | {
408 | int hashCode = -1877228240;
409 | hashCode = hashCode * -1521134295 + this.hWnd.GetHashCode();
410 | hashCode = hashCode * -1521134295 + this.HWND.GetHashCode();
411 | hashCode = hashCode * -1521134295 + this.topPos.GetHashCode();
412 | hashCode = hashCode * -1521134295 + this.position.GetHashCode();
413 | hashCode = hashCode * -1521134295 + this.size.GetHashCode();
414 | hashCode = hashCode * -1521134295 + this.Size.GetHashCode();
415 | hashCode = hashCode * -1521134295 + this.Position.GetHashCode();
416 | hashCode = hashCode * -1521134295 + this.Parent.GetHashCode();
417 | hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(this.Title);
418 | hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(this.ClassName);
419 | return hashCode;
420 | }
421 |
422 | public override string ToString()
423 | {
424 | return this.hWnd.ToString();
425 | }
426 |
427 | public static implicit operator IntPtr(WindowsForm form)
428 | {
429 | return form.HWND;
430 | }
431 | public static implicit operator WindowsForm(IntPtr ptr)
432 | {
433 | return WindowsForm.CreateFromHWND(ptr);
434 | }
435 | }
436 | }
437 |
--------------------------------------------------------------------------------
/Shared.JxCode.Windows/WinformMessageProc.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using JxCode.Windows.Native;
4 | using System.Runtime.InteropServices;
5 |
6 | using WindowsLongMessage = JxCode.Windows.Native.User32.GWL_WindowsLongMessage;
7 | using WindowsMessage = JxCode.Windows.Native.User32.WM_WindowsMessage;
8 | using WindowsActiveMessage = JxCode.Windows.Native.User32.WA_WindowsActiveMessage;
9 |
10 | namespace JxCode.Windows
11 | {
12 | public interface IWinformMessageProc
13 | {
14 | ///
15 | /// 窗口收到关闭消息,返回一个值来确定是否关闭
16 | ///
17 | /// true为不关闭,false为关闭
18 | bool OnClose();
19 | ///
20 | /// 窗口收到激活
21 | ///
22 | void OnActive();
23 | ///
24 | /// 窗口失去激活
25 | ///
26 | void OnInactive();
27 | }
28 | public class WinformMessageProc : IDisposable
29 | {
30 | protected IntPtr hWnd;
31 | protected IntPtr msgcb_src;
32 | protected IWinformMessageProc proc;
33 |
34 | public WinformMessageProc(IntPtr hWnd, IWinformMessageProc proc)
35 | {
36 | this.proc = proc;
37 | this.msgcb_src = User32.GetWindowLong(hWnd, WindowsLongMessage.GWL_WNDPROC);
38 | this.hWnd = User32.SetWindowLong(hWnd, WindowsLongMessage.GWL_WNDPROC, WndProc);
39 | }
40 |
41 | protected virtual IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam)
42 | {
43 | switch (msg)
44 | {
45 | case (int)WindowsMessage.WM_ACTIVATE:
46 | switch ((uint)wParam)
47 | {
48 | case (uint)WindowsActiveMessage.WA_INACTIVE:
49 | this.proc.OnInactive();
50 | break;
51 | case (uint)WindowsActiveMessage.WA_ACTIVE:
52 | case (uint)WindowsActiveMessage.WA_CLICKACTIVE:
53 | this.proc.OnActive();
54 | break;
55 | }
56 | break;
57 | case (int)WindowsMessage.WM_CLOSE:
58 | if (!this.proc.OnClose())
59 | {
60 | return (IntPtr)0;
61 | }
62 | break;
63 | default:
64 | break;
65 | }
66 | return User32.CallWindowProc(this.hWnd, hWnd, msg, wParam, lParam);
67 | }
68 |
69 | protected bool isDispose = false;
70 | public virtual void Dispose()
71 | {
72 | if (this.isDispose)
73 | {
74 | return;
75 | }
76 | var ptr = Marshal.GetDelegateForFunctionPointer(this.msgcb_src, typeof(User32.WindowLongCallBack)) as User32.WindowLongCallBack;
77 | User32.SetWindowLong(this.hWnd, WindowsLongMessage.GWL_WNDPROC, ptr);
78 | this.isDispose = true;
79 | GC.SuppressFinalize(this);
80 | }
81 |
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/Test/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | using JxCode.Windows;
7 |
8 | namespace Test
9 | {
10 | class Program
11 | {
12 | static void Main(string[] args)
13 | {
14 |
15 | }
16 |
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Test/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的一般信息由以下
6 | // 控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("Test")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Test")]
13 | [assembly: AssemblyCopyright("Copyright © 2020")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 会使此程序集中的类型
18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
19 | //请将此类型的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("b41b8f6e-844f-4347-9ee2-0f202fbeabaf")]
24 |
25 | // 程序集的版本信息由下列四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
33 | //通过使用 "*",如下所示:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Test/Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {B41B8F6E-844F-4347-9EE2-0F202FBEABAF}
8 | Exe
9 | Test
10 | Test
11 | v4.0
12 | 512
13 | true
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------