こんにちは。
Windows10でWPFのアプリケーションを開発しています。
Visual Studio 2015 Communityを使っています。
###前提・実現したいこと
現在アクティブなウィンドウ(エクスプローラ)の開いているフォルダのフルパスを取得したいです。
下記のコードで、ウィンドウのタイトルを取得はできています。
Processの値を見ているのですが、フルパスは入っていないみたいなのです。
###試したこと
###発生している問題・エラーメッセージ
###該当のソースコード
C#
1using System; 2using System.Diagnostics; 3using System.Runtime.InteropServices; 4using System.Windows; 5 6namespace WpfApplication1 { 7 public partial class MainWindow : Window { 8 System.Windows.Threading.DispatcherTimer dispatchertimer = new System.Windows.Threading.DispatcherTimer(); 9 10 [DllImport("user32.dll")] 11 public static extern IntPtr GetForegroundWindow(); 12 [DllImport("user32.dll")] 13 public static extern int GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId); 14 15 public MainWindow() { 16 InitializeComponent(); 17 } 18 19 private void Window_Loaded(object sender, RoutedEventArgs e) { 20 dispatchertimer.Interval = new TimeSpan(3000); 21 dispatchertimer.Start(); 22 dispatchertimer.Tick += Dispatchertimer_Tick; 23 } 24 25 private void Dispatchertimer_Tick(object sender, EventArgs e) { 26 this.Dispatcher.Invoke(new Action(() => { 27 GetActiveWindow(); 28 })); 29 } 30 31 private void GetActiveWindow() { 32 IntPtr handle = GetForegroundWindow(); 33 int id; 34 GetWindowThreadProcessId(handle, out id); 35 36 37 Process process = Process.GetProcessById(id); 38 if (process.ProcessName == "explorer") { 39 Title = process.ProcessName + " " + process.MainWindowTitle; 40 } 41 else 42 Title = "[not explorer]"+process.ProcessName; 43 } 44 } 45} 46
###補足情報(言語/FW/ツール等のバージョンなど)
Microsoft Visual Studio Community 2015
Version 14.0.25424.00 Update 3
Microsoft .NET Framework
Version 4.6.01038
インストールしているバージョン:Community
Visual C# 2015 00322-20000-00000-AA575
Microsoft Visual C# 2015
です。
よろしくお願いします。

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/11/13 08:33
2016/11/13 08:47
2016/11/13 11:47
2016/11/13 11:50