From ee22df6c94793777fe5b28f2886ebeb2ba2c4256 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期一, 02 九月 2024 21:06:36 +0800 Subject: [PATCH] 1 --- TEWin/FrmWin.cs | 88 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 87 insertions(+), 1 deletions(-) diff --git a/TEWin/FrmWin.cs b/TEWin/FrmWin.cs index 4ea0d93..2a29dc5 100644 --- a/TEWin/FrmWin.cs +++ b/TEWin/FrmWin.cs @@ -7,6 +7,7 @@ using System.Drawing; using System.IO; using System.Linq; +using System.Runtime.InteropServices; using System.Text; using System.Windows.Forms; using TerraExplorerX; @@ -42,11 +43,31 @@ string mainUrl = Application.StartupPath; + System.Timers.Timer timer; + public FrmWin() { InitializeComponent(); + //this.KeyPreview = true; this.Load += FrmWeb_Load; + //this.KeyDown += FrmWin_KeyDown; this.FormClosed += FrmWin_FormClosed; + + timer = new System.Timers.Timer(1500); + timer.Elapsed += timer_Elapsed; + } + + void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) + { + MoveWinPosition("MeshLayerTool", 583, 304); + } + + void FrmWin_KeyDown(object sender, KeyEventArgs e) + { + if (e.Modifiers == Keys.Control && e.KeyCode == Keys.F1) + { + MoveWinPosition("MeshLayerTool", 400, 400); + } } void FrmWeb_Load(object sender, EventArgs e) @@ -143,7 +164,10 @@ SG.Command.Execute(1014, 26); break; case 0xc6: // 妯″瀷鏁版嵁(*.osgb) ExecCmd(new List<string> { "taskkill /f /t /im MeshLayerTool.exe" }); // SG.Command.Execute(2342, null); - RunExe(Path.Combine(ConfigurationManager.AppSettings["tePath"], "MeshLayerTool.exe"), " -RunConvertor -Mode ImportMeshLayer -Type osgb", false); // -RunApp TerraExplorer + //RunExe(Path.Combine(ConfigurationManager.AppSettings["tePath"], "MeshLayerTool.exe"), " -RunConvertor -Mode ImportMeshLayer -Type osgb", false); // -RunApp TerraExplorer + RunExe(Path.Combine(ConfigurationManager.AppSettings["tePath"], "MeshLayerTool.exe"), " -RunApp TerraExplorer -RunConvertor -Mode ImportMeshLayer -Type osgb", false); // -RunApp TerraExplorer + timer.Stop(); + timer.Start(); break; case 0xc7: // 妯″瀷鏁版嵁(*.obj) SG.Command.Execute(1012, 13); break; @@ -187,6 +211,68 @@ } } + #region user32.dll + public const int SWP_NOSIZE = 0x0001; + + public const int SWP_NOMOVE = 0x0002; + + public const int SWP_NOZORDER = 0x0004; + + public const int SWP_SHOWWINDOW = 0x0040; + + public const int HWND_TOPMOST = -1; + + public const int HWND_NOTOPMOST = -2; + + [DllImport("user32.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); + + [DllImport("user32.dll", SetLastError = true)] + static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect); + + [Serializable] + [StructLayout(LayoutKind.Sequential)] + public struct RECT + { + public int Left; + public int Top; + public int Right; + public int Bottom; + } + + public void MoveWinPosition(String name, int left, int right) + { + Process[] processes = Process.GetProcessesByName(name); + if (processes.Length > 0) + { + Process process = processes[0]; + IntPtr hWnd = process.MainWindowHandle; + + // 鑾峰彇绐椾綋鐨勫潗鏍� + RECT rect; + GetWindowRect(hWnd, out rect); + + if (rect.Left < 0 || rect.Left > 1920 || rect.Top < 0 || rect.Top > 1080) + { + timer.Stop(); + // 绉诲姩绐楀彛鍒板睆骞曚笂鐨勪綅缃�: + SetWindowPos(hWnd, IntPtr.Zero, left, right, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW); + } + } + } + + public static void Main() + { + // 鑾峰彇鎸囧畾绐椾綋鐨勫彞鏌� + //IntPtr hWnd = // 鑾峰彇绐椾綋鍙ユ焺鐨勬柟娉曪紝渚嬪FindWindow鎴栬�呴�氳繃杩涚▼鍚嶈幏鍙� + // 鑾峰彇绐椾綋鐨勫潗鏍� + //RECT rect; + //GetWindowRect(hWnd, out rect); + //Console.WriteLine("绐椾綋鍧愭爣: 宸︿笂瑙�({0}, {1}), 鍙充笅瑙�({2}, {3})", rect.Left, rect.Top, rect.Right, rect.Bottom); + } + #endregion + public void ShowHtmlByid(int id, int arg) { switch (id) -- Gitblit v1.9.3