using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Threading; using System.Diagnostics; using HXX.Scanner.Common; namespace HXX.Scanner.Starter { public partial class frmStarter : Form { public frmStarter() { InitializeComponent(); } bool haveHandle = false; private void Form1_Load(object sender, EventArgs e) { int frameX = (System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Size.Width - HXX.Scanner.Starter.Properties.Resources.检测中.Width) / 2; int frameY = (System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Size.Height - HXX.Scanner.Starter.Properties.Resources.检测中.Height) / 2; this.SetDesktopLocation(frameX, frameY); SetBits(global::HXX.Scanner.Starter.Properties.Resources.检测中); UpdateBiz(); } private async void UpdateBiz() { try { var checkInfo = await biz.get_version_info(); //test //checkInfo.Data.data.allowFlag = 1; //checkInfo.Data.data.force = 0; //checkInfo.Data.data.version = "1.9.50"; //checkInfo.Data.data.description = @"1. 优化扫描识别 \r\n2. 修复bug \r\n3. abcdef \r\n4. aabbcc \r\n5. kknd"; //test if (checkInfo != null && checkInfo.Data != null && checkInfo.Data.data != null && checkInfo.Status == 1) { if (checkInfo.Data.data.allowFlag == 1)//强制开关,开关=1才允许进入升级流程 { if (biz.check_new_version(checkInfo.Data.data))//版本对比 { await Task.Run(() => { this.Invoke(new Action(() => { this.Hide(); frmCheckUpdate frm = new frmCheckUpdate(checkInfo.Data.data); frm.Show(); })); }); } else { await go_to_main(); } } else { await go_to_main(); } } else //访问升级信息报错 { this.Hide(); MessageBox.Show(checkInfo.Message); await go_to_main(); } } catch (Exception ee) { LogManager.WriteLog(ee); this.Hide(); MessageBox.Show(ee.Message); await go_to_main(); } } private async Task go_to_main() { await Task.Run(() => { this.Invoke(new Action(() => { try { Process.Start("HXXScannerClient.exe"); Environment.Exit(0); } catch (Exception ee) { MessageBox.Show(ee.Message); Environment.Exit(0); } })); }); } private void InitializeStyles() { SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.UserPaint, true); UpdateStyles(); } protected override void OnClosing(CancelEventArgs e) { e.Cancel = true; base.OnClosing(e); haveHandle = false; } protected override void OnHandleCreated(EventArgs e) { InitializeStyles(); base.OnHandleCreated(e); haveHandle = true; } protected override CreateParams CreateParams { get { CreateParams cParms = base.CreateParams; cParms.ExStyle |= 0x00080000; // WS_EX_LAYERED return cParms; } } public void SetBits(Bitmap bitmap) { if (!haveHandle) return; if (!Bitmap.IsCanonicalPixelFormat(bitmap.PixelFormat) || !Bitmap.IsAlphaPixelFormat(bitmap.PixelFormat)) throw new ApplicationException("The picture must be 32bit picture with alpha channel."); IntPtr oldBits = IntPtr.Zero; IntPtr screenDC = Win32.GetDC(IntPtr.Zero); IntPtr hBitmap = IntPtr.Zero; IntPtr memDc = Win32.CreateCompatibleDC(screenDC); try { Win32.Point topLoc = new Win32.Point(Left, Top); Win32.Size bitMapSize = new Win32.Size(bitmap.Width, bitmap.Height); Win32.BLENDFUNCTION blendFunc = new Win32.BLENDFUNCTION(); Win32.Point srcLoc = new Win32.Point(0, 0); hBitmap = bitmap.GetHbitmap(Color.FromArgb(0)); oldBits = Win32.SelectObject(memDc, hBitmap); blendFunc.BlendOp = Win32.AC_SRC_OVER; blendFunc.SourceConstantAlpha = 255; blendFunc.AlphaFormat = Win32.AC_SRC_ALPHA; blendFunc.BlendFlags = 0; Win32.UpdateLayeredWindow(Handle, screenDC, ref topLoc, ref bitMapSize, memDc, ref srcLoc, 0, ref blendFunc, Win32.ULW_ALPHA); } finally { if (hBitmap != IntPtr.Zero) { Win32.SelectObject(memDc, oldBits); Win32.DeleteObject(hBitmap); } Win32.ReleaseDC(IntPtr.Zero, screenDC); Win32.DeleteDC(memDc); } } } }