5 changed files with 127 additions and 75 deletions
@ -0,0 +1,56 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Runtime.InteropServices; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace formula_manage.UserClass |
||||
|
{ |
||||
|
internal class IniFile |
||||
|
{ |
||||
|
public class IniFiles |
||||
|
{ |
||||
|
public string path; |
||||
|
[DllImport("kernel32")] //返回0表示失败,非0为成功
|
||||
|
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath); |
||||
|
[DllImport("kernel32")] //返回取得字符串缓冲区的长度
|
||||
|
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath); |
||||
|
/// <summary>
|
||||
|
/// 保存ini文件的路径
|
||||
|
/// 调用示例:var ini = IniFiles("C:\file.ini");
|
||||
|
/// </summary>
|
||||
|
/// <param name="INIPath"></param>
|
||||
|
public IniFiles(string iniPath) |
||||
|
{ |
||||
|
this.path = iniPath; |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 写Ini文件
|
||||
|
/// 调用示例:ini.IniWritevalue("Server","name","localhost");
|
||||
|
/// </summary>
|
||||
|
/// <param name="Section">[缓冲区]</param>
|
||||
|
/// <param name="Key">键</param>
|
||||
|
/// <param name="value">值</param>
|
||||
|
public void IniWritevalue(string Section, string Key, string value) |
||||
|
{ |
||||
|
WritePrivateProfileString(Section, Key, value, this.path); |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 读Ini文件
|
||||
|
/// 调用示例:ini.IniWritevalue("Server","name");
|
||||
|
/// </summary>
|
||||
|
/// <param name="Section">[缓冲区]</param>
|
||||
|
/// <param name="Key">键</param>
|
||||
|
/// <returns>值</returns>
|
||||
|
public string IniReadvalue(string Section, string Key) |
||||
|
{ |
||||
|
StringBuilder temp = new StringBuilder(255); |
||||
|
|
||||
|
int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path); |
||||
|
return temp.ToString(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Runtime.InteropServices; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using System.Windows.Forms; |
||||
|
|
||||
|
namespace formula_manage.UserClass |
||||
|
{ |
||||
|
internal class PressKey |
||||
|
{ |
||||
|
[DllImport("user32.dll", SetLastError = true)] |
||||
|
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo); |
||||
|
public static void PressKeys(Keys key, bool up) |
||||
|
{ |
||||
|
const int KEYEVENTF_EXTENDEDKEY = 0x1; |
||||
|
const int KEYEVENTF_KEYUP = 0x2; |
||||
|
if (up) |
||||
|
{ |
||||
|
keybd_event((byte)key, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, (UIntPtr)0); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
keybd_event((byte)key, 0x45, KEYEVENTF_EXTENDEDKEY, (UIntPtr)0); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue