// find the name of the image for this HWND. If this fails for any reason just return null. // Review: Getting the image name is expessive if the image name starts to be used a lot // we could cache it in a static hash using the PID as the key. internal static string GetImageName(NativeMethods.HWND hwnd) { int instance = Misc.GetWindowLong(hwnd, SafeNativeMethods.GWL_HINSTANCE); if (instance == 0) { return(null); } StringBuilder sb = new StringBuilder(NativeMethods.MAX_PATH); using (SafeProcessHandle processHandle = new SafeProcessHandle(hwnd)) { if (processHandle.IsInvalid) { return(null); } if (Misc.GetModuleFileNameEx(processHandle, (IntPtr)instance, sb, NativeMethods.MAX_PATH) == 0) { return(null); } } return(System.IO.Path.GetFileName(sb.ToString().ToLower(CultureInfo.InvariantCulture))); }