From e05f48fc7ba368d3561d8702b18d65ee021b1ae2 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期二, 03 九月 2024 14:31:15 +0800 Subject: [PATCH] 11 --- TEWin/FrmWin.cs | 83 +++++++++++++++++++++++++++++++++++------ TEWin/TEWin.csproj | 3 + TEWin/FrmTool.cs | 5 ++ TEWin/Resources/favicon.ico | 0 TEWin/FrmTool.Designer.cs | 16 +++++++ 5 files changed, 93 insertions(+), 14 deletions(-) diff --git a/TEWin/FrmTool.Designer.cs b/TEWin/FrmTool.Designer.cs index dc306a4..c9d7284 100644 --- a/TEWin/FrmTool.Designer.cs +++ b/TEWin/FrmTool.Designer.cs @@ -31,6 +31,7 @@ this.txtCode = new System.Windows.Forms.TextBox(); this.btnTest = new System.Windows.Forms.Button(); this.cbCode = new System.Windows.Forms.ComboBox(); + this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // txtCode @@ -62,11 +63,23 @@ this.cbCode.Size = new System.Drawing.Size(198, 24); this.cbCode.TabIndex = 2; // + // button1 + // + this.button1.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.button1.Location = new System.Drawing.Point(487, 12); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 26); + this.button1.TabIndex = 3; + this.button1.Text = "OSGBLab"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // // FrmTool // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(486, 48); + this.ClientSize = new System.Drawing.Size(579, 50); + this.Controls.Add(this.button1); this.Controls.Add(this.cbCode); this.Controls.Add(this.btnTest); this.Controls.Add(this.txtCode); @@ -85,5 +98,6 @@ private System.Windows.Forms.TextBox txtCode; private System.Windows.Forms.Button btnTest; private System.Windows.Forms.ComboBox cbCode; + private System.Windows.Forms.Button button1; } } \ No newline at end of file diff --git a/TEWin/FrmTool.cs b/TEWin/FrmTool.cs index 3e67beb..62855df 100644 --- a/TEWin/FrmTool.cs +++ b/TEWin/FrmTool.cs @@ -50,5 +50,10 @@ int code = Convert.ToInt32(str, 16); win.InvokeProc(code); } + + private void button1_Click(object sender, EventArgs e) + { + this.win.DealOsgbLab(); + } } } diff --git a/TEWin/FrmWin.cs b/TEWin/FrmWin.cs index dc5d562..a3a45d2 100644 --- a/TEWin/FrmWin.cs +++ b/TEWin/FrmWin.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Runtime.InteropServices; using System.Text; +using System.Threading; using System.Windows.Forms; using TerraExplorerX; using TETree; @@ -49,11 +50,11 @@ { InitializeComponent(); //this.KeyPreview = true; - this.Load += FrmWeb_Load; //this.KeyDown += FrmWin_KeyDown; - this.FormClosed += FrmWin_FormClosed; + this.Load += FrmWeb_Load; + this.FormClosing += FrmWin_FormClosing; - timer = new System.Timers.Timer(1500); + timer = new System.Timers.Timer(1000); timer.Elapsed += timer_Elapsed; } @@ -118,12 +119,14 @@ this.SG.OnLoadFinished -= SG_OnLoadFinished; } - void FrmWin_FormClosed(object sender, FormClosedEventArgs e) + void FrmWin_FormClosing(object sender, FormClosingEventArgs e) { + ExecCmd(new List<string> { "taskkill /f /t /im OSGBLab.exe" }); LogOut.Info("鍏抽棴绋嬪簭."); } #endregion + #region invoke protected override void DefWndProc(ref Message m) { switch (m.Msg) @@ -214,6 +217,7 @@ DisplayByAttribute(1, "鎸夌収灞炴�ц缃鑹�"); break; } } + #endregion #region user32.dll public const int SWP_NOSIZE = 0x0001; @@ -265,18 +269,65 @@ } } } + #endregion - public static void Main() + #region OSGBLab + const int GCLP_HICON = -14; + const int ICON_SMALL = 0; + const int ICON_BIG = 1; + + [DllImport("user32.dll", SetLastError = true)] + static extern IntPtr FindWindow(string lpClassName, string lpWindowsName); + + [DllImport("user32.dll", SetLastError = true)] + public static extern IntPtr FindWindowEx(IntPtr hWndParent, IntPtr hWndChildAfter, string lpszClass, string lpszWindow); + + [DllImport("user32.dll", SetLastError = true)] + static extern bool SetWindowText(IntPtr hWnd, String lpString); + + [DllImport("user32.dll", SetLastError = true)] + public static extern IntPtr SetClassLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong); + + public void DealOsgbLab() { - // 鑾峰彇鎸囧畾绐椾綋鐨勫彞鏌� - //IntPtr hWnd = // 鑾峰彇绐椾綋鍙ユ焺鐨勬柟娉曪紝渚嬪FindWindow鎴栬�呴�氳繃杩涚▼鍚嶈幏鍙� - // 鑾峰彇绐椾綋鐨勫潗鏍� - //RECT rect; - //GetWindowRect(hWnd, out rect); - //Console.WriteLine("绐椾綋鍧愭爣: 宸︿笂瑙�({0}, {1}), 鍙充笅瑙�({2}, {3})", rect.Left, rect.Top, rect.Right, rect.Bottom); + /*Process[] processes = Process.GetProcessesByName("OSGBLab"); + if (processes.Length > 0) + { + IntPtr hWnd = processes[0].MainWindowHandle; + SetWindowText(hWnd, "OSGB鏁版嵁澶勭悊宸ュ叿"); + }*/ + + IntPtr hWnd = FindWindow(null, "OSGBLab(鍊炬枩浼翠荆) (Windows) 鍏嶈垂鐗�"); + if (hWnd == IntPtr.Zero) return; + + DealOsgbLab(hWnd); + } + + public void DealOsgbLab(Process p) + { + do + { + if (p.MainWindowHandle != IntPtr.Zero) + { + DealOsgbLab(p.MainWindowHandle); + break; + } + + Thread.Sleep(50); + } while (true); + } + + public void DealOsgbLab(IntPtr hWnd) + { + SetWindowText(hWnd, "OSGB鏁版嵁澶勭悊宸ュ叿"); + + Icon icon = new Icon(Path.Combine(mainUrl, @"Resources\favicon.ico")); + SetClassLongPtr(hWnd, GCLP_HICON + ICON_SMALL, icon.Handle); + SetClassLongPtr(hWnd, GCLP_HICON + ICON_BIG, icon.Handle); } #endregion + #region ShowHtml+RunExe public void ShowHtmlByid(int id, int arg) { switch (id) @@ -324,7 +375,7 @@ SG.Window.ShowPopup(popup); } - public void RunExe(string path, string args, bool noWindow = true) + public Process RunExe(string path, string args, bool noWindow = true) { Process p = new Process(); p.StartInfo.FileName = path; @@ -332,6 +383,8 @@ p.StartInfo.CreateNoWindow = noWindow; p.StartInfo.UseShellExecute = false; p.Start(); + + return p; } public static string ExecCmd(List<string> list) @@ -379,6 +432,7 @@ return str; } + #endregion #region 瑙掗噺绠� private void AngleMeasurement() @@ -566,6 +620,7 @@ } #endregion + #region 璋冪敤Html private string GetAbsolutePath(string key) { string str = ConfigurationManager.AppSettings[key]; @@ -586,13 +641,15 @@ private void InvokeOsgbLab() { ExecCmd(new List<string> { "taskkill /f /t /im OSGBLab.exe" }); - RunExe(GetAbsolutePath("osgblabPath"), null, false); + osgbProc = RunExe(GetAbsolutePath("osgblabPath"), null, false); + DealOsgbLab(osgbProc); } private void DisplayByAttribute(int type, String name) { this.ShowHtml(name, mainUrl + @"\Resources\DisplayByAttribute\DisplayByAttribute.html?Type=" + type + "&lang=2052", 20, 20, 365, 355); } + #endregion #region 鍔犺浇shp + 璇诲彇shp private void LoadShp() diff --git a/TEWin/Resources/favicon.ico b/TEWin/Resources/favicon.ico new file mode 100644 index 0000000..0791ef9 --- /dev/null +++ b/TEWin/Resources/favicon.ico Binary files differ diff --git a/TEWin/TEWin.csproj b/TEWin/TEWin.csproj index dc5a4ee..43a83be 100644 --- a/TEWin/TEWin.csproj +++ b/TEWin/TEWin.csproj @@ -916,6 +916,9 @@ <EmbeddedResource Include="Resources\DisplayByAttribute\ToolIcon.png"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </EmbeddedResource> + <EmbeddedResource Include="Resources\favicon.ico"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </EmbeddedResource> <Content Include="Resources\log4net4.dll" /> <Content Include="Resources\Newtonsoft.Json.dll" /> </ItemGroup> -- Gitblit v1.9.3