Permalink
Browse files

AddIn: Code cleanup.

  • Loading branch information...
Rpinski committed Oct 25, 2018
1 parent 8c19e64 commit 83759eed377b3230433170703d2cd840a434d708
Showing with 11 additions and 29 deletions.
  1. +11 −15 ILSpy.AddIn/ILSpyInstance.cs
  2. +0 −14 ILSpy/NativeMethods.cs
@@ -66,22 +66,18 @@ void SendMessage(Process ilspyProcess, string message, bool activate)
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);
@@ -50,20 +50,6 @@ public static string GetWindowText(IntPtr hWnd, int maxLength)
[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)]

0 comments on commit 83759ee

Please sign in to comment.