基线 SVN r240
SVN-Revision: r240
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using Lskj.Main2.Properties;
|
||||
using Lskj.Util;
|
||||
|
||||
namespace Lskj.Main2.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源图片管理类
|
||||
/// </summary>
|
||||
public static class BitMapHelper
|
||||
{
|
||||
#region 本地资源文件
|
||||
/// <summary>
|
||||
/// 获取本地资源文件
|
||||
/// </summary>
|
||||
/// <param name="mapEnum"></param>
|
||||
/// <returns></returns>
|
||||
public static Bitmap getBitmap(BitMapEnum mapEnum)
|
||||
{
|
||||
Bitmap bitmap = null;
|
||||
try
|
||||
{
|
||||
FileStream fs = File.OpenRead(getBitMapPath(mapEnum)); //OpenRead
|
||||
|
||||
int filelength = (int)fs.Length; //获得文件长度
|
||||
Byte[] image = new Byte[filelength]; //建立一个字节数组
|
||||
fs.Read(image, 0, filelength); //按字节流读取
|
||||
Image result = Image.FromStream(fs);
|
||||
fs.Close();
|
||||
|
||||
bitmap = new Bitmap(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
switch (mapEnum)
|
||||
{
|
||||
case BitMapEnum.loginbg:
|
||||
bitmap = Resources.newlogin;
|
||||
break;
|
||||
case BitMapEnum.submenubg:
|
||||
bitmap = Resources.sub_backgroud;
|
||||
break;
|
||||
case BitMapEnum.submenubg_tip:
|
||||
bitmap = Resources.sub_tip_backgound;
|
||||
break;
|
||||
case BitMapEnum.logobg:
|
||||
bitmap = Resources.logo;
|
||||
break;
|
||||
case BitMapEnum.logo2bg:
|
||||
bitmap = Resources.logo;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取文件路径
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static string getBitMapPath(BitMapEnum mapEnum)
|
||||
{
|
||||
string bitmapPath = string.Empty;
|
||||
switch (mapEnum)
|
||||
{
|
||||
case BitMapEnum.loginbg:
|
||||
bitmapPath = BitMapType.Loginbg;
|
||||
break;
|
||||
case BitMapEnum.submenubg:
|
||||
bitmapPath = BitMapType.Submenubg;
|
||||
break;
|
||||
case BitMapEnum.submenubg_tip:
|
||||
bitmapPath = BitMapType.Submenubg_tip;
|
||||
break;
|
||||
case BitMapEnum.logobg:
|
||||
bitmapPath = BitMapType.Logobg;
|
||||
break;
|
||||
case BitMapEnum.logo2bg:
|
||||
bitmapPath = BitMapType.Logo2bg;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return PubUtil.BitMapPath + bitmapPath;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 图片存放地址
|
||||
/// </summary>
|
||||
public static class BitMapType
|
||||
{
|
||||
/// <summary>
|
||||
/// 登录背景图
|
||||
/// </summary>
|
||||
public static string Loginbg = @"Login\newlogin.png";
|
||||
/// <summary>
|
||||
/// 子系统背景图
|
||||
/// </summary>
|
||||
public static string Submenubg = @"Submenu\submenu.png";
|
||||
/// <summary>
|
||||
/// 子系统背景图提示
|
||||
/// </summary>
|
||||
public static string Submenubg_tip = @"Submenu\submenu_tip.png";
|
||||
/// <summary>
|
||||
/// logo背景图
|
||||
/// </summary>
|
||||
public static string Logobg = @"Main\logo.png";
|
||||
/// <summary>
|
||||
/// logo2背景图
|
||||
/// </summary>
|
||||
public static string Logo2bg = @"Main2\logo.png";
|
||||
}
|
||||
/// <summary>
|
||||
/// 图片类型
|
||||
/// </summary>
|
||||
public enum BitMapEnum
|
||||
{
|
||||
loginbg,
|
||||
submenubg,
|
||||
submenubg_tip,
|
||||
logobg,
|
||||
logo2bg
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,382 @@
|
||||
/******************************
|
||||
* 说明:主程序启动相关管理类
|
||||
* 创建人:龚宇超
|
||||
* 创建日期:2017-08-09
|
||||
* 修改人:
|
||||
* 修改日期:
|
||||
* 修改备注:
|
||||
* 版本:1.0.0.0
|
||||
******************************/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using Lskj.Control.Model;
|
||||
using Lskj.Core;
|
||||
using DevExpress.XtraEditors;
|
||||
using Lskj.Control;
|
||||
using Lskj.Data;
|
||||
using System.Threading;
|
||||
using Lskj.Business;
|
||||
using System.Data;
|
||||
using Lskj.Model;
|
||||
using DevExpress.XtraTab;
|
||||
using Lskj.Util;
|
||||
using DevExpress.Utils;
|
||||
using System.Diagnostics;
|
||||
using Lskj.Business.Impl;
|
||||
using System.IO;
|
||||
|
||||
|
||||
|
||||
namespace Lskj.Main2.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// 主程序启动相关管理类
|
||||
/// </summary>
|
||||
public sealed class Manager
|
||||
{
|
||||
/// <summary>
|
||||
/// 主程序
|
||||
/// </summary>
|
||||
private static FrmMain _frmMain = null;
|
||||
public static XtraTabControl TabMain = null;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 记录当前打开的窗口
|
||||
/// </summary>
|
||||
public static Dictionary<string, DllModule> ModuleForms = new Dictionary<string, DllModule>();
|
||||
/// <summary>
|
||||
/// <para>说明:程序启动入口</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-08-09 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
public static void StartForm()
|
||||
{
|
||||
bool isStart = true;
|
||||
// 加载Splash动画界面
|
||||
SplashForm.ShowForm();
|
||||
// C#数据库连接检查
|
||||
if (!DBConfig.Instance.CreateConnection())
|
||||
{
|
||||
MessageUtil.Show(ResourceKeys.UnConnectServer);
|
||||
SplashForm.HideForm();
|
||||
DialogResult result = RunConfigForm();
|
||||
isStart = result == DialogResult.OK;
|
||||
}
|
||||
if (isStart)
|
||||
{
|
||||
// Delphi数据库连接检查
|
||||
if (DelphiHelper.Delphi_Init(new StringBuilder(DBConfig.Instance.GetDelphiConnection())) == 0)
|
||||
{
|
||||
MessageUtil.Show(ResourceKeys.UnConnectServer + "[By Delphi]");
|
||||
SplashForm.HideForm();
|
||||
RunConfigForm();
|
||||
return;
|
||||
}
|
||||
SplashForm.HideForm();
|
||||
// 汉化dev控件
|
||||
BaseResources.Localization(LocalizationType.CHS);
|
||||
// 启动登录页面
|
||||
DialogResult result = RunLoginForm();
|
||||
if (result == DialogResult.OK)
|
||||
{
|
||||
string where = string.IsNullOrEmpty(ERPInfo.Instance.SeriesId) ? "" : string.Format("and SeriesId={0}", ERPInfo.Instance.SeriesId);
|
||||
DataTable table = MainImpl.EnableSubSystem(where);
|
||||
ERPInfo.Instance.SubMenuCount = table.Rows.Count;
|
||||
if (table.Rows.Count == 1)
|
||||
{
|
||||
ERPInfo.Instance.SubSysId = table.Rows[0]["SubSysId"] + "";
|
||||
ERPInfo.Instance.SubSysName = table.Rows[0]["SubSysName"] + "";
|
||||
}
|
||||
|
||||
ReStartMain();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SplashForm.HideForm();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>说明:重新启动</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-08-14 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="skipMenu">是否跳过子系统选择(适用于切换用户).</param>
|
||||
public static void ReStartMain(bool skipMenu = false)
|
||||
{
|
||||
|
||||
if (_frmMain != null)
|
||||
{
|
||||
_frmMain.Close();
|
||||
_frmMain.Dispose();
|
||||
_frmMain = null;
|
||||
}
|
||||
|
||||
bool isStart = true;
|
||||
DialogResult result;
|
||||
|
||||
if (ERPInfo.Instance.SubMenuCount > 1 && !skipMenu)
|
||||
{
|
||||
// 进入子系统界面
|
||||
result = RunSubSystemForm();
|
||||
isStart = result == DialogResult.OK;
|
||||
}
|
||||
if (isStart)
|
||||
{
|
||||
if (ERPInfo.Instance.SubMenuCount == 0)
|
||||
{
|
||||
MessageUtil.Show("方案内未配置子模块!");
|
||||
}
|
||||
else
|
||||
{
|
||||
// 直接进入主界面
|
||||
RunMainForm();
|
||||
if (ERPInfo.Instance.SubMenuCount > 1)
|
||||
{
|
||||
ReStartMain();
|
||||
}
|
||||
else
|
||||
{
|
||||
ExitSystem();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ExitSystem();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:打开模块</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-08-18 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="menuId">The menu identifier.</param>
|
||||
/// <param name="menuName">Name of the menu.</param>
|
||||
/// <param name="modelFlag">The model flag.</param>
|
||||
/// <param name="urlParams">The URL parameters.</param>
|
||||
public static void OpenModule(string menuId, string menuName, string dllName, string modelFlag, string urlParams)
|
||||
{
|
||||
// 验证参数
|
||||
if (string.IsNullOrWhiteSpace(menuId) || string.IsNullOrWhiteSpace(dllName))
|
||||
{
|
||||
MessageUtil.Show(ResourceKeys.NotFoundMenu);
|
||||
return;
|
||||
}
|
||||
// 验证权限
|
||||
int purview = MainImpl.GetUserPurviewsByMenuId(menuId);
|
||||
if (purview == 0)
|
||||
{
|
||||
MessageUtil.Show(ResourceKeys.UnPurview);
|
||||
return;
|
||||
}
|
||||
//LogUtil.WriteDebug(menuId.ToString(), "操作模块", menuName, menuName);
|
||||
LogUtil.WriteDebug(modelFlag.ToString(), "操作模块", menuName, menuName, menuId.ToString());
|
||||
DllModule module = new DllModule
|
||||
{
|
||||
DllName = ReplaceDllFileName(dllName),
|
||||
Id = menuId,
|
||||
Name = menuName
|
||||
};
|
||||
string[] args = new string[]{
|
||||
menuName,
|
||||
ERPInfo.Instance.UserId,
|
||||
ERPInfo.Instance.UserName,
|
||||
purview + "",
|
||||
urlParams,
|
||||
menuId
|
||||
};
|
||||
dllName = MainImpl.GetDefaultValue(dllName);
|
||||
|
||||
if (dllName.ToLower().Contains(".exe"))
|
||||
{
|
||||
WinHelper.WinExec(dllName);
|
||||
}
|
||||
else if (dllName.ToLower().IndexOf("http:", StringComparison.OrdinalIgnoreCase) != -1 ||
|
||||
dllName.ToLower().IndexOf("www.", StringComparison.OrdinalIgnoreCase) != -1 ||
|
||||
dllName.ToLower().IndexOf("ftp:", StringComparison.OrdinalIgnoreCase) != -1)
|
||||
{
|
||||
Process.Start(dllName);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dllName.ToLower().EndsWith(".lsp"))
|
||||
{
|
||||
//MessageBox.Show(PubUtil.AbsolutelyLibPath + dllName+" "+ menuName+" "+purview+" "+urlParams);
|
||||
// 打开delphi程序
|
||||
DelphiHelper.LoadDelphiDll(PubUtil.AbsolutelyLibPath + dllName, "", menuName, "", "", purview, urlParams);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 打开module程序
|
||||
AddModuleToTab(module, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:添加模块到tab中</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-08-16 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="tabMain">The tab main.</param>
|
||||
/// <param name="module">The module.</param>
|
||||
/// <param name="args">The arguments.</param>
|
||||
public static void AddModuleToTab(DllModule module, string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
IForm iform = FormHelper.LoadDllForm(module.DllName, args);
|
||||
// 菜单打开的模块默认最大化,界面FormState设置为Normal模式,否则会出现界面不是全屏,会显示默认阴影界面
|
||||
iform.SubForm.WindowState = FormWindowState.Maximized;
|
||||
Form form = iform.SubForm;
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
|
||||
XtraTabPage tp = new XtraTabPage();
|
||||
tp.Text = module.Name;
|
||||
tp.Tag = guid;
|
||||
|
||||
// 这个必须有不然会提示:"不能向tabControl中添加顶级控件"
|
||||
form.TopLevel = false;
|
||||
form.Dock = DockStyle.Fill;
|
||||
form.FormBorderStyle = FormBorderStyle.None;
|
||||
|
||||
tp.Controls.Add(form);
|
||||
tp.ShowCloseButton = DefaultBoolean.True;
|
||||
|
||||
TabMain.TabPages.Add(tp);
|
||||
TabMain.SelectedTabPage = tp;
|
||||
|
||||
module.Tag = "1";
|
||||
module.ModuleForm = form;
|
||||
|
||||
form.Show();
|
||||
ModuleForms.Add(guid, module);
|
||||
//LastModuleForm.Add(module);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageUtil.Show(ex.InnerException != null ? ex.InnerException.Message : ex.Message);
|
||||
LogHelper.Instance.WriteError(ex);
|
||||
LogUtil.WriteError("打开" + module.Name + "模块失败!", ex);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:特殊dll模块处理</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2018-04-20 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="dllName">Name of the DLL.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
private static string ReplaceDllFileName(string dllName)
|
||||
{
|
||||
switch (dllName.ToLower().Trim())
|
||||
{
|
||||
case "pubspec.dll":
|
||||
dllName = "Lskj.PubSpec.dll";
|
||||
break;
|
||||
}
|
||||
return dllName;
|
||||
}
|
||||
private static void ExitSystem()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 退出系统
|
||||
if (DBConfig.Instance.NoticeExit)
|
||||
{
|
||||
Process[] p1 = Process.GetProcessesByName("Ls_Notice");
|
||||
foreach (Process item in p1)
|
||||
item.Kill();
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:启动配置窗口</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-08-09 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
private static DialogResult RunConfigForm()
|
||||
{
|
||||
FrmConfig frmConfig = new FrmConfig();
|
||||
return frmConfig.ShowDialog();
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:打开登录界面</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-08-12 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <returns>DialogResult.</returns>
|
||||
private static DialogResult RunLoginForm()
|
||||
{
|
||||
FrmLogin frmLogin = new FrmLogin();
|
||||
return frmLogin.ShowDialog();
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:打开子系统</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-08-14 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <returns>System.Windows.Forms.DialogResult.</returns>
|
||||
private static DialogResult RunSubSystemForm()
|
||||
{
|
||||
FrmSubSystem subSystem = new FrmSubSystem();
|
||||
return subSystem.ShowDialog();
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:打开主程序</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-08-14 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <returns>DialogResult.</returns>
|
||||
private static DialogResult RunMainForm()
|
||||
{
|
||||
_frmMain = new FrmMain();
|
||||
return _frmMain.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,403 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace Lskj.Main2.Model
|
||||
{
|
||||
public static class WinAPI
|
||||
{
|
||||
#region 常量声明
|
||||
|
||||
public const int GWL_WNDPROC = -4; //得到窗口回调函数的地址,或者句柄。得到后必须使用CallWindowProc函数来调用
|
||||
public const int GWL_HINSTANCE = -6; //得到应用程序运行实例的句柄
|
||||
public const int GWL_HWNDPARENT = -8; //得到父窗口的句柄
|
||||
public const int GWL_STYLE = -16; //得到窗口风格
|
||||
public const int GWL_EXSTYLE = -20; //得到扩展的窗口风格
|
||||
public const int GWL_USERDATA = -21; //得到和窗口相关联的32位的值(每一个窗口都有一个有意留给创建窗口的应用程序是用的32位的值)
|
||||
public const int GWL_ID = -12; //得到窗口的标识符
|
||||
|
||||
public const int DWL_MSGRESULT = 0;
|
||||
public const int DWL_DLGPROC = 4;
|
||||
public const int DWL_USER = 8;
|
||||
|
||||
public const int HWND_BOTTOM = 1;
|
||||
public const int HWND_TOP = 0;
|
||||
public const int HWND_TOPMOST = -1;
|
||||
public const int HWND_NOTOPMOST = -2;
|
||||
|
||||
public const int SWP_DRAW = 0x20;
|
||||
public const int SWP_HIDEWINDOW = 0x80;
|
||||
public const int SWP_NOACTIVATE = 0x10;
|
||||
public const int SWP_NOMOVE = 0x2;
|
||||
public const int SWP_NOREDRAW = 0x8;
|
||||
public const int SWP_NOSIZE = 0x1;
|
||||
public const int SWP_NOZORDER = 0x4;
|
||||
public const int SWP_SHOWWINDOW = 0x40;
|
||||
|
||||
public const int WS_OVERLAPPED = 0;
|
||||
public const int WS_BORDER = 0x800000;
|
||||
public const int WS_CAPTION = 0xC00000;
|
||||
public const int WS_CHILD = 0x40000000;
|
||||
public const int WS_DLGFRAME = 0x400000;
|
||||
public const int WS_SIZEBOX = 0x40000;
|
||||
public const int WS_MAXIMIZEBOX = 0x10000;
|
||||
public const int WS_MINIMIZEBOX = 0x20000;
|
||||
public const int WS_SYSMENU = 0x80000;
|
||||
public const int WS_HSCROLL = 0x100000;
|
||||
public const int WS_VSCROLL = 0x200000;
|
||||
|
||||
public const int WA_INACTIVE = 0;
|
||||
public const int WA_ACTIVE = 1;
|
||||
public const int WA_CLICKACTIVE = 2;
|
||||
public const int WM_NOTIFY = 0x004E;
|
||||
|
||||
public const int WM_ACTIVATE = 0x0006;
|
||||
public const int WM_NULL = 0x0000;
|
||||
public const int WM_CREATE = 0x0001;
|
||||
public const int WM_DESTROY = 0x0002;
|
||||
public const int WM_MOVE = 0x0003;
|
||||
public const int WM_SIZE = 0x0005;
|
||||
public const int WM_SETFOCUS = 0x0007;
|
||||
public const int WM_MOUSEACTIVATE = 0x0021;
|
||||
public const int WM_CLOSE = 0x0010;
|
||||
public const int WM_QUIT = 0x0012;
|
||||
|
||||
public const int WM_KEYDOWN = 0x0100;
|
||||
public const int WM_KEYUP = 0x0101;
|
||||
public const int WM_CHAR = 0x0102;
|
||||
public const int WM_DEADCHAR = 0x0103;
|
||||
public const int WM_SYSKEYDOWN = 0x0104;
|
||||
public const int WM_SYSKEYUP = 0x0105;
|
||||
public const int WM_SYSCHAR = 0x0106;
|
||||
public const int WM_SYSDEADCHAR = 0x0107;
|
||||
public const int WM_UNICHAR = 0x0109;
|
||||
public const int WM_KEYLAST = 0x0109;
|
||||
public const int UNICODE_NOCHAR = 0xFFFF;
|
||||
|
||||
public const int MK_LBUTTON = 0x0001;
|
||||
public const int MK_RBUTTON = 0x0002;
|
||||
public const int MK_SHIFT = 0x0004;
|
||||
public const int MK_CONTROL = 0x0008;
|
||||
public const int MK_MBUTTON = 0x0010;
|
||||
|
||||
public const int WM_MOUSEFIRST = 0x0200;
|
||||
public const int WM_MOUSEMOVE = 0x0200;
|
||||
public const int WM_LBUTTONDOWN = 0x0201;
|
||||
public const int WM_LBUTTONUP = 0x0202;
|
||||
public const int WM_LBUTTONDBLCLK = 0x0203;
|
||||
public const int WM_RBUTTONDOWN = 0x0204;
|
||||
public const int WM_RBUTTONUP = 0x0205;
|
||||
public const int WM_RBUTTONDBLCLK = 0x0206;
|
||||
public const int WM_MBUTTONDOWN = 0x0207;
|
||||
public const int WM_MBUTTONUP = 0x0208;
|
||||
public const int WM_MBUTTONDBLCLK = 0x0209;
|
||||
public const int WM_MOUSEWHEEL = 0x020A;
|
||||
public const int WM_MDICREATE = 0x0220;
|
||||
|
||||
public const int WM_ERASEBKGND = 0x14;
|
||||
public const int WM_PAINT = 0xF;
|
||||
public const int WM_NC_HITTEST = 0x84;
|
||||
public const int WM_NC_PAINT = 0x85;
|
||||
public const int WM_PRINTCLIENT = 0x318;
|
||||
public const int WM_SETCURSOR = 0x20;
|
||||
|
||||
public const int BM_CLICK = 0x00F5;
|
||||
public const int BM_GETIMAGE = 0x00F6;
|
||||
public const int BM_SETIMAGE = 0x00F7;
|
||||
|
||||
public const int VK_BACK = 0x08;
|
||||
public const int VK_TAB = 0x09;
|
||||
public const int VK_CLEAR = 0x0C;
|
||||
public const int VK_RETURN = 0x0D;
|
||||
public const int VK_SHIFT = 0x10;
|
||||
public const int VK_CONTROL = 0x11;
|
||||
public const int VK_MENU = 0x12;
|
||||
public const int VK_PAUSE = 0x13;
|
||||
public const int VK_CAPITAL = 0x14;
|
||||
public const int VK_KANA = 0x15;
|
||||
public const int VK_HANGEUL = 0x15;
|
||||
public const int VK_HANGUL = 0x15;
|
||||
public const int VK_JUNJA = 0x17;
|
||||
public const int VK_FINAL = 0x18;
|
||||
public const int VK_HANJA = 0x19;
|
||||
public const int VK_KANJI = 0x19;
|
||||
public const int VK_ESCAPE = 0x1B;
|
||||
public const int VK_CONVERT = 0x1C;
|
||||
public const int VK_NONCONVERT = 0x1D;
|
||||
public const int VK_ACCEPT = 0x1E;
|
||||
public const int VK_MODECHANGE = 0x1F;
|
||||
public const int VK_SPACE = 0x20;
|
||||
public const int VK_PRIOR = 0x21;
|
||||
public const int VK_NEXT = 0x22;
|
||||
public const int VK_END = 0x23;
|
||||
public const int VK_HOME = 0x24;
|
||||
public const int VK_LEFT = 0x25;
|
||||
public const int VK_UP = 0x26;
|
||||
public const int VK_RIGHT = 0x27;
|
||||
public const int VK_DOWN = 0x28;
|
||||
public const int VK_SELECT = 0x29;
|
||||
public const int VK_PRINT = 0x2A;
|
||||
public const int VK_EXECUTE = 0x2B;
|
||||
public const int VK_SNAPSHOT = 0x2C;
|
||||
public const int VK_INSERT = 0x2D;
|
||||
public const int VK_DELETE = 0x2E;
|
||||
public const int VK_HELP = 0x2F;
|
||||
|
||||
public const int KEYEVENTF_EXTENDEDKEY = 0x0001;
|
||||
public const int KEYEVENTF_KEYUP = 0x0002;
|
||||
public const int KEYEVENTF_UNICODE = 0x0004;
|
||||
public const int KEYEVENTF_SCANCODE = 0x0008;
|
||||
|
||||
public const int HC_ACTION = 0x0;
|
||||
public const int WH_MOUSELL = 0xE;
|
||||
|
||||
public const int STATUS_SUCCESS = 0x0;
|
||||
#endregion
|
||||
|
||||
#region API函数声明
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "SetParent")]
|
||||
public static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "GetParent")]
|
||||
public static extern int GetParent(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "GetWindowLong")]
|
||||
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern int GetWindowRect(IntPtr hwnd, out Rect lpRect);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "SetWindowLong")]
|
||||
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int lNewLong);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
|
||||
public static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int cx, int cy, int uFlags);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "UpdateWindow")]
|
||||
public static extern bool UpdateWindow(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "SendMessage")]
|
||||
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "SendMessage")]
|
||||
public static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "PostMessage")]
|
||||
public static extern int PostMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "PostMessage")]
|
||||
public static extern int PostMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "keybd_event")]
|
||||
public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, long dwExtraInfo);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "GetWindowThreadProcessId")]
|
||||
public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int lpdwProcessId);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
||||
public static extern void SetForegroundWindow(IntPtr hwnd);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "DrawMenuBar")]
|
||||
public static extern int DrawMenuBar(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "mouse_event")]
|
||||
public static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, IntPtr dwExtraInfo);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "SetCursorPos")]
|
||||
public static extern void SetCursorPos(int x, int y);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "GetCursorPos")]
|
||||
public static extern bool GetCursorPos(out POINT p);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "SetWindowsHookEx")]
|
||||
public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "UnhookWindowsHookEx")]
|
||||
public static extern int UnhookWindowsHookEx(int idHook);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "CallNextHookEx")]
|
||||
public static extern int CallNextHookEx(int idHook, int nCode, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "GetWindowDC")]
|
||||
public static extern IntPtr GetWindowDC(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "ReleaseDC")]
|
||||
public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern IntPtr GetModuleHandle(string name);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr WindowFromPoint(POINT Point);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "GetDoubleClickTime")]
|
||||
public static extern int GetDoubleClickTime();
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "FindWindow")]
|
||||
public extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "FindWindow")]
|
||||
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 表示 Hook 回调函数。
|
||||
/// </summary>
|
||||
/// <param name="nCode"></param>
|
||||
/// <param name="wParam"></param>
|
||||
/// <param name="lParam"></param>
|
||||
/// <returns></returns>
|
||||
public delegate int HookProc(int nCode, IntPtr wParam, IntPtr lParam);
|
||||
/// <summary>
|
||||
/// 表示进程间传递的数据结构
|
||||
/// </summary>
|
||||
public struct COPYDATASTRUCT
|
||||
{
|
||||
public IntPtr dwData;
|
||||
public int cbData;
|
||||
[MarshalAs(UnmanagedType.LPStr)]
|
||||
public string lpData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用于通过 API 获取位置信息的结构。
|
||||
/// </summary>
|
||||
public struct Rect
|
||||
{
|
||||
public int Left;
|
||||
public int Top;
|
||||
public int Right;
|
||||
public int Bottom;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 与非托管通信的鼠标位置结构。
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct POINT
|
||||
{
|
||||
public int X;
|
||||
public int Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 鼠标事件标识。
|
||||
/// </summary>
|
||||
public enum MouseEventFlags
|
||||
{
|
||||
Move = 0x0001,
|
||||
LeftDown = 0x0002,
|
||||
LeftUp = 0x0004,
|
||||
RightDown = 0x0008,
|
||||
RightUp = 0x0010,
|
||||
MiddleDown = 0x0020,
|
||||
MiddleUp = 0x0040,
|
||||
Wheel = 0x0800,
|
||||
Absolute = 0x8000
|
||||
}
|
||||
}
|
||||
public class FormatSystemDatetime
|
||||
{
|
||||
[DllImport("kernel32.dll", EntryPoint = "GetSystemDefaultLCID")]
|
||||
public static extern int GetSystemDefaultLCID();
|
||||
[DllImport("kernel32.dll", EntryPoint = "SetLocaleInfoA")]
|
||||
public static extern int SetLocaleInfo(int Locale, int LCType, string lpLCData);
|
||||
[DllImport("user32.dll", EntryPoint = "SendMessageTimeout")]
|
||||
public static extern long SendMessageTimeout(int hWnd, int Msg, int wParam, int lParam, int fuFlags, int uTimeout, ref int lpdwResult);
|
||||
public const int LOCALE_SSHORTDATE = 0x1F;
|
||||
public const int LOCALE_SLONGDATE = 0x20;
|
||||
public const int LOCALE_STIME = 0x1003;
|
||||
public const int HWND_BROADCAST = 0xFFFF;
|
||||
public const int WM_SETTINGCHANGE = 0x001A;
|
||||
public const int SMTO_ABORTIFHUNG = 2;
|
||||
|
||||
public void SetDateTimeFormat()
|
||||
{
|
||||
try
|
||||
{
|
||||
int p = 0;
|
||||
int x = GetSystemDefaultLCID();
|
||||
SetLocaleInfo(x, LOCALE_SSHORTDATE, "yyyy-M-d"); //短日期格式
|
||||
SetLocaleInfo(x, LOCALE_SLONGDATE, "yyyy年M月d日"); //长日期格式
|
||||
SetLocaleInfo(x, LOCALE_STIME, "H:mm:ss"); //时间格式
|
||||
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0, SMTO_ABORTIFHUNG, 10, ref p);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// DevExpress
|
||||
/// </summary>
|
||||
public class AboutDevCompanion
|
||||
{
|
||||
private int Interval;
|
||||
private bool ResidentMode;
|
||||
private bool StopCompanion;
|
||||
private Thread m_Thread;
|
||||
|
||||
/// <summary>
|
||||
/// 按指定的模式创建 <see cref="Wunion.Budget.PowerBasicFramework.AboutDevCompanion"/> 对象实例。
|
||||
/// <param name="interval">检测Dev注册弹框的时间间隔(以毫秒为单位)。</param>
|
||||
/// <param name="resident">检测程序是否以常驻模式运行(默认值 true)。</param>
|
||||
/// </summary>
|
||||
public AboutDevCompanion(int interval, bool resident = true)
|
||||
{
|
||||
Interval = interval;
|
||||
ResidentMode = resident;
|
||||
StopCompanion = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭 DevExpress 控件的注册弹框(如果调用时找到并关闭了DevExpress注册弹框则返回true,否则返回false)。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private bool CloseAboutDev()
|
||||
{
|
||||
IntPtr devHwnd = WinAPI.FindWindow(null, "About DevExpress");
|
||||
if (devHwnd != IntPtr.Zero)
|
||||
{
|
||||
WinAPI.SendMessage(devHwnd, WinAPI.WM_CLOSE, 0, 0);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 运行 Dev 伴侣,对其注册弹框下毒手。
|
||||
/// </summary>
|
||||
public void Run()
|
||||
{
|
||||
if (!StopCompanion)
|
||||
return; // 防止多次运行导致可能的线程错误。
|
||||
StopCompanion = false;
|
||||
m_Thread = new Thread(new ThreadStart(() =>
|
||||
{
|
||||
while (!StopCompanion)
|
||||
{
|
||||
if (ResidentMode)
|
||||
CloseAboutDev();
|
||||
else // 如果非常驻模式,则在检测并关闭Dev注册弹框后应结束程序。
|
||||
StopCompanion = CloseAboutDev();
|
||||
Thread.Sleep(Interval);
|
||||
}
|
||||
m_Thread = null;
|
||||
}));
|
||||
m_Thread.Start();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭程序的运行。
|
||||
/// </summary>
|
||||
public void Stop()
|
||||
{
|
||||
StopCompanion = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user