From 83759eed377b3230433170703d2cd840a434d708 Mon Sep 17 00:00:00 2001 From: Andreas Weizel Date: Fri, 26 Oct 2018 01:15:20 +0200 Subject: [PATCH] AddIn: Code cleanup. --- ILSpy.AddIn/ILSpyInstance.cs | 26 +++++++++++--------------- ILSpy/NativeMethods.cs | 14 -------------- 2 files changed, 11 insertions(+), 29 deletions(-) diff --git a/ILSpy.AddIn/ILSpyInstance.cs b/ILSpy.AddIn/ILSpyInstance.cs index fe4ee1abc..3c56e448e 100644 --- a/ILSpy.AddIn/ILSpyInstance.cs +++ b/ILSpy.AddIn/ILSpyInstance.cs @@ -66,22 +66,18 @@ namespace ICSharpCode.ILSpy.AddIn do { NativeMethods.EnumWindows( (hWnd, lParam) => { - uint processId = NativeMethods.GetProcessIdFromWindow(hWnd); - //if (processId == ilspyProcess.Id) { - Debug.WriteLine("Found {0:x4} for process {1}", hWnd, processId); - string windowTitle = NativeMethods.GetWindowText(hWnd, 100); - if (windowTitle.StartsWith("ILSpy", StringComparison.Ordinal)) { - Debug.WriteLine("Found {0:x4}: {1}", hWnd, windowTitle); - IntPtr result = Send(hWnd, message); - Debug.WriteLine("WM_COPYDATA result: {0:x8}", result); - if (result == (IntPtr)1) { - if (activate) - NativeMethods.SetForegroundWindow(hWnd); - success = true; - return false; // stop enumeration - } + string windowTitle = NativeMethods.GetWindowText(hWnd, 100); + if (windowTitle.StartsWith("ILSpy", StringComparison.Ordinal)) { + Debug.WriteLine("Found {0:x4}: {1}", hWnd, windowTitle); + IntPtr result = Send(hWnd, message); + Debug.WriteLine("WM_COPYDATA result: {0:x8}", result); + if (result == (IntPtr)1) { + if (activate) + NativeMethods.SetForegroundWindow(hWnd); + success = true; + return false; // stop enumeration } - //} + } return true; // continue enumeration }, IntPtr.Zero); diff --git a/ILSpy/NativeMethods.cs b/ILSpy/NativeMethods.cs index f2eb56989..1513d66ae 100644 --- a/ILSpy/NativeMethods.cs +++ b/ILSpy/NativeMethods.cs @@ -50,20 +50,6 @@ namespace ICSharpCode.ILSpy [DllImport("user32.dll", CharSet = CharSet.Auto)] [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool SetForegroundWindow(IntPtr hWnd); - - //HANDLE WINAPI GetProcessHandleFromHwnd( - // _In_ HWND hwnd - //); - - [DllImport("user32.dll", CharSet = CharSet.Auto)] - [return: MarshalAs(UnmanagedType.I4)] - internal static extern uint GetWindowThreadProcessId(IntPtr hWnd, [MarshalAs(UnmanagedType.I4)] out uint processId); - - public static uint GetProcessIdFromWindow(IntPtr hWnd) - { - GetWindowThreadProcessId(hWnd, out uint processId); - return processId; - } } [return: MarshalAs(UnmanagedType.Bool)]