diff --git a/TestEngine/App.config b/TestEngine/App.config index 4bba09a..49ac713 100644 --- a/TestEngine/App.config +++ b/TestEngine/App.config @@ -3,4 +3,9 @@ + + + + + \ No newline at end of file diff --git a/TestEngine/Form2.Designer.cs b/TestEngine/Form2.Designer.cs new file mode 100644 index 0000000..d10db95 --- /dev/null +++ b/TestEngine/Form2.Designer.cs @@ -0,0 +1,93 @@ +namespace TestEngine +{ + partial class Form2 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.sans = new System.Windows.Forms.PictureBox(); + this.heart = new System.Windows.Forms.PictureBox(); + this.label1 = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.sans)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.heart)).BeginInit(); + this.SuspendLayout(); + // + // sans + // + this.sans.Location = new System.Drawing.Point(118, 12); + this.sans.Name = "sans"; + this.sans.Size = new System.Drawing.Size(324, 259); + this.sans.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; + this.sans.TabIndex = 0; + this.sans.TabStop = false; + // + // heart + // + this.heart.Location = new System.Drawing.Point(229, 277); + this.heart.Name = "heart"; + this.heart.Size = new System.Drawing.Size(23, 24); + this.heart.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; + this.heart.TabIndex = 1; + this.heart.TabStop = false; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.ForeColor = System.Drawing.Color.Red; + this.label1.Location = new System.Drawing.Point(457, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(59, 22); + this.label1.TabIndex = 2; + this.label1.Text = "label1"; + // + // Form2 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 22F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.SystemColors.ActiveCaptionText; + this.ClientSize = new System.Drawing.Size(528, 313); + this.Controls.Add(this.label1); + this.Controls.Add(this.heart); + this.Controls.Add(this.sans); + this.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.Name = "Form2"; + this.Text = "Form2"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form2_FormClosing); + ((System.ComponentModel.ISupportInitialize)(this.sans)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.heart)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.PictureBox sans; + private System.Windows.Forms.PictureBox heart; + private System.Windows.Forms.Label label1; + } +} \ No newline at end of file diff --git a/TestEngine/Form2.cs b/TestEngine/Form2.cs new file mode 100644 index 0000000..addc52f --- /dev/null +++ b/TestEngine/Form2.cs @@ -0,0 +1,35 @@ +using System; +using TheWorstEngine; +using System.Windows.Forms; + +namespace TestEngine +{ + public partial class Form2 : Form + { + Twe sans1 = new Twe(); + Twe Heart = new Twe(); + public Form2() + { + InitializeComponent(); + sans1.form = this; + sans1.picturebox = sans; + string[] FS = { ".\\img\\sans1.png", ".\\img\\sans2.png", + ".\\img\\sans3.png", ".\\img\\sans4.png", + ".\\img\\sans3.png", ".\\img\\sans2.png", ".\\img\\sans1.png"}; + sans1.NewAnim(FS, 5, label1); + Heart.form = this; + Heart.picturebox = heart; + Heart.NewImage(@".\img\red.png"); + // Heart.KeySet(Keys.Up, Keys.Down, Keys.Left, Keys.Right); + Heart.CanMove(true); + + // sans1.KeySet(Keys.Up, Keys.Down, Keys.Left, Keys.Right); + // sans1.CanMove(true); + } + + private void Form2_FormClosing(object sender, FormClosingEventArgs e) + { + sans1.isClosed = true; + } + } +} diff --git a/TestEngine/Form2.resx b/TestEngine/Form2.resx new file mode 100644 index 0000000..29dcb1b --- /dev/null +++ b/TestEngine/Form2.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TestEngine/Main.Designer.cs b/TestEngine/Main.Designer.cs index d75e07e..1fb2358 100644 --- a/TestEngine/Main.Designer.cs +++ b/TestEngine/Main.Designer.cs @@ -30,15 +30,19 @@ private void InitializeComponent() { this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.FPS = new System.Windows.Forms.Label(); + this.pictureBox2 = new System.Windows.Forms.PictureBox(); + this.FPS2 = new System.Windows.Forms.Label(); + this.button1 = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit(); this.SuspendLayout(); // // pictureBox1 // - this.pictureBox1.BackColor = System.Drawing.SystemColors.AppWorkspace; + this.pictureBox1.BackColor = System.Drawing.SystemColors.ActiveCaptionText; this.pictureBox1.Location = new System.Drawing.Point(12, 12); this.pictureBox1.Name = "pictureBox1"; - this.pictureBox1.Size = new System.Drawing.Size(504, 289); + this.pictureBox1.Size = new System.Drawing.Size(187, 289); this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; this.pictureBox1.TabIndex = 0; this.pictureBox1.TabStop = false; @@ -47,25 +51,62 @@ private void InitializeComponent() // this.FPS.AutoSize = true; this.FPS.Font = new System.Drawing.Font("微软雅黑", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.FPS.Location = new System.Drawing.Point(218, 12); + this.FPS.Location = new System.Drawing.Point(102, 12); this.FPS.Name = "FPS"; this.FPS.Size = new System.Drawing.Size(96, 28); this.FPS.TabIndex = 1; this.FPS.Text = "FPS:114"; // + // pictureBox2 + // + this.pictureBox2.BackColor = System.Drawing.SystemColors.ActiveCaptionText; + this.pictureBox2.Location = new System.Drawing.Point(330, 12); + this.pictureBox2.Name = "pictureBox2"; + this.pictureBox2.Size = new System.Drawing.Size(186, 289); + this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; + this.pictureBox2.TabIndex = 2; + this.pictureBox2.TabStop = false; + // + // FPS2 + // + this.FPS2.AutoSize = true; + this.FPS2.Font = new System.Drawing.Font("微软雅黑", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.FPS2.Location = new System.Drawing.Point(420, 12); + this.FPS2.Name = "FPS2"; + this.FPS2.Size = new System.Drawing.Size(96, 28); + this.FPS2.TabIndex = 3; + this.FPS2.Text = "FPS:114"; + // + // button1 + // + this.button1.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.button1.ForeColor = System.Drawing.Color.Teal; + this.button1.Location = new System.Drawing.Point(205, 126); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(119, 45); + this.button1.TabIndex = 4; + this.button1.Text = "MoveTest"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // // Main // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.BackColor = System.Drawing.SystemColors.AppWorkspace; + this.BackColor = System.Drawing.SystemColors.ActiveCaptionText; this.ClientSize = new System.Drawing.Size(528, 313); + this.Controls.Add(this.button1); + this.Controls.Add(this.FPS2); this.Controls.Add(this.FPS); this.Controls.Add(this.pictureBox1); + this.Controls.Add(this.pictureBox2); + this.ForeColor = System.Drawing.SystemColors.ActiveCaption; this.Name = "Main"; this.Text = "Main"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Main_FormClosing); this.SizeChanged += new System.EventHandler(this.Main_SizeChanged); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -75,5 +116,8 @@ private void InitializeComponent() private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.Label FPS; + private System.Windows.Forms.PictureBox pictureBox2; + private System.Windows.Forms.Label FPS2; + private System.Windows.Forms.Button button1; } } \ No newline at end of file diff --git a/TestEngine/Main.cs b/TestEngine/Main.cs index 76843ae..3c35d2f 100644 --- a/TestEngine/Main.cs +++ b/TestEngine/Main.cs @@ -1,42 +1,49 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; using System.Windows.Forms; using TheWorstEngine; using LogSystem; +using LangSystem; namespace TestEngine { public partial class Main : Form { - Twe twe = new Twe(); + Twe sans1 = new Twe(); + Twe sans2 = new Twe(); Log log = new Log(); - + Lang lang = new Lang(); public Main() { InitializeComponent(); CheckForIllegalCrossThreadCalls = false; //Thread RunTask = new Thread(Run); //RunTask.Start(); - twe.form = this; - twe.picturebox = pictureBox1; + sans2.form = this; + sans2.picturebox = pictureBox2; + sans1.form = this; + sans1.picturebox = pictureBox1; log.LogWriteInit(); log.TimeShowSet(true); - log.Info(twe.SetResolution(new Size(800, 600))); - // log.Info(twe.NewImage(@".\wt.gif")); + log.Info(sans1.SetResolution(new Size(544, 351))); + // log.Info(sans1.NewImage(@".\wt.gif")); - string[] FS = { ".\\img\\sans1.png", ".\\img\\sans2.png", ".\\img\\sans3.png", ".\\img\\sans4.png" }; + string[] FS = { ".\\img\\sans1.png", ".\\img\\sans2.png", + ".\\img\\sans3.png", ".\\img\\sans4.png", + ".\\img\\sans3.png", ".\\img\\sans2.png", ".\\img\\sans1.png"}; // pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize; - twe.NewAnim(FS, 114, FPS); + sans1.NewAnim(FS, 5, FPS); + sans2.NewAnim(FS, 5, FPS2); } - + public void LangInit() + { + string[] LangType = { "简体中文", "English" }; + lang.Init(); + lang.SetLangType(LangType); + lang.ChangeCreateLangType(0); + lang.CreateLangStr("Null", "null"); + } /// /// 负责游戏刷新的函数,可重写 /// @@ -48,12 +55,19 @@ public Main() private void Main_SizeChanged(object sender, EventArgs e) { - pictureBox1.Size = new Size(Width - 40, Height - 62); + // pictureBox1.Size = new Size(Width - 40, Height - 62); } private void Main_FormClosing(object sender, FormClosingEventArgs e) { - twe.isClosed = true; + sans1.isClosed = true; + sans2.isClosed = true; + } + + private void button1_Click(object sender, EventArgs e) + { + Form2 f2 = new Form2(); + f2.Show(); } } } diff --git a/TestEngine/TestEngine.csproj b/TestEngine/TestEngine.csproj index d99f813..ac3ce39 100644 --- a/TestEngine/TestEngine.csproj +++ b/TestEngine/TestEngine.csproj @@ -57,6 +57,12 @@ + + Form + + + Form2.cs + Form @@ -70,6 +76,9 @@ + + Form2.cs + Main.cs diff --git a/TestEngine/bin/Debug/TestEngine.exe b/TestEngine/bin/Debug/TestEngine.exe index 799f627..5262c1c 100644 Binary files a/TestEngine/bin/Debug/TestEngine.exe and b/TestEngine/bin/Debug/TestEngine.exe differ diff --git a/TestEngine/bin/Debug/TestEngine.exe.config b/TestEngine/bin/Debug/TestEngine.exe.config index 4bba09a..49ac713 100644 --- a/TestEngine/bin/Debug/TestEngine.exe.config +++ b/TestEngine/bin/Debug/TestEngine.exe.config @@ -3,4 +3,9 @@ + + + + + \ No newline at end of file diff --git a/TestEngine/bin/Debug/lib/LangSystem.dll b/TestEngine/bin/Debug/lib/LangSystem.dll new file mode 100644 index 0000000..4da355f Binary files /dev/null and b/TestEngine/bin/Debug/lib/LangSystem.dll differ diff --git a/TestEngine/bin/Debug/lib/LogSystem.dll b/TestEngine/bin/Debug/lib/LogSystem.dll new file mode 100644 index 0000000..9b42fa2 Binary files /dev/null and b/TestEngine/bin/Debug/lib/LogSystem.dll differ diff --git a/TestEngine/bin/Debug/lib/TheWorstEngine.dll b/TestEngine/bin/Debug/lib/TheWorstEngine.dll new file mode 100644 index 0000000..39ca746 Binary files /dev/null and b/TestEngine/bin/Debug/lib/TheWorstEngine.dll differ diff --git a/TestEngine/obj/Debug/DesignTimeResolveAssemblyReferences.cache b/TestEngine/obj/Debug/DesignTimeResolveAssemblyReferences.cache new file mode 100644 index 0000000..f818dc9 Binary files /dev/null and b/TestEngine/obj/Debug/DesignTimeResolveAssemblyReferences.cache differ diff --git a/TestEngine/obj/Debug/TestEngine.Form2.resources b/TestEngine/obj/Debug/TestEngine.Form2.resources new file mode 100644 index 0000000..6c05a97 Binary files /dev/null and b/TestEngine/obj/Debug/TestEngine.Form2.resources differ diff --git a/TestEngine/obj/Debug/TestEngine.csproj.CoreCompileInputs.cache b/TestEngine/obj/Debug/TestEngine.csproj.CoreCompileInputs.cache index 224d88e..445742d 100644 --- a/TestEngine/obj/Debug/TestEngine.csproj.CoreCompileInputs.cache +++ b/TestEngine/obj/Debug/TestEngine.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -fc78b9347a66495f1213a6b6e05ab8a0f3d951cc +a95bdd1f0bf895d2423ac03c9b118a66e6b5cd33 diff --git a/TestEngine/obj/Debug/TestEngine.csproj.FileListAbsolute.txt b/TestEngine/obj/Debug/TestEngine.csproj.FileListAbsolute.txt index 73df469..2d6ebe5 100644 --- a/TestEngine/obj/Debug/TestEngine.csproj.FileListAbsolute.txt +++ b/TestEngine/obj/Debug/TestEngine.csproj.FileListAbsolute.txt @@ -3,7 +3,6 @@ D:\C#类编程文件\带工程\TWE\TheWorstEngine\TestEngine\bin\Debug\TestEngin D:\C#类编程文件\带工程\TWE\TheWorstEngine\TestEngine\bin\Debug\TestEngine.pdb D:\C#类编程文件\带工程\TWE\TheWorstEngine\TestEngine\bin\Debug\TheWorstEngine.dll D:\C#类编程文件\带工程\TWE\TheWorstEngine\TestEngine\bin\Debug\TheWorstEngine.pdb -D:\C#类编程文件\带工程\TWE\TheWorstEngine\TestEngine\bin\Debug\TheWorstEngine.dll.config D:\C#类编程文件\带工程\TWE\TheWorstEngine\TestEngine\obj\Debug\TestEngine.csprojAssemblyReference.cache D:\C#类编程文件\带工程\TWE\TheWorstEngine\TestEngine\obj\Debug\TestEngine.csproj.CoreCompileInputs.cache D:\C#类编程文件\带工程\TWE\TheWorstEngine\TestEngine\obj\Debug\TestEngine.csproj.CopyComplete @@ -15,3 +14,4 @@ D:\C#类编程文件\带工程\TWE\TheWorstEngine\TestEngine\bin\Debug\LangSyste D:\C#类编程文件\带工程\TWE\TheWorstEngine\TestEngine\bin\Debug\LogSystem.dll D:\C#类编程文件\带工程\TWE\TheWorstEngine\TestEngine\bin\Debug\LangSystem.pdb D:\C#类编程文件\带工程\TWE\TheWorstEngine\TestEngine\bin\Debug\LogSystem.pdb +D:\C#类编程文件\带工程\TWE\TheWorstEngine\TestEngine\obj\Debug\TestEngine.Form2.resources diff --git a/TestEngine/obj/Debug/TestEngine.csproj.GenerateResource.cache b/TestEngine/obj/Debug/TestEngine.csproj.GenerateResource.cache index 51d6e20..ffa5dc2 100644 Binary files a/TestEngine/obj/Debug/TestEngine.csproj.GenerateResource.cache and b/TestEngine/obj/Debug/TestEngine.csproj.GenerateResource.cache differ diff --git a/TestEngine/obj/Debug/TestEngine.csprojAssemblyReference.cache b/TestEngine/obj/Debug/TestEngine.csprojAssemblyReference.cache index eaf8403..c5e343b 100644 Binary files a/TestEngine/obj/Debug/TestEngine.csprojAssemblyReference.cache and b/TestEngine/obj/Debug/TestEngine.csprojAssemblyReference.cache differ diff --git a/TestEngine/obj/Debug/TestEngine.exe b/TestEngine/obj/Debug/TestEngine.exe index 799f627..5262c1c 100644 Binary files a/TestEngine/obj/Debug/TestEngine.exe and b/TestEngine/obj/Debug/TestEngine.exe differ diff --git a/TestEngine/obj/Debug/TestEngine.pdb b/TestEngine/obj/Debug/TestEngine.pdb index dbb3161..0ce77fa 100644 Binary files a/TestEngine/obj/Debug/TestEngine.pdb and b/TestEngine/obj/Debug/TestEngine.pdb differ diff --git a/TheWorstEngine/KeyManager(unused).cs b/TheWorstEngine/KeyManager(unused).cs new file mode 100644 index 0000000..f11fefa --- /dev/null +++ b/TheWorstEngine/KeyManager(unused).cs @@ -0,0 +1,167 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; +using System.Windows.Forms; +using System.Reflection; + +namespace TheWorstEngine +{ + /// + /// 键盘钩子 + /// [以下代码来自某网友,并非本人原创] + /// + class KeyManager + { + public event KeyEventHandler KeyDownEvent; + public event KeyPressEventHandler KeyPressEvent; + public event KeyEventHandler KeyUpEvent; + + public delegate int HookProc(int nCode, Int32 wParam, IntPtr lParam); + static int hKeyboardHook = 0; //声明键盘钩子处理的初始值 + //值在Microsoft SDK的Winuser.h里查询 + public const int WH_KEYBOARD_LL = 13; //线程键盘钩子监听鼠标消息设为2,全局键盘监听鼠标消息设为13 + HookProc KeyboardHookProcedure; //声明KeyboardHookProcedure作为HookProc类型 + //键盘结构 + [StructLayout(LayoutKind.Sequential)] + public class KeyboardHookStruct + { + public int vkCode; //定一个虚拟键码。该代码必须有一个价值的范围1至254 + public int scanCode; // 指定的硬件扫描码的关键 + public int flags; // 键标志 + public int time; // 指定的时间戳记的这个讯息 + public int dwExtraInfo; // 指定额外信息相关的信息 + } + //使用此功能,安装了一个钩子 + [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] + public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId); + + + //调用此函数卸载钩子 + [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] + public static extern bool UnhookWindowsHookEx(int idHook); + + + //使用此功能,通过信息钩子继续下一个钩子 + [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] + public static extern int CallNextHookEx(int idHook, int nCode, Int32 wParam, IntPtr lParam); + + // 取得当前线程编号(线程钩子需要用到) + [DllImport("kernel32.dll")] + static extern int GetCurrentThreadId(); + + //使用WINDOWS API函数代替获取当前实例的函数,防止钩子失效 + [DllImport("kernel32.dll")] + public static extern IntPtr GetModuleHandle(string name); + + public void Start() + { + // 安装键盘钩子 + if (hKeyboardHook == 0) + { + KeyboardHookProcedure = new HookProc(KeyboardHookProc); + hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProcedure, GetModuleHandle(System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleName), 0); + //hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProcedure, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]), 0); + //************************************ + //键盘线程钩子 + //SetWindowsHookEx( 2,KeyboardHookProcedure, IntPtr.Zero, GetCurrentThreadId());//指定要监听的线程idGetCurrentThreadId(), + //键盘全局钩子,需要引用空间(using System.Reflection;) + //SetWindowsHookEx( 13,MouseHookProcedure,Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]),0); + // + //关于SetWindowsHookEx (int idHook, HookProc lpfn, IntPtr hInstance, int threadId)函数将钩子加入到钩子链表中,说明一下四个参数: + //idHook 钩子类型,即确定钩子监听何种消息,上面的代码中设为2,即监听键盘消息并且是线程钩子,如果是全局钩子监听键盘消息应设为13, + //线程钩子监听鼠标消息设为7,全局钩子监听鼠标消息设为14。lpfn 钩子子程的地址指针。如果dwThreadId参数为0 或是一个由别的进程创建的 + //线程的标识,lpfn必须指向DLL中的钩子子程。 除此以外,lpfn可以指向当前进程的一段钩子子程代码。钩子函数的入口地址,当钩子钩到任何 + //消息后便调用这个函数。hInstance应用程序实例的句柄。标识包含lpfn所指的子程的DLL。如果threadId 标识当前进程创建的一个线程,而且子 + //程代码位于当前进程,hInstance必须为NULL。可以很简单的设定其为本应用程序的实例句柄。threaded 与安装的钩子子程相关联的线程的标识符 + //如果为0,钩子子程与所有的线程关联,即为全局钩子 + //************************************ + //如果SetWindowsHookEx失败 + if (hKeyboardHook == 0) + { + Stop(); + throw new Exception("安装键盘钩子失败"); + } + } + } + public void Stop() + { + bool retKeyboard = true; + + + if (hKeyboardHook != 0) + { + retKeyboard = UnhookWindowsHookEx(hKeyboardHook); + hKeyboardHook = 0; + } + + if (!(retKeyboard)) throw new Exception("卸载钩子失败!"); + } + //ToAscii职能的转换指定的虚拟键码和键盘状态的相应字符或字符 + [DllImport("user32")] + public static extern int ToAscii(int uVirtKey, //[in] 指定虚拟关键代码进行翻译。 + int uScanCode, // [in] 指定的硬件扫描码的关键须翻译成英文。高阶位的这个值设定的关键,如果是(不压) + byte[] lpbKeyState, // [in] 指针,以256字节数组,包含当前键盘的状态。每个元素(字节)的数组包含状态的一个关键。如果高阶位的字节是一套,关键是下跌(按下)。在低比特,如果设置表明,关键是对切换。在此功能,只有肘位的CAPS LOCK键是相关的。在切换状态的NUM个锁和滚动锁定键被忽略。 + byte[] lpwTransKey, // [out] 指针的缓冲区收到翻译字符或字符。 + int fuState); // [in] Specifies whether a menu is active. This parameter must be 1 if a menu is active, or 0 otherwise. + + //获取按键的状态 + [DllImport("user32")] + public static extern int GetKeyboardState(byte[] pbKeyState); + + + [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] + private static extern short GetKeyState(int vKey); + + private const int WM_KEYDOWN = 0x100;//KEYDOWN + private const int WM_KEYUP = 0x101;//KEYUP + private const int WM_SYSKEYDOWN = 0x104;//SYSKEYDOWN + private const int WM_SYSKEYUP = 0x105;//SYSKEYUP + + private int KeyboardHookProc(int nCode, Int32 wParam, IntPtr lParam) + { + // 侦听键盘事件 + if ((nCode >= 0) && (KeyDownEvent != null || KeyUpEvent != null || KeyPressEvent != null)) + { + KeyboardHookStruct MyKeyboardHookStruct = (KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyboardHookStruct)); + // raise KeyDown + if (KeyDownEvent != null && (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN)) + { + Keys keyData = (Keys)MyKeyboardHookStruct.vkCode; + KeyEventArgs e = new KeyEventArgs(keyData); + KeyDownEvent(this, e); + } + + //键盘按下 + if (KeyPressEvent != null && wParam == WM_KEYDOWN) + { + byte[] keyState = new byte[256]; + GetKeyboardState(keyState); + + byte[] inBuffer = new byte[2]; + if (ToAscii(MyKeyboardHookStruct.vkCode, MyKeyboardHookStruct.scanCode, keyState, inBuffer, MyKeyboardHookStruct.flags) == 1) + { + KeyPressEventArgs e = new KeyPressEventArgs((char)inBuffer[0]); + KeyPressEvent(this, e); + } + } + + // 键盘抬起 + if (KeyUpEvent != null && (wParam == WM_KEYUP || wParam == WM_SYSKEYUP)) + { + Keys keyData = (Keys)MyKeyboardHookStruct.vkCode; + KeyEventArgs e = new KeyEventArgs(keyData); + KeyUpEvent(this, e); + } + + } + //如果返回1,则结束消息,这个消息到此为止,不再传递。 + //如果返回0或调用CallNextHookEx函数则消息出了这个钩子继续往下传递,也就是传给消息真正的接受者 + return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam); + } + ~KeyManager() + { + Stop(); + } + } +} \ No newline at end of file diff --git a/TheWorstEngine/TheWorstEngine.csproj b/TheWorstEngine/TheWorstEngine.csproj index d27abdd..5331705 100644 --- a/TheWorstEngine/TheWorstEngine.csproj +++ b/TheWorstEngine/TheWorstEngine.csproj @@ -49,6 +49,7 @@ + @@ -70,8 +71,5 @@ True - - - \ No newline at end of file diff --git a/TheWorstEngine/bin/Debug/TheWorstEngine.dll b/TheWorstEngine/bin/Debug/TheWorstEngine.dll index a787825..70d4a0e 100644 Binary files a/TheWorstEngine/bin/Debug/TheWorstEngine.dll and b/TheWorstEngine/bin/Debug/TheWorstEngine.dll differ diff --git a/TheWorstEngine/bin/Debug/TheWorstEngine.pdb b/TheWorstEngine/bin/Debug/TheWorstEngine.pdb index 47b3fa0..6955221 100644 Binary files a/TheWorstEngine/bin/Debug/TheWorstEngine.pdb and b/TheWorstEngine/bin/Debug/TheWorstEngine.pdb differ diff --git a/TheWorstEngine/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/TheWorstEngine/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache index 5968978..2a9b440 100644 Binary files a/TheWorstEngine/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache and b/TheWorstEngine/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/TheWorstEngine/obj/Debug/TheWorstEngine.csproj.CoreCompileInputs.cache b/TheWorstEngine/obj/Debug/TheWorstEngine.csproj.CoreCompileInputs.cache index 08021df..938cff2 100644 --- a/TheWorstEngine/obj/Debug/TheWorstEngine.csproj.CoreCompileInputs.cache +++ b/TheWorstEngine/obj/Debug/TheWorstEngine.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -3a6d932e32c257bbc566bcbdbdf0da9a58ee886b +203c201f3a7d64c3e93cdf222ec98b767cdd3352 diff --git a/TheWorstEngine/obj/Debug/TheWorstEngine.csproj.FileListAbsolute.txt b/TheWorstEngine/obj/Debug/TheWorstEngine.csproj.FileListAbsolute.txt index 2e7a7f6..07b44d8 100644 --- a/TheWorstEngine/obj/Debug/TheWorstEngine.csproj.FileListAbsolute.txt +++ b/TheWorstEngine/obj/Debug/TheWorstEngine.csproj.FileListAbsolute.txt @@ -3,7 +3,6 @@ D:\C#类编程文件\带工程\TWE\TheWorstEngine\TheWorstEngine\obj\Debug\TheWo D:\C#类编程文件\带工程\TWE\TheWorstEngine\TheWorstEngine\obj\Debug\TheWorstEngine.csproj.GenerateResource.cache D:\C#类编程文件\带工程\TWE\TheWorstEngine\TheWorstEngine\obj\Debug\TheWorstEngine.csproj.CoreCompileInputs.cache D:\C#类编程文件\带工程\TWE\TheWorstEngine\TheWorstEngine\obj\Debug\TheWorstEngine.pdb -D:\C#类编程文件\带工程\TWE\TheWorstEngine\TheWorstEngine\bin\Debug\TheWorstEngine.dll.config D:\C#类编程文件\带工程\TWE\TheWorstEngine\TheWorstEngine\bin\Debug\TheWorstEngine.dll D:\C#类编程文件\带工程\TWE\TheWorstEngine\TheWorstEngine\obj\Debug\TheWorstEngine.dll D:\C#类编程文件\带工程\TWE\TheWorstEngine\TheWorstEngine\obj\Debug\TheWorstEngine.csprojAssemblyReference.cache diff --git a/TheWorstEngine/obj/Debug/TheWorstEngine.csprojAssemblyReference.cache b/TheWorstEngine/obj/Debug/TheWorstEngine.csprojAssemblyReference.cache index 6ba77f7..73f8817 100644 Binary files a/TheWorstEngine/obj/Debug/TheWorstEngine.csprojAssemblyReference.cache and b/TheWorstEngine/obj/Debug/TheWorstEngine.csprojAssemblyReference.cache differ diff --git a/TheWorstEngine/obj/Debug/TheWorstEngine.dll b/TheWorstEngine/obj/Debug/TheWorstEngine.dll index a787825..70d4a0e 100644 Binary files a/TheWorstEngine/obj/Debug/TheWorstEngine.dll and b/TheWorstEngine/obj/Debug/TheWorstEngine.dll differ diff --git a/TheWorstEngine/obj/Debug/TheWorstEngine.pdb b/TheWorstEngine/obj/Debug/TheWorstEngine.pdb index 47b3fa0..6955221 100644 Binary files a/TheWorstEngine/obj/Debug/TheWorstEngine.pdb and b/TheWorstEngine/obj/Debug/TheWorstEngine.pdb differ diff --git a/TheWorstEngine/twe.cs b/TheWorstEngine/twe.cs index 38c5d92..c572d1b 100644 --- a/TheWorstEngine/twe.cs +++ b/TheWorstEngine/twe.cs @@ -2,6 +2,9 @@ using System.Drawing; using System.Threading; using System.Windows.Forms; +// KeyManager +// using System.Runtime.InteropServices; //调用WINDOWS API函数时要用到 +// using Microsoft.Win32; //写入注册表时要用到 namespace TheWorstEngine { @@ -15,15 +18,30 @@ public class Twe /// 添加图片box /// public PictureBox picturebox; + /// /// 检测程序是否被关闭 /// public bool isClosed = false; + // FPS显示 private Label FPSLabelG = new Label(); + // 是否显示FPS private bool isFPSShow = false; - - private string[] FilesNameGolobal = { }; - private int FPSGolobal = 0; + // 向上的按键 + private Keys UpKeyGlobal = Keys.W; + // 向下的按键 + private Keys DownKeyGlobal = Keys.S; + // 向左的按键 + private Keys LeftKeyGlobal = Keys.A; + // 向右的按键 + private Keys RightKeyGlobal = Keys.D; + // 移动速度 + private int MoveSpeed = 5; + // 动画图片 + private string[] FilesNameGlobal = { }; + // 动画FPS + private int FPSGlobal = 0; + // 初始化函数 /// /// 设置窗口分辨率 /// @@ -33,6 +51,36 @@ public string SetResolution(Size size) form.Size = size; return "已将分辨率设为:" + size; } + + // 帧动画/图片函数 + /// + /// 帧动画 + /// + /// 文件集,将所有需要参与演算的图片路径存到这个数组里 + /// 帧数 + /// + public string NewAnim(string[] FilesName, int FPS) + { + FilesNameGlobal = FilesName; + FPSGlobal = FPS; + Thread Anim = new Thread(AnimFor); + Anim.Start(); + return "动画已创建"; + } + /// + /// 帧动画 + /// + /// 文件集,将所有需要参与演算的图片路径存到这个数组里 + /// 帧数 + /// 绑定帧数显示label + /// + public string NewAnim(string[] FilesName, int FPS, Label FPSLabel) + { + isFPSShow = true; + FPSLabelG = FPSLabel; + NewAnim(FilesName, FPS); + return "动画已创建"; + } /// /// 设置图片用的 /// @@ -44,38 +92,104 @@ public string NewImage(string FileName) return "已将图片设置为:" + FileName; } - + // 移动函数 /// - /// 帧动画 + /// 是否可以移动 /// - /// 文件集,将所有需要参与演算的图片路径存到这个数组里 - /// 帧数 + /// true则可以移动,false则为贴图 + public void CanMove(bool CanItMove) + { + if (CanItMove) + { + /* + KeyManager k_hook = new KeyManager(); + k_hook.KeyDownEvent += new KeyEventHandler(hook_KeyDown);//钩住键按下 + k_hook.Start();//安装键盘钩子*/ + form.KeyDown += new KeyEventHandler(hook_KeyDown); + } + } + /// + /// 是否可以移动 + /// + /// true则可以移动, false则为贴图 + /// MoveSpeed,即移动速度,默认5 + public void CanMove(bool CanItMove, int MS) + { + MoveSpeed = MS; + CanMove(CanItMove); + } + /// + /// 设置移动速度 + /// + /// 移动速度(默认为5) + public void SetMoveSpeed(int MS) + { + MoveSpeed = MS; + } + /// + /// 设置移动按键 + /// + /// 向上走按键 + /// 向下走按键 + /// 向左走按键 + /// 向右走按键 /// - public string NewAnim(string[] FilesName, int FPS) + public string KeySet(Keys UpKey, Keys DownKey, Keys LeftKey, Keys RightKey) { - FilesNameGolobal = FilesName; - FPSGolobal = FPS; - Thread Anim = new Thread(AnimFor); - Anim.Start(); - return ""; + UpKeyGlobal = UpKey; + DownKeyGlobal = DownKey; + LeftKeyGlobal = LeftKey; + RightKeyGlobal = RightKey; + return "已将上下左右分别设置为按键:" + UpKey + " " + DownKey + + " " + LeftKey + " " + RightKey; } - public string NewAnim(string[] FilesName, int FPS, Label FPSLable) + + // 私有类 + // 按键event + private void hook_KeyDown(object sender, KeyEventArgs e) { - FilesNameGolobal = FilesName; - FPSGolobal = FPS; - isFPSShow = true; - FPSLabelG = FPSLable; - Thread Anim = new Thread(AnimFor); - Anim.Start(); - return ""; + int x = picturebox.Location.X; + int y = picturebox.Location.Y; + /* + //判断按下的键(Alt + A) + if (e.KeyValue == (int)Keys.A && (int)Control.ModifierKeys == (int)Keys.Alt) + { + + }*/ + + if (e.KeyCode == UpKeyGlobal) + { + picturebox.Location = new Point( + x, y - MoveSpeed); + // Console.WriteLine("按下了" + UpKeyGlobal); + } + if (e.KeyCode == DownKeyGlobal) + { + picturebox.Location = new Point( + x, y + MoveSpeed); + // Console.WriteLine("按下了" + DownKeyGlobal); + } + if (e.KeyCode == LeftKeyGlobal) + { + picturebox.Location = new Point( + x - MoveSpeed, y); + // Console.WriteLine("按下了" + LeftKeyGlobal); + } + if (e.KeyCode == RightKeyGlobal) + { + picturebox.Location = new Point( + x + MoveSpeed, y); + // Console.WriteLine("按下了" + RightKeyGlobal); + } } + // 动画多线程方法 private void AnimFor() { - int Flenght = FilesNameGolobal.Length; + int Flenght = FilesNameGlobal.Length; int Count = 0; try { - picturebox.Image = Image.FromFile(FilesNameGolobal[Count]); + picturebox.Image = Image.FromFile(FilesNameGlobal[Count]); } catch (Exception e) { @@ -83,27 +197,28 @@ private void AnimFor() "改为了AutoSize,请联系TWE引擎开发者或本游戏开发者进行解决" + "\n具体问题(您并不需要看懂,请截图给开发者):" + e); } + if (isFPSShow) + { + FPSLabelG.Text = "FPS:" + FPSGlobal.ToString(); + } while (true) { if (isClosed) { break; } - if (Count == FilesNameGolobal.Length) + if (Count == FilesNameGlobal.Length) { Count = 0; } else { - if (isFPSShow) - { - FPSLabelG.Text = "FPS:" + FPSGolobal.ToString(); - } - picturebox.Image = Image.FromFile(FilesNameGolobal[Count]); + picturebox.Image = Image.FromFile(FilesNameGlobal[Count]); Count++; - Thread.Sleep(1000 / FPSGolobal); + Thread.Sleep(1000 / FPSGlobal); } } } + } }