Skip to content

Commit

Permalink
Add Seer preview (#450)
Browse files Browse the repository at this point in the history
Closes #450
  • Loading branch information
srwi committed Nov 5, 2023
1 parent 04078ff commit 8af9be3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions EverythingToolbar/Controls/SearchResultsView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ private void OpenFilePath(object sender, RoutedEventArgs e)
private void PreviewSelectedFile()
{
SelectedItem?.PreviewInQuickLook();
SelectedItem?.PreviewInSeer();
}

private ScrollViewer GetScrollViewer()
Expand Down
34 changes: 32 additions & 2 deletions EverythingToolbar/Data/SearchResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Diagnostics;
using System.IO;
using System.IO.Pipes;
using System.Runtime.InteropServices.ComTypes;
using System.Security.Principal;
using System.Threading.Tasks;
using System.Windows;
Expand All @@ -13,9 +12,11 @@
using EverythingToolbar.Properties;
using NLog;
using Peter;
using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME;
using Clipboard = System.Windows.Clipboard;
using DataObject = System.Windows.DataObject;
using MessageBox = System.Windows.MessageBox;
using System.Runtime.InteropServices;

namespace EverythingToolbar.Data
{
Expand Down Expand Up @@ -194,7 +195,36 @@ public void PreviewInQuickLook()
}
catch (Exception e)
{
Logger.Error(e, "Failed to open preview.");
Logger.Error(e, "Failed to open QuickLook preview.");
}
});
}

public void PreviewInSeer()
{
Task.Run(() =>
{
try
{
IntPtr seer = NativeMethods.FindWindowEx(IntPtr.Zero, IntPtr.Zero, "SeerWindowClass", null);
const int SEER_INVOKE_W32 = 5000;
const int WM_COPYDATA = 0x004A;
NativeMethods.COPYDATASTRUCT cd = new NativeMethods.COPYDATASTRUCT
{
cbData = (FullPathAndFileName.Length + 1) * 2,
lpData = Marshal.StringToHGlobalUni(FullPathAndFileName),
dwData = new IntPtr(SEER_INVOKE_W32)
};
NativeMethods.SendMessage(seer, WM_COPYDATA, IntPtr.Zero, ref cd);
Marshal.FreeHGlobal(cd.lpData);
}
catch (Exception e)
{
Logger.Error(e, "Failed to open Seer preview.");
}
});
}
Expand Down
14 changes: 14 additions & 0 deletions EverythingToolbar/Helpers/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,22 @@ namespace EverythingToolbar.Helpers
{
public class NativeMethods
{
[StructLayout(LayoutKind.Sequential)]
public struct COPYDATASTRUCT
{
public IntPtr dwData;
public int cbData;
public IntPtr lpData;
}

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow(IntPtr hWnd);

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);

[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, ref COPYDATASTRUCT lParam);
}
}

0 comments on commit 8af9be3

Please sign in to comment.