|
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
namespace NavigationAssistanceSample
{
/// <summary>
/// Implements a manager for total commander windows.
/// </summary>
public class TotalCommanderManager : INavigatorManager
{
private readonly string _totalCommanderPath;
public TotalCommanderManager(string totalCommanderPath)
{
_totalCommanderPath = Path.GetFullPath(totalCommanderPath);
}
public bool IsNavigator(ApplicationWindow hostWindow)
{
uint hostProcessId;
GetWindowThreadProcessId(hostWindow.Handle, out hostProcessId);
Process hostProcess = Process.GetProcessById((int)hostProcessId);
string executablePath = null;
try
{
executablePath = hostProcess.MainModule.FileName;
}
catch (Exception)
{
//This may happen if hostProcess is not TotalCommander (e.g. Windows Explorer)
}
//Ignore case is not very accurate, but should prevent possible case mistakes
return string.Equals(executablePath, _totalCommanderPath, StringComparison.InvariantCultureIgnoreCase);
}
public INavigator GetNavigator(ApplicationWindow hostWindow)
{
return new TotalCommander(hostWindow, _totalCommanderPath, false);
}
public INavigator CreateNavigator()
{
return new TotalCommander(null, _totalCommanderPath, true);
}
[DllImport("user32.dll", SetLastError = true)]
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.